Я пытаюсь сделать индикатор трейлинг-стопа ATR.Псевдокод выглядит следующим образом:
H = closing_price + ATR
L = closing_price - ATR
If H #new# > H.shift(1) #previous#
H_TS = H.shift(1)
else
H_TS = H
If L #new# > L.shift(1) #previous#
L_TS = L.shift(1)
else
L_TS = L
If closing_price > H_TS
ATR_TS = L_TS
If closing_price < L_TS
ATR_TS = H_TS
Что я пробовал:
'' ''
df = pd.read_csv('EURUSD_pp.csv',index_col='date')
df['h'] = df['bidclose'] + ATR(df['bidclose'],10)*2
df['h_shift']= df['h'].shift(1)
df['ATR_H_line'] = np.NaN
df['ATR_H_line']= np.where((df['h'] > df['hh']),df['hhh'].shift(1),df['h'])
Изображение, которое я ожидаю после визуализации df
:
https://www.photobox.co.uk/my/photo/full?photo_id=501810265125