Saya mencoba mengatur jual beli di kolom dalam kerangka data kamus. Saya telah membangun fitur seperti ini:

tff = ["GBPUSD","USDJPY","USDCHF","AUDUSD","GBPJPY","EURUSD","EURGBP","GBPCHF","GBPAUD","GBPAUD","USDCAD","EURCHF","EURCAD","AUDCAD","AUDCHF","AUDJPY","CADCHF"]       
TF = ["M1","M2","M3","M4","M5","M6","M10","M12","M15","M20","M30","H1","H2","H3","H4","H6","H8","H12","D1","W1",]

for r in TF:
    for item in tff:
        ratesC =  {item: {r:pd.DataFrame(mt5.copy_rates_from(item, getattr(mt5, 'TIMEFRAME_%s' % r), utc_from ,  288),
           columns=['time', 'open', 'low', 'high', 'close', 'tick_volume', 'spread', 'real_volume']).drop(['tick_volume','spread','real_volume'], axis=1)for r in TF}for item in tff } 

       
for k2, w2 in ratesC.items():
       for r in TF:
            w2[r]['time'] = pd.to_datetime(w2[r]['time'], unit='s')
            w2[r]['MA20'] = (w2['M1']['close'].rolling(window=20).mean())
            w2[r]['MA200'] = w2[r]['close'].rolling(window=200).mean()
            w2[r]['20dSTD'] = w2[r]['close'].rolling(window=20).std()
            w2[r]['Upper'] = w2[r]['MA20'] + (w2[r]['20dSTD'] * 2)
            w2[r]['Lower'] = w2[r]['MA20'] - (w2[r]['20dSTD'] * 2)


Saya mencoba memetakan kondisi dan mengatur kolom ke 1 atau -1 tetapi ini tidak berfungsi dan saya tidak yakin bagaimana melanjutkannya. Apakah saya perlu menggunakan kerangka data?. Mohon saran?

for klk, wlkl in ratesC.values():
       for r in TF:            
         if wlkl[r]['close']  >=  wlkl[r]['AllHigh']:
                 wlkl[r]['AllHighPosition']  = -1
            
         if wlkl[r]['close']  <= wlkl[r]['AllLow1']:
                wlkl[r]['AllHighPosition']  = 1

0
Daniel Hill 11 Juli 2020, 19:58

1 menjawab

Jawaban Terbaik

Anda membandingkan nilai-nilai yang bukan int - itu adalah string, itu sebabnya program tidak bekerja dengan benar.

0
Aleksander Ikleiw 11 Juli 2020, 17:02