ATR Trailing Stop loss Strategy Python

simonofficial
I'm trying to code ATR Trailing Stop loss. But the values are not matching with algo - back tested with streak / Trading view.

ATR Trailing stoploss (multiplier =1 and Period =5). I want to understand how it is calculated.

For example:
Close price crosses above ATR Trailing stoploss (What is the ATR Trailing stoploss here).

Is it previous close + (ATR*Multiplier) or Previous EMA 1 + (ATR*Multiplier)?

It will be helpful if anyone can help me with this part.

I do calculate ATR:
# Define a function to calculate ATR manually
def calculate_atr(df, window=5):
tr = pd.DataFrame()
tr['h-l'] = df['high'] - df['low']
tr['h-pc'] = np.abs(df['high'] - df['close'].shift())
tr['l-pc'] = np.abs(df['low'] - df['close'].shift())
atr = tr.max(axis=1).rolling(window=window).mean()
return atr

Am i doing it right or missing something? What to do with this ATR to get the condition close price crosses above ATR Trailing stop loss?
Sign In or Register to comment.