0

Hi need help on my code I don't know why my stop loss on short position is not triggering when the price level reached

Can anyone explain me why and help me to fix it `

//short position
var float ssellPrice = 0
ssellCondition  = close < s1 and close < s2 and co and strategy.position_size == 0 and f_datefilter
sbuyCondition = close > s2 and co and strategy.position_size < 0 and (not i_higherclose or close > high[1])
sstopDistance  = strategy.position_size < 0 ? ((ssellPrice + close) / close) : na
sstopPrice     = strategy.position_size < 0 ? ssellPrice + (ssellPrice * sstoppercent) : na
sstopCondition = strategy.position_size < 0 and sstopDistance < sstoppercent


//enter short positions
if ssellCondition
    strategy.entry(id="short", direction = strategy.short, comment = "ENTER-SHORT")

if ssellCondition[1]
    ssellPrice := open

//exit short position
if sbuyCondition or sstopCondition
    strategy.close(id="short", comment="EXIT-SHORT" + (sstopCondition ? "SL=true" : ""))
    ssellPrice := na

`

I just need help on my code to trigger those stop loss

  • you can add `plot(sbuyCondition ? 1 : 0)` & `plot(sstopCondition ? 1 : 0)` into your script and check if this condition become true. – Andrey D Nov 08 '22 at 18:50

0 Answers0