Clear all

ATR Trailing Stop Loss

Co-Founder Admin

Using trailing stop loss in trading is highly suggested for good risk management. With VAI, we can be more dynamic in our trailing stops by basing it off the stock's current 10 day average volatility. This way, you'll have tight stops on consolidating markets but a wider breathing room for volatile markets. This will help in reducing premature exits.

Feel free to change the ATRratio or multiple, this will change how sensitive your exits will be. A lower number will make it more sensitive and vice versa.

//ATR Trailing Stops

set ATRratio= 3
set ATR = ATR(10)* ATRratio
set atrTrailing = close - ATR

//set indicators
set ema1 = ema(close,15)
set ema2 = ema(close,50)

//Set Signals
set buyref = ema1 > ema2 //edit this to your buy condition
set sellref = crossover(ema2,ema1) //edit this to your sell condition
set days = countifs(buyref,sellref) 
set maxatr = max(atrtrailing,days)
set atrstop = condref(maxatr,buyref,0,sellref)
set ATRexit2 = crossover(atrstop,close)


set buy = crossover(ema1,ema2) //edit this to your buy condition
set atr_exit = atrexit2
set sell = false //edit this to your sell condition
signals(buy,sell) //edit this to use your main buy and sell condition

This topic was modified 3 months ago 2 times by Mike
Topic starter Posted : 22/07/2021 6:12 pm