How to create ATR Trailing Stoploss
Posted: Fri Mar 24, 2023 3:35 pm
I tried to code stop loss and it's plotting fine in a chart when I tried to add to the strategy it was not executing... please help
if longBuy
strategy.entry(id = "Long", direction = strategy.long)
// strategy.exit(id = "exit", from_entry = "Long", stop = longStopATR)
// Long trade exit
if buyExit or longStopATR
strategy.close(id = "Long", comment = "Long_Exit" + ( longStopATR ? "_ATR_SL " : buyExit ? "_RSI_Hit " : na))
// Sell Entry
if shortSell
strategy.entry(id = "Short", direction = strategy.short)
// strategy.exit(id = "exit", from_entry = "Short", stop = shortStopATR)
// Sell exit
if sellExit or shortStopATR
strategy.close(id = "Short", comment = "Short_Exit" + ( shortStopATR ? "_ATR_SL" : sellExit ? "_RSI_Hit" : an))
if longBuy
strategy.entry(id = "Long", direction = strategy.long)
// strategy.exit(id = "exit", from_entry = "Long", stop = longStopATR)
// Long trade exit
if buyExit or longStopATR
strategy.close(id = "Long", comment = "Long_Exit" + ( longStopATR ? "_ATR_SL " : buyExit ? "_RSI_Hit " : na))
// Sell Entry
if shortSell
strategy.entry(id = "Short", direction = strategy.short)
// strategy.exit(id = "exit", from_entry = "Short", stop = shortStopATR)
// Sell exit
if sellExit or shortStopATR
strategy.close(id = "Short", comment = "Short_Exit" + ( shortStopATR ? "_ATR_SL" : sellExit ? "_RSI_Hit" : an))