The following syntax example shows how to calculate relative quantity based on a defined risk in a unified alert – so it will work the same for both long and short signals!

Risk here means the maximum percentage of the account we are willing to lose when our stoploss is hit.
In our example we specify “3” – meaning 3% worst-case account loss when stopped out.

In this example we use a TV candle close price of 27375.7 (our assumed entry) and our strategy is placing a stoploss 0.85% below that entry at 27143.007 for a LONG order:

#close:27375.7,sl:27143.007,risk:3,lev:48
 
[side] quantity=[-][_risk / (_sl/close-1) / _lev]% leverage=_lev

In the first line “close”, “sl”, “risk” and “lev” are defined as defaults and are just example values - when used in production you would send these as variables from TV!


For a long signal the above syntax would be resolved to the following by ProfitView:

long quantity=7.353% leverage=48
 
# variables are replaced by values ⇒ quantity = - 3 / (27143.007 / 27375.7 - 1) / 48


For a short signal the strategy would place a stoploss 0.85% above the entry so our SL would be at 27608.393 – with those values our syntax would be resolved to this:

short quantity=7.353% leverage=48
 
# variables are replaced by values ⇒ quantity = 3 / (27608.393 / 27375.7 - 1) / 48


As we can see for both cases the correct quantity given the entry and (worst case) exit price and used leverage is calculated – so when our stoploss is hit our account will only shrink by 3%!

Attention

Always double check that you are using the right syntax/alert!