如何使用数据框制作ATR追踪止损指示器? (不仅仅是ATR)使用python

时间:2019-04-23 17:44:54

标签: python pandas dataframe analysis

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

0 个答案:

没有答案