[CMD] Plot Balance - Strooth Mod
stableDescription
Command to easily throw in your scripts which plots the balance monitor
Can be called without any settings, the defaults should work with a test balance, otherwise specify as needed as shown in the second example.
Will also flag up if you got liquidated too
CC_PlotBalance()
CC_PlotBalance(-2, 0.8, 75, false, true, false, true, true, 20000, false)
HaasScript
DefineIntervalOptimization(CurrentInterval())
DefineCommand('PlotBalance', 'Final Wallet Balance')
local cindex = DefineParameter(NumberType, 'ChartIndex', 'The index to plot the chart', false, -10, 'Number, Input')
local maxBudget = DefineParameter(NumberType, 'maxBudget', 'The index to plot the chart', false, 0.8, 'Number, Input')
local leverage = DefineParameter(NumberType, 'leverage', 'leverage', false, 50, 'Number, Input')
local compound = DefineParameter(BooleanType, 'AddProfit', 'Add profit into balance', false, true, 'true/false, boolean, Input')
local deact = DefineParameter(BooleanType, 'StopOnLiquidation', 'Deactivate bot on liquidation', false, true, 'true/false, boolean, Input')
local testWallet = DefineParameter(BooleanType, 'Test Wallet', 'Simulate with test wallet balance', false, true, 'true/false, boolean, Input')
local testBal = DefineParameter(NumberType, 'Test Balance', 'Test Balance Amount', false, 10000, 'Number, Input')
local log = DefineParameter(BooleanType, 'log', 'verbose logging', false, false, 'true/false, boolean, Input')
local zrb, WorkBalline, Budgetline, Walletline, plot
local profitLabel = ProfitLabel()
if profitLabel == nil then profitLabel = QuoteCurrency() end
local availBal = testWallet and testBal or WalletAmount(AccountGuid(), profitLabel)
local longAmount = LongAmount()
local shortAmount = ShortAmount()
local getProfitL = GetCurrentProfit(PositionLong)
local getProfitS = GetCurrentProfit(PositionShort)
local getProfit = getProfitL + getProfitS
local usedLong = UsedMargin(AccountGuid(), UserPositionContainer({direction=PositionLong}).enterPrice, longAmount, leverage)
local usedShort = UsedMargin(AccountGuid(), UserPositionContainer({direction=PositionShort}).enterPrice, shortAmount, leverage)
local botProfit = GetBotProfit()
-- balance warning
local walletBal = compound and (availBal + botProfit) or availBal
local workBal = usedLong + usedShort - getProfit
local budgetBal = maxBudget * walletBal
local balRatio = budgetBal > 0 and workBal / budgetBal or 0
if log then
if balRatio > 0.5 and balRatio < 0.8 then LogWarning('Working balance is > 50% of Budget!!!') end
if balRatio > 0.8 then LogWarning('Working balance is > 80% of Budget!!!') end
Log('Balance Monitor Binance -> Budget Balance: '..Round(budgetBal, 5)..' '..profitLabel..' | Working Balance: '..Round(workBal, 5)..' '..profitLabel..' | Ratio: '..Round(balRatio, 3))
end
local output = {}
output.label = profitLabel
output.availbal = availBal
output.walletbal = walletBal
output.workbal = workBal
output.budgetbal = budgetBal
output.usedShort = usedShort
output.usedLong = usedLong
output.balRatio = balRatio
plot = function()
zrb = Plot(cindex, 'Zero', 0, {c=White, s=Step, width=1})
WorkBalline = Plot(cindex, 'WorkBal', workBal, {c=Yellow, s=Step})
Budgetline = Plot(cindex, 'Budget Balance', (walletBal * maxBudget), {c=Orange, s=Step})
Walletline = Plot(cindex, 'Wallet Balance', (walletBal), {c=Red, s=Step})
end
if deact and workBal > walletBal then
if not Load('done', false) then
PlotShape(0, ShapeCross, White, 11, true, 'Liquidated', White)
PlotVerticalLine(0, 'Liquidated', Red, Time(), Dashed)
Save('done', true)
end
end
if Finalize(OptimizedForInterval(CurrentInterval(), plot)) then
if Load('done', false) then
DeactivateBot()
end
PlotBands(WorkBalline, zrb, ChangeColorOpacity(White,10))
if IsSmallerThan(workBal, (walletBal * maxBudget)) then
PlotCloud(Budgetline, WorkBalline, 10)
end
if IsSmallerThan(workBal, (walletBal * maxBudget)) then
PlotCloud(Walletline, Budgetline, 10)
elseif IsSmallerThan(workBal, walletBal) then
PlotCloud(Walletline, WorkBalline, 10)
end
ChartSetOptions(cindex, 'Balance Monitor', 100)
end
DefineOutput(ListDynamicType, output, '', '')
DefineOutputIndex(1, StringType, 'label', 'Profit label of the market i.e. USDT', 'string')
DefineOutputIndex(2, NumberType, 'availbal', 'available balance', 'number')
DefineOutputIndex(3, NumberType, 'walletbal', 'wallet balance', 'number')
DefineOutputIndex(4, NumberType, 'workbal', 'working balance', 'number')
DefineOutputIndex(5, NumberType, 'budgetbal', 'budget balance', 'number')
DefineOutputIndex(6, NumberType, 'usedShort', 'long amount', 'number')
DefineOutputIndex(7, NumberType, 'usedLong', 'short amount', 'number')
DefineOutputIndex(8, NumberType, 'balRatio', 'balance ratio', 'number')
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!