Dynamic Quantity based on the Balance Request

,

Hello,

Is there a way to say “If trading account is above XXX USD then position size = YYY”?

There is no way from TradingView.com to know what’s the broker trading account balance.
But from tradingview.to, we can access to the trading account balance with the “BALANCE” command

Thank

Yes this is possible to achieve. Although it is not documented as it is not fully supported. Watch the topic: Metatrader (MT4 or MT5)

We have a hidden param b that stands for balance that allows you to filter the minimum balance

Example

buy EURUSD q=0.1 b=1000 will only buy 0.1 lots if the balance is equal to or greater thatn 1000. Try it out on TradingView.To/Metatrader

awesome
is this b=1000 based off the tradingview strategy balance or based off the broker account balance?

1 Like

Based on Metatrader borker account balance. Filters in tradingview are done by your script not by the commands.

Sorry if it wasn’t clear

I want basically to say in the alert

If balance = 1000 then quantity = 1
else if balance = 2000 then quantity = 2

else if balance = 5000 then quantity = 5

Is that possible with 1 alert?

Thank you Lucem

Would that work to create 1 alert for 1 order with 5 conditions based off the trading balance?

alert_long_message_1 = “Buy " + syminfo.ticker + " q=1 b=1000” + “\n” + “Buy " + syminfo.ticker + " q=2 b=2000” + “\n” + “Buy " + syminfo.ticker + " q=3 b=3000” + “\n” + “Buy " + syminfo.ticker + " q=4 b=4000” + “\n” + “Buy " + syminfo.ticker + " q=5 b=5000”

strategy.entry(“Long”, strategy.long, alert_message=alert_long_message_1)

to set the position size based of the balance

Hi @Daveatt

You are suggessting this?

buy q=1 b=1000
buy q=2 b=2000
buy q=3 b=3000

This will result to 3 buys if the balance is at least 1000, 2 buys if it is at least 2000 as the first order will fail.

Your request is to have dynamic volume based on the balance. Since your Q and balance seem to increase constantly, I would suggest using the Q as a percentage which will have the same effect.

If lets say with a 1000 USD balance and 1% volume is 1, then if the balance is 2000USD the volume will be 2.

Would this work for you?

Hi Lucem

Do you suggest I create only 2 alert messages, then?
I want the trade quantities in lots → if balance = 1000 then qty lot = 1

Should I keep using the balance b parameter?

Like this?

buy eurusd q=0.1%
sell eurusd q=0.1%

The balance parameter is for limiting trade execution if the balance has not met a certain value. Using Q as percentage uses the balance to determine the appropriate volume. So if your balance is 1500 from my previous example, your volume would be 0.15. This means that you no longer want to filter the Q based on balance because it is automatic.