我正在尝试制作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