This is my code:
for tradeIndex = 0 to strategy.opentrades - 1
entryPrice = math.round(strategy.opentrades.entry_price(tradeIndex))
tradeQty = strategy.opentrades.size(tradeIndex)
tradeId = strategy.opentrades.entry_id(tradeIndex)
stopLossCond = close < entryPrice * (100 - slThreshold) / 100
if (stopLossCond)
//strategy.close_all()
strategy.exit("SL", from_entry = tradeId, stop = entryPrice)
//strategy.close(tradeId, comment="SL hit", immediately = true)
label.new(x=bar_index, y = low*(1-tradeIndex/150), text="ID: "+ str.tostring(tradeId)+" Qty: "+str.tostring(tradeQty)+" EP: "+str.tostring(entryPrice)+" SL: "+str.tostring(entryPrice * (100 - slThreshold) / 100)+"n", color=color.black, style=label.style_label_down, textcolor=color.white, size=size.small)
As you may see the commented part, I tried close()
and close_all()
, the latter worked just fine.
I know for sure, that stopLossCond
is triggering, because I see labels printing out on every bar with all the details. So it’s beyond me, WHY doesn’t my code close/exit the trade.