import MetaTrader5 as mt5
import pandas as pd
import numpy as np
import re
import datetime
import matplotlib.dates as mdates
import time
import talib
import winsound

#長期の場合OHLCVとEntry_longのPathを短期のPathにする(短期の方はそのまま)     
#短期の場合はtrend_flagを0、長期の場合はtrend_flagを1に変更する(手動)

df = pd.read_csv('C:/Users/xi/MT5/in_dat/common.csv', index_col=0)
use_max = df.iat[0,0]
use = df.iat[0,1]
spread = df.iat[0,2]
use_data = df.iat[0,3]
data_short = df.iat[0,4]
data_long = df.iat[0,5]
max_weight = df.iat[0,6]
indi_number = df.iat[0,8]
trend_flag = df.iat[0,9]
flag = 0

path_ohlcv = 'C:/Users/xi/MT5/in_dat/{}/OHLCV_{}_TRADE.csv'#長期なら短期のPCのpath
path_ohlcv = path_ohlcv.format(use_data,use_data)

if indi_number == 7:
    indi_list = ['EMA','BBAND','MACD','RSI','STOCH','DMI','ULTOSC']
elif indi_number == 15:
    indi_list = ['EMA','BBAND','MACD','RSI','STOCH','WillR','DMI','CCI','MOM','ROC','ULTOSC','TSF','TRIX','AROON','MFI']
path_para = []
for i in range(len(indi_list)):
    path = 'C:/Users/xi/MT5/out_dat/{}/para/para_{}.csv'
    path = path.format(use_data,indi_list[i])
    path_para.append(path)
path_para_df = pd.DataFrame(path_para)

path_Storategy = 'C:/Users/xi/MT5/out_dat/Strategy.csv'
path_Entry_short = 'C:/Users/xi/MT5/out_dat/Entry_short.csv'

path_Entry_long = 'C:/Users/xi/MT5/out_dat/Entry_long.csv'#長期なら短期のPCのpath
path_Position = 'C:/Users/xi/MT5/out_dat/position.csv'#長期なら短期のPCのpath

# MetaTrader 5ターミナルとの接続を確立する
if not mt5.initialize():
   print("initialize() failed, error code =",mt5.last_error())
   quit()

symbol = 'USDJPY'   #取引銘柄
lot = 0.1        #ロットのこと
deviation = 20      #発注後実際に取引が行われるまでのタイムロスの間に値動きがあった場合、slippageの幅以内だったら売買を行う
past_rule = 0
cols = ['time', 'indi', 'order','price','pips']
Entry = pd.DataFrame(index=[], columns=cols)

def ATR(value1,value2,value3,n):
    high = pd.Series(value1)
    low = pd.Series(value2)
    close = pd.Series(value3)
    return talib.ATR(high, low, close, timeperiod=n)

def EMA(values, n):
    close = pd.Series(values)
    return talib.EMA(close, timeperiod=n)

def BBAND(values, n):
    close = pd.Series(values)
    return talib.BBANDS(close, timeperiod=n, nbdevup=2, nbdevdn=2, matype=0)

def MACD(values,l,m,n):
    close = pd.Series(values)
    return talib.MACD(close,fastperiod=m, slowperiod=n, signalperiod=l)

def RSI(values, n):
    close = pd.Series(values)
    return talib.RSI(close, timeperiod=n)

def STOCH(value1,value2, value3, m, n):
    high = pd.Series(value1)
    low = pd.Series(value2)
    close = pd.Series(value3)
    return talib.STOCH(high, low, close, fastk_period=m, slowk_period=n)

def WillR(value1,value2,value3,n):
    high = pd.Series(value1)
    low = pd.Series(value2)
    close = pd.Series(value3)
    return talib.WILLR(high, low, close, timeperiod=n)

def DMI(value1,value2, value3,n):
    high = pd.Series(value1)
    low = pd.Series(value2)
    close = pd.Series(value3)
    ADX = talib.ADX(high, low, close, timeperiod=n)
    DIp = talib.PLUS_DI(high, low, close,timeperiod=n)
    DIm = talib.MINUS_DI(high, low, close,timeperiod=n)
    return ADX, DIp, DIm

def CCI(value1,value2,value3,n):
    high = pd.Series(value1)
    low = pd.Series(value2)
    close = pd.Series(value3)
    return talib.CCI(high, low, close, timeperiod=n)

def MOM(values, n):
    close = pd.Series(values)
    return talib.MOM(close, timeperiod=n)

def ROC(values, n):
    close = pd.Series(values)
    return talib.ROC(close, timeperiod=n)

def ULTOSC(value1,value2, value3, l, m, n):
    high = pd.Series(value1)
    low = pd.Series(value2)
    close = pd.Series(value3)
    return talib.ULTOSC(high, low, close, timeperiod1=l, timeperiod2=m, timeperiod3=n)

def TSF(values, n):
        close = pd.Series(values)
        return talib.TSF(close, timeperiod=n)

def TRIX(value, n):
    close = pd.Series(value)
    return talib.TRIX(close, timeperiod=n)

def AROON(value1,value2,n):
    high = pd.Series(value1)
    low = pd.Series(value2)
    return talib.AROON(high, low, timeperiod=n)

def MFI(value1,value2,value3,value4,n):
    high = pd.Series(value1)
    low = pd.Series(value2)
    close = pd.Series(value3)
    volume = pd.Series(value4)
    return talib.MFI(high, low, close, volume,timeperiod=n)

def order_buy(value):
    
    request = {
        "action": mt5.TRADE_ACTION_DEAL,
        "symbol": symbol,
        "volume": lot,
        "type": mt5.ORDER_TYPE_BUY,
        "price": ask,
        "sl": ask - value * point,
        "tp": ask + (value * point) + (spread * 10 * point),
        "deviation": deviation,
        "magic": 234000,
        "comment": "python script open",
        "type_time": mt5.ORDER_TIME_GTC,
        "type_filling": mt5.ORDER_FILLING_RETURN,
    }
    
    # 取引リクエストを送信する
    #print('buy')
    result = mt5.order_send(request)
    
def order_sell(value):
    request = {
        "action": mt5.TRADE_ACTION_DEAL,
        "symbol": symbol,
        "volume": lot,
        "type": mt5.ORDER_TYPE_SELL,
        "price": bid,
        "sl": bid + value * point,
        "tp": bid - (value * point) - (spread * 10 * point),
        "deviation": deviation,
        "magic": 234000,
        "comment": "python script open",
        "type_time": mt5.ORDER_TIME_GTC,
        "type_filling": mt5.ORDER_FILLING_RETURN,
    }
    
    # 取引リクエストを送信する
    #print('sell')
    result = mt5.order_send(request)

while True:
    try:
        mt5.initialize()
        # データの読み込み
        if indi_number == 15:
            # データの読み込み
            #EMA
            df = pd.read_csv(path_para_df.iat[0,0], index_col=0)
            EMAvalue1 = df.at[0,'EMA1']
            EMAvalue2 = df.at[0,'EMA2']
            ATRvalue_ema = df.at[0,'ATR']
            ATRweight_ema = df.at[0,'ATRweight']
            #BBAND
            df = pd.read_csv(path_para_df.iat[1,0], index_col=0)
            BBANDvalue = df.at[0,'BBAND']
            ATRvalue_bband = df.at[0,'ATR']
            ATRweight_bband = df.at[0,'ATRweight']
            #MACD
            df = pd.read_csv(path_para_df.iat[2,0], index_col=0)
            MACDvalue1 = df.at[0,'MACD1']
            MACDvalue2 = df.at[0,'MACD2']
            MACDvalue3 = df.at[0,'MACD3']
            ATRvalue_macd = df.at[0,'ATR']
            ATRweight_macd = df.at[0,'ATRweight']
            #RSI
            df = pd.read_csv(path_para_df.iat[3,0], index_col=0)
            RSIvalue = df.at[0,'RSI']
            ATRvalue_rsi = df.at[0,'ATR']
            ATRweight_rsi = df.at[0,'ATRweight']
            #STOCH
            df = pd.read_csv(path_para_df.iat[4,0], index_col=0)
            STOCHvalue1 = df.at[0,'STOCH1']
            STOCHvalue2 = df.at[0,'STOCH2']
            ATRvalue_stoch = df.at[0,'ATR']
            ATRweight_stoch = df.at[0,'ATRweight']
            #WillR
            df = pd.read_csv(path_para_df.iat[5,0], index_col=0)
            WillRvalue = df.at[0,'WillR']
            ATRvalue_willr = df.at[0,'ATR']
            ATRweight_willr = df.at[0,'ATRweight']
            #DMI
            df = pd.read_csv(path_para_df.iat[6,0], index_col=0)
            DMIvalue = df.at[0,'DMI']
            ATRvalue_dmi = df.at[0,'ATR']
            ATRweight_dmi = df.at[0,'ATRweight']
            #CCI
            df = pd.read_csv(path_para_df.iat[7,0], index_col=0)
            CCIvalue = df.at[0,'CCI']
            ATRvalue_cci = df.at[0,'ATR']
            ATRweight_cci = df.at[0,'ATRweight']
            #MOM
            df = pd.read_csv(path_para_df.iat[8,0], index_col=0)
            MOMvalue = df.at[0,'MOM']
            ATRvalue_mom = df.at[0,'ATR']
            ATRweight_mom = df.at[0,'ATRweight']
            #ROC
            df = pd.read_csv(path_para_df.iat[9,0], index_col=0)
            ROCvalue = df.at[0,'ROC']
            ATRvalue_roc = df.at[0,'ATR']
            ATRweight_roc = df.at[0,'ATRweight']
            #ULTOSC
            df = pd.read_csv(path_para_df.iat[10,0], index_col=0)
            ULTOSCvalue1 = df.at[0,'ULTOSC1']
            ULTOSCvalue2 = df.at[0,'ULTOSC2']
            ULTOSCvalue3 = df.at[0,'ULTOSC3']
            ATRvalue_ultosc = df.at[0,'ATR']
            ATRweight_ultosc = df.at[0,'ATRweight']
            #TSF
            df = pd.read_csv(path_para_df.iat[11,0], index_col=0)
            TSFvalue = df.at[0,'TSF']
            ATRvalue_tsf = df.at[0,'ATR']
            ATRweight_tsf = df.at[0,'ATRweight']
            #TRIX
            df = pd.read_csv(path_para_df.iat[12,0], index_col=0)
            TRIXvalue = df.at[0,'TRIX']
            ATRvalue_trix = df.at[0,'ATR']
            ATRweight_trix = df.at[0,'ATRweight']
            #AROON
            df = pd.read_csv(path_para_df.iat[13,0], index_col=0)
            AROONvalue = df.at[0,'AROON']
            ATRvalue_aroon = df.at[0,'ATR']
            ATRweight_aroon = df.at[0,'ATRweight']
            #MFI
            df = pd.read_csv(path_para_df.iat[14,0], index_col=0)
            MFIvalue = df.at[0,'MFI']
            ATRvalue_mfi = df.at[0,'ATR']
            ATRweight_mfi = df.at[0,'ATRweight']
        if indi_number == 7:
            # データの読み込み
            #EMA
            df = pd.read_csv(path_para_df.iat[0,0], index_col=0)
            EMAvalue1 = df.at[0,'EMA1']
            EMAvalue2 = df.at[0,'EMA2']
            ATRvalue_ema = df.at[0,'ATR']
            ATRweight_ema = df.at[0,'ATRweight']
            #BBAND
            df = pd.read_csv(path_para_df.iat[1,0], index_col=0)
            BBANDvalue = df.at[0,'BBAND']
            ATRvalue_bband = df.at[0,'ATR']
            ATRweight_bband = df.at[0,'ATRweight']
            #MACD
            df = pd.read_csv(path_para_df.iat[2,0], index_col=0)
            MACDvalue1 = df.at[0,'MACD1']
            MACDvalue2 = df.at[0,'MACD2']
            MACDvalue3 = df.at[0,'MACD3']
            ATRvalue_macd = df.at[0,'ATR']
            ATRweight_macd = df.at[0,'ATRweight']
            #RSI
            df = pd.read_csv(path_para_df.iat[3,0], index_col=0)
            RSIvalue = df.at[0,'RSI']
            ATRvalue_rsi = df.at[0,'ATR']
            ATRweight_rsi = df.at[0,'ATRweight']
            #STOCH
            df = pd.read_csv(path_para_df.iat[4,0], index_col=0)
            STOCHvalue1 = df.at[0,'STOCH1']
            STOCHvalue2 = df.at[0,'STOCH2']
            ATRvalue_stoch = df.at[0,'ATR']
            ATRweight_stoch = df.at[0,'ATRweight']
            #DMI
            df = pd.read_csv(path_para_df.iat[5,0], index_col=0)
            DMIvalue = df.at[0,'DMI']
            ATRvalue_dmi = df.at[0,'ATR']
            ATRweight_dmi = df.at[0,'ATRweight']
            #ULTOSC
            df = pd.read_csv(path_para_df.iat[6,0], index_col=0)
            ULTOSCvalue1 = df.at[0,'ULTOSC1']
            ULTOSCvalue2 = df.at[0,'ULTOSC2']
            ULTOSCvalue3 = df.at[0,'ULTOSC3']
            ATRvalue_ultosc = df.at[0,'ATR']
            ATRweight_ultosc = df.at[0,'ATRweight']
        #最適
        df = pd.read_csv(path_Storategy, index_col=0)
        rule_number = df.iat[0,0]
        #ポジションの有無
        df = pd.read_csv(path_Position, index_col=0)
        posi = df.iat[0,0]
        #長期のトレンド確認
        if data_long == '10S':
            df = pd.read_csv(path_Entry_long, index_col=0)
            df = df.tail(1)
            df = df.reset_index(drop=True)
            order = df.at[0,'order']
        if data_long == '30S':
            df = pd.read_csv(path_Entry_long, index_col=0)
            df = df.tail(1)
            df = df.reset_index(drop=True)
            order = df.at[0,'order']
        if data_long == '1T':
            df = pd.read_csv(path_Entry_long, index_col=0)
            df = df.tail(1)
            df = df.reset_index(drop=True)
            order = df.at[0,'order']
        if data_long == '3T':
            df = pd.read_csv(path_Entry_long, index_col=0)
            df = df.tail(1)
            df = df.reset_index(drop=True)
            order = df.at[0,'order']
        if data_long == '5T':
            df = pd.read_csv(path_Entry_long, index_col=0)
            df = df.tail(1)
            df = df.reset_index(drop=True)
            order = df.at[0,'order']
        if data_long == '10T':
            df = pd.read_csv(path_Entry_long, index_col=0)
            df = df.tail(1)
            df = df.reset_index(drop=True)
            order = df.at[0,'order']
        if data_long == '15T':
            df = pd.read_csv(path_Entry_long, index_col=0)
            df = df.tail(1)
            df = df.reset_index(drop=True)
            order = df.at[0,'order']

        #長期の場合OHLCVのPathだけ短期のPathにする(短期の方はそのまま)
        #最終行を取得---------
        lastRow = sum(1 for line in open(path_ohlcv)) - 2
        #最終行からuse_max行の行数を求める
        pickRow = [lastRow - line for line in range(use_max)]
        pickRow.reverse()
        df = pd.read_csv(path_ohlcv, header=None,skiprows=lambda x: x not in pickRow)
        df.columns = ['time','Open','High','Low','Close','Volume']
        df = df.drop(0)
        # timeの型変換
        # datetime型にする
        df = df.astype({'Open':float,'High':float,'Low':float,'Close':float,'Volume':float})
        df_first = df.tail(1)
        ohlcv_last = df_first.iat[0,0]
        ohlcv_last = pd.to_datetime(ohlcv_last)
        dt_now = datetime.datetime.now()
        dt_now = pd.to_datetime(dt_now)
        td = dt_now - ohlcv_last
        if use_data == 'short':
            if data_short == '10S':
                if td.seconds < 30:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_short == '30S':
                if td.seconds < 90:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_short == '1T':
                if td.seconds < 180:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_short == '3T':
                if td.seconds < 540:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_short == '5T':
                if td.seconds < 900:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_short == '10T':
                if td.seconds < 1800:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_short == '15T':
                if td.seconds < 2700:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
        if use_data == 'long':    
            if data_long == '10S':
                if td.seconds < 30:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_long == '30S':
                if td.seconds < 90:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_long == '1T':
                if td.seconds < 180:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_long == '3T':
                if td.seconds < 540:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_long == '5T':
                if td.seconds < 900:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_long == '10T':
                if td.seconds < 1800:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            if data_long == '15T':
                if td.seconds < 2700:
                    flag = 1
                    df["time"] = pd.to_datetime(df["time"])
                    df = df.set_index('time')
                else:
                    flag = 0
            
        if flag == 1:
            #NaN回避
            nan_count = df.isnull().sum()
            nan_count_sum = 0
            for i in range(len(nan_count)):
                nan_count_sum = nan_count_sum + nan_count[i]
            #OHLCVにNaNが含まれてなかった場合のみ次へ
            if nan_count_sum == 0:
                if indi_number == 15:
                    atr_ema = ATR(df['High'], df['Low'], df['Close'], ATRvalue_ema)
                    atr_bband = ATR(df['High'], df['Low'], df['Close'], ATRvalue_bband)
                    atr_macd = ATR(df['High'], df['Low'], df['Close'], ATRvalue_macd)
                    atr_rsi = ATR(df['High'], df['Low'], df['Close'], ATRvalue_rsi)
                    atr_stoch = ATR(df['High'], df['Low'], df['Close'], ATRvalue_stoch)
                    atr_willr = ATR(df['High'], df['Low'], df['Close'], ATRvalue_willr)
                    atr_dmi = ATR(df['High'], df['Low'], df['Close'], ATRvalue_dmi)
                    atr_cci = ATR(df['High'], df['Low'], df['Close'], ATRvalue_cci)
                    atr_mom = ATR(df['High'], df['Low'], df['Close'], ATRvalue_mom)
                    atr_roc = ATR(df['High'], df['Low'], df['Close'], ATRvalue_roc)
                    atr_ultosc = ATR(df['High'], df['Low'], df['Close'], ATRvalue_ultosc)
                    atr_tsf = ATR(df['High'], df['Low'], df['Close'], ATRvalue_tsf)
                    atr_trix = ATR(df['High'], df['Low'], df['Close'], ATRvalue_trix)
                    atr_aroon = ATR(df['High'], df['Low'], df['Close'], ATRvalue_aroon)
                    atr_mfi = ATR(df['High'], df['Low'], df['Close'], ATRvalue_mfi)

                    ema1 = EMA(df['Close'], EMAvalue1)
                    ema2 = EMA(df['Close'], EMAvalue2)
                    bband_upper, bband_middle, bband_lower = BBAND(df['Close'], BBANDvalue)
                    macd, macdsignal, macdhist = MACD(df['Close'], MACDvalue1, MACDvalue2, MACDvalue3)
                    rsi = RSI(df['Close'], RSIvalue)
                    K, D = STOCH(df['High'], df['Low'], df['Close'], STOCHvalue1, STOCHvalue2)
                    willr = WillR(df['High'], df['Low'], df['Close'], WillRvalue)
                    adx, dip, dim = DMI(df['High'], df['Low'], df['Close'], DMIvalue)
                    cci = CCI(df['High'], df['Low'], df['Close'], CCIvalue)
                    mom = MOM(df['Close'], MOMvalue)
                    roc = ROC(df['Close'], ROCvalue)
                    ultosc = ULTOSC(df['High'], df['Low'], df['Close'], ULTOSCvalue1, ULTOSCvalue2, ULTOSCvalue3)
                    tsf = TSF(df['Close'], TSFvalue)
                    trix = TRIX(df['Close'], TRIXvalue)
                    aroondown, aroonup = AROON(df['High'], df['Low'], AROONvalue)
                    mfi = MFI(df['High'], df['Low'], df['Close'], df['Volume'], MFIvalue)
                if indi_number == 7:
                    atr_ema = ATR(df['High'], df['Low'], df['Close'], ATRvalue_ema)
                    atr_bband = ATR(df['High'], df['Low'], df['Close'], ATRvalue_bband)
                    atr_macd = ATR(df['High'], df['Low'], df['Close'], ATRvalue_macd)
                    atr_rsi = ATR(df['High'], df['Low'], df['Close'], ATRvalue_rsi)
                    atr_stoch = ATR(df['High'], df['Low'], df['Close'], ATRvalue_stoch)
                    atr_dmi = ATR(df['High'], df['Low'], df['Close'], ATRvalue_dmi)
                    atr_ultosc = ATR(df['High'], df['Low'], df['Close'], ATRvalue_ultosc)

                    ema1 = EMA(df['Close'], EMAvalue1)
                    ema2 = EMA(df['Close'], EMAvalue2)
                    bband_upper, bband_middle, bband_lower = BBAND(df['Close'], BBANDvalue)
                    macd, macdsignal, macdhist = MACD(df['Close'], MACDvalue1, MACDvalue2, MACDvalue3)
                    rsi = RSI(df['Close'], RSIvalue)
                    K, D = STOCH(df['High'], df['Low'], df['Close'], STOCHvalue1, STOCHvalue2)
                    adx, dip, dim = DMI(df['High'], df['Low'], df['Close'], DMIvalue)
                    ultosc = ULTOSC(df['High'], df['Low'], df['Close'], ULTOSCvalue1, ULTOSCvalue2, ULTOSCvalue3)

                symbol_info = mt5.symbol_info(symbol)
                if symbol_info is None:
                    print(symbol, "not found, can not call order_check()")
                
                point = mt5.symbol_info(symbol).point
                ask = mt5.symbol_info_tick(symbol).ask
                bid = mt5.symbol_info_tick(symbol).bid
                real_spread = ask - bid 
                #短期で使用するとき
                if trend_flag == 0:
                    if indi_number == 7:
                        #最適なルールを01に変換
                        rule = list(format(rule_number,'07b'))
                        rule = np.array(rule,dtype='int64')
                        #indi表示
                        if rule_number != past_rule:
                            dt_now = datetime.datetime.now()
                            print('---------------------------')
                            print(dt_now)
                            print('rule_number = ',rule_number)
                            print(rule)
                            print('インジケーター')
                            for i in range(len(rule)):
                                if rule[i] == 1:
                                    print(indi_list[i])
                            past_rule = rule_number
                        if posi == 1:
                            if order == 'buy':
                                #buy
                                if rule[0] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if  max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                            if (ema1[-2] < ema2[-2] and ema1[-1] > ema2[-1]): 
                                                print('EMA買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_ema[-1] * ATRweight_ema *1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'EMA'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[1] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if  max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                            if (bband_lower[-2] > df.Close[-2] and bband_lower[-1] < df.Close[-1]): 
                                                print('BBAND買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_bband[-1] * ATRweight_bband *1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'BBAND'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[2] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03:
                                            if (macd[-2] < macdsignal[-2] and macd[-1] > macdsignal[-1] and macd[-1] < 0 and macdsignal[-1] < 0):
                                                print('MACD買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_macd[-1] * ATRweight_macd*1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'MACD'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[3] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                            if (rsi[-2] < 30 and rsi[-1] > 30): 
                                                print('RSI買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_rsi[-1] * ATRweight_rsi * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'RSI'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[4] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                            if (D[-2] > K[-2] and D[-1] < K[-1] and D[-1] < 20 and K[-1] < 20): 
                                                print('STOCH買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_stoch[-1] * ATRweight_stoch * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'STOCH'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[5] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                            if (dim[-2] > dip[-2] and dim[-1] < dip[-1] and dim[-1] < adx[-1]): 
                                                print('DMI買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_dmi[-1] * ATRweight_dmi * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'DMI'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[6] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_ultosc[-1] * ATRweight_ultosc >= 0.03:
                                            if (ultosc[-2] < 30 and ultosc[-1] > 30): 
                                                print('ULTOSC買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'ULTOSC'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                            if order == 'sell':    
                                #sell
                                if rule[0] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                            if (ema1[-2] > ema2[-2] and ema1[-1] < ema2[-1]):
                                                print('EMA売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_ema[-1] * ATRweight_ema * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'EMA'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                            
                                if rule[1] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:    
                                        if max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                            if (bband_upper[-2] < df.Close[-2] and bband_upper[-1] > df.Close[-1]):
                                                print('BBAND売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_bband[-1] * ATRweight_bband * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'BBAND'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[2] == 1:   
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0: 
                                        if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03: 
                                            if (macd[-2] > macdsignal[-2] and macd[-1] < macdsignal[-1] and macd[-1] > 0 and macdsignal[-1] > 0):
                                                print('MACD売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_macd[-1] * ATRweight_macd * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'MACD'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[3] == 1:    
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0: 
                                        if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                            if (rsi[-2] > 70 and rsi[-1] < 70):
                                                print('RSI売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_rsi[-1] * ATRweight_rsi * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'RSI'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[4] == 1: 
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                            if (D[-2] < K[-2] and D[-1] > K[-1] and D[-1] > 80 and K[-1] > 80):
                                                print('STOCH売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_stoch[-1] * ATRweight_stoch * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'STOCH'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[5] == 1: 
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:     
                                        if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                            if (dim[-2] < dip[-2] and dim[-1] > dip[-1] and dip[-1] < adx[-1]):
                                                print('DMI売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_dmi[-1] * ATRweight_dmi * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'DMI'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[6] == 1:    
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_ultosc[-1] * ATRweight_ultosc>= 0.03:
                                            if (ultosc[-2] > 70 and ultosc[-1] < 70):
                                                print('ULTOSC売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'ULTOSC'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                    if indi_number == 15:
                        rule = list(format(value,'015b'))
                        rule = np.array(rule,dtype='int64')
                        #indi表示
                        if rule_number != past_rule:
                            dt_now = datetime.datetime.now()
                            print('---------------------------')
                            print(dt_now)
                            print('rule_number = ',rule_number)
                            print(rule)
                            print('インジケーター')
                            for i in range(len(rule)):
                                if rule[i] == 1:
                                    print(indi_list[i])
                            past_rule = rule_number
                        if posi == 1:
                            if order == 'buy':
                                #buy
                                if rule[0] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if  max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                            if (ema1[-2] < ema2[-2] and ema1[-1] > ema2[-1]): 
                                                print('EMA買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_ema[-1] * ATRweight_ema *1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'EMA'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[1] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if  max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                            if (bband_lower[-2] > df.Close[-2] and bband_lower[-1] < df.Close[-1]): 
                                                print('BBAND買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_bband[-1] * ATRweight_bband *1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'BBAND'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[2] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03:
                                            if (macd[-2] < macdsignal[-2] and macd[-1] > macdsignal[-1] and macd[-1] < 0 and macdsignal[-1] < 0):
                                                print('MACD買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_macd[-1] * ATRweight_macd*1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'MACD'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[3] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                            if (rsi[-2] < 30 and rsi[-1] > 30): 
                                                print('RSI買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_rsi[-1] * ATRweight_rsi * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'RSI'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[4] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                            if (D[-2] > K[-2] and D[-1] < K[-1] and D[-1] < 20 and K[-1] < 20): 
                                                print('STOCH買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_stoch[-1] * ATRweight_stoch * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'STOCH'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[5] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_willr[-1] * ATRweight_willr >= 0.03:
                                            if (willr[-2] < -80 and willr[-1] > -80): 
                                                print('willr買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_willr[-1] * ATRweight_willr * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'WILLR'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)                        

                                if rule[6] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                            if (dim[-2] > dip[-2] and dim[-1] < dip[-1] and dim[-1] < adx[-1]): 
                                                print('DMI買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_dmi[-1] * ATRweight_dmi * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'DMI'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)                        

                                if rule[7] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_cci[-1] * ATRweight_cci >= 0.03:
                                            if (cci[-2] < -100 and cci[-1] > -100): 
                                                print('CCI買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_cci[-1] * ATRweight_cci * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'CCI'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[8] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_mom[-1] * ATRweight_mom >= 0.03:
                                            if (mom[-2] < -30 and mom[-1] > -30): 
                                                print('MOM買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_mom[-1] * ATRweight_mom * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'MOM'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)                

                                if rule[9] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_roc[-1] * ATRweight_roc >= 0.03:
                                            if (roc[-2] < -30 and roc[-1] > -30): 
                                                print('ROC買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_roc[-1] * ATRweight_roc * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'ROC'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                                
                                if rule[10] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_ultosc[-1] * ATRweight_ultosc >= 0.03:
                                            if (ultosc[-2] < 30 and ultosc[-1] > 30): 
                                                print('ULTOSC買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'ULTOSC'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[11] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_tsf[-1] * ATRweight_tsf >= 0.03:
                                            if (tsf[-3] < tsf[-2]  and tsf[-2] < tsf[-1] and df.iat[-1, 3] < tsf[-1] ): 
                                                print('TSF買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_tsf[-1] * ATRweight_tsf * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'TSF'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[12] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_trix[-1] * ATRweight_trix >= 0.03:
                                            if (trix[-2] < 30 and trix[-1] > 30): 
                                                print('TRIX買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_trix[-1] * ATRweight_trix * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'TRIX'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[13] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_aroon[-1] * ATRweight_aroon >= 0.03:
                                            if (aroonup[-2] < aroondown[-2] and aroonup[-1] > aroondown[-1]): 
                                                print('AROONUP買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_aroon[-1] * ATRweight_aroon * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'aroonup'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)                

                                if rule[14] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_mfi[-1] * ATRweight_mfi >= 0.03:
                                            if (mfi[-2] < 20 and mfi[-1] > 20): 
                                                print('MFI買います')
                                                winsound.Beep(2000, 500)
                                                value = atr_mfi[-1] * ATRweight_mfi * 1000
                                                value = int(value)
                                                order_buy(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('ask =',ask)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'mfi'
                                                order = 'buy'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)                    
                            if order == 'sell':    
                                #sell
                                if rule[0] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:
                                        if max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                            if (ema1[-2] > ema2[-2] and ema1[-1] < ema2[-1]):
                                                print('EMA売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_ema[-1] * ATRweight_ema * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'EMA'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[1] == 1:
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:    
                                        if max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                            if (bband_upper[-2] < df.Close[-2] and bband_upper[-1] > df.Close[-1]):
                                                print('BBAND売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_bband[-1] * ATRweight_bband * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'BBAND'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[2] == 1:   
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0: 
                                        if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03: 
                                            if (macd[-2] > macdsignal[-2] and macd[-1] < macdsignal[-1] and macd[-1] > 0 and macdsignal[-1] > 0):
                                                print('MACD売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_macd[-1] * ATRweight_macd * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'MACD'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[3] == 1:    
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0: 
                                        if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                            if (rsi[-2] > 70 and rsi[-1] < 70):
                                                print('RSI売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_rsi[-1] * ATRweight_rsi * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'RSI'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[4] == 1: 
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                            if (D[-2] < K[-2] and D[-1] > K[-1] and D[-1] > 80 and K[-1] > 80):
                                                print('STOCH売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_stoch[-1] * ATRweight_stoch * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'STOCH'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[5] == 1: 
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_willr[-1] * ATRweight_willr >= 0.03:
                                            if (willr[-2] > -20 and willr[-1] < -20):
                                                print('WILLR売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_willr[-1] * ATRweight_willr * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'WILLR'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[6] == 1: 
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:     
                                        if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                            if (dim[-2] < dip[-2] and dim[-1] > dip[-1] and dip[-1] < adx[-1]):
                                                print('DMI売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_dmi[-1] * ATRweight_dmi * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'DMI'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[7] == 1: 
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:     
                                        if max_weight >= atr_cci[-1] * ATRweight_cci >= 0.03:
                                            if (cci[-2] > 100 and cci[-1] < 100):
                                                print('CCI売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_cci[-1] * ATRweight_cci * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'CCI'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[8] == 1: 
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:     
                                        if max_weight >= atr_mom[-1] * ATRweight_mom >= 0.03:
                                            if (mom[-2] > 30 and mom[-1] < 30):
                                                print('MOM売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_mom[-1] * ATRweight_mom * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'MOM'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                            
                                if rule[9] == 1: 
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:     
                                        if max_weight >= atr_roc[-1] * ATRweight_roc >= 0.03:
                                            if (roc[-2] > 30 and roc[-1] < 30):
                                                print('ROC売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_roc[-1] * ATRweight_roc * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'ROC'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[10] == 1:    
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_ultosc[-1] * ATRweight_ultosc>= 0.03:
                                            if (ultosc[-2] > 70 and ultosc[-1] < 70):
                                                print('ULTOSC売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'ULTOSC'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[11] == 1:    
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_tsf[-1] * ATRweight_tsf>= 0.03:
                                            if (tsf[-3] > tsf[-2]  and tsf[-2] > tsf[-1] and df.iat[-1, 3] > tsf[-1]):
                                                print('TSF売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_tsf[-1] * ATRweight_tsf * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'TSF'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[12] == 1:    
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_trix[-1] * ATRweight_trix>= 0.03:
                                            if (trix[-2] > 30 and trix[-1] < 30):
                                                print('TRIX売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_trix[-1] * ATRweight_trix * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'TRIX'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[13] == 1:    
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_aroon[-1] * ATRweight_aroon>= 0.03:
                                            if (aroonup[-2] > aroondown[-2] and aroonup[-1] < aroondown[-1]):
                                                print('AROONUP売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_aroon[-1] * ATRweight_aroon * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'AROONUP'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)

                                if rule[14] == 1:    
                                    positions=mt5.positions_get(symbol="USDJPY")
                                    if len(positions) == 0:  
                                        if max_weight >= atr_mfi[-1] * ATRweight_mfi >= 0.03:
                                            if (mfi[-2] > 80 and mfi[-1] < 80):
                                                print('MFI売ります')
                                                winsound.Beep(2000, 500)
                                                value = atr_mfi[-1] * ATRweight_mfi * 1000
                                                value = int(value)
                                                order_sell(value)
                                                entrytime = df.tail(1)
                                                entrytime = entrytime.reset_index()
                                                lasttime = entrytime.iat[0,0]
                                                print('time =',lasttime)
                                                print('bid =',bid)
                                                print('spread =',real_spread)
                                                print('tp & sl =',value*0.1,'pips')
                                                indi = 'MFI'
                                                order = 'sell'
                                                pips = value*0.1
                                                entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                                Entry = Entry.append(entry, ignore_index=True)
                                                Entry.to_csv(path_Entry_short,  index=True, header=True)
                
                    if data_short == '10S':
                        time.sleep(11)
                    if data_short == '30S':
                        time.sleep(31)
                    if data_short == '1T':
                        time.sleep(61)
                    if data_short == '3T':
                        time.sleep(181)
                    if data_short == '5T':
                        time.sleep(301)
                    if data_short == '10T':
                        time.sleep(601)
                    if data_short == '15T':
                        time.sleep(901)                 
                #長期で使用するとき
                #長期の場合EntryのPathを短期のPathにする(短期の方はそのまま)        
                elif trend_flag == 1:
                    positions=mt5.positions_get(symbol="USDJPY")
                    position = []
                    position.append(len(positions))
                    position = pd.DataFrame(position)
                    position.to_csv(path_Position,  index=True, header=True)
                    if indi_number == 7:
                        #最適なルールを01に変換
                        rule = list(format(rule_number,'07b'))
                        rule = np.array(rule,dtype='int64')
                        #indi表示
                        if rule_number != past_rule:
                            dt_now = datetime.datetime.now()
                            print('---------------------------')
                            print(dt_now)
                            print('rule_number = ',rule_number)
                            print(rule)
                            print('インジケーター')
                            for i in range(len(rule)):
                                if rule[i] == 1:
                                    print(indi_list[i])
                            past_rule = rule_number
                        #buy
                        if rule[0] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if  max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                    if (ema1[-2] < ema2[-2] and ema1[-1] > ema2[-1]): 
                                        print('EMA買います')
                                        value = atr_ema[-1] * ATRweight_ema *1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'EMA'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[1] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if  max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                    if (bband_lower[-2] > df.Close[-2] and bband_lower[-1] < df.Close[-1]): 
                                        print('BBAND買います')
                                        value = atr_bband[-1] * ATRweight_bband *1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'BBAND'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[2] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03:
                                    if (macd[-2] < macdsignal[-2] and macd[-1] > macdsignal[-1] and macd[-1] < 0 and macdsignal[-1] < 0):
                                        print('MACD買います')
                                        value = atr_macd[-1] * ATRweight_macd*1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MACD'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[3] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                    if (rsi[-2] < 30 and rsi[-1] > 30): 
                                        print('RSI買います')
                                        value = atr_rsi[-1] * ATRweight_rsi * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'RSI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[4] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                    if (D[-2] > K[-2] and D[-1] < K[-1] and D[-1] < 20 and K[-1] < 20): 
                                        print('STOCH買います')
                                        value = atr_stoch[-1] * ATRweight_stoch * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'STOCH'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[5] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                    if (dim[-2] > dip[-2] and dim[-1] < dip[-1] and dim[-1] < adx[-1]): 
                                        print('DMI買います')
                                        value = atr_dmi[-1] * ATRweight_dmi * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'DMI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[6] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_ultosc[-1] * ATRweight_ultosc >= 0.03:
                                    if (ultosc[-2] < 30 and ultosc[-1] > 30): 
                                        print('ULTOSC買います')
                                        value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ULTOSC'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        #sell
                        if rule[0] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                    if (ema1[-2] > ema2[-2] and ema1[-1] < ema2[-1]):
                                        print('EMA売ります')
                                        value = atr_ema[-1] * ATRweight_ema * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'EMA'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                                    
                        if rule[1] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:    
                                if max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                    if (bband_upper[-2] < df.Close[-2] and bband_upper[-1] > df.Close[-1]):
                                        print('BBAND売ります')
                                        value = atr_bband[-1] * ATRweight_bband * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'BBAND'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[2] == 1:   
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0: 
                                if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03: 
                                    if (macd[-2] > macdsignal[-2] and macd[-1] < macdsignal[-1] and macd[-1] > 0 and macdsignal[-1] > 0):
                                        print('MACD売ります')
                                        value = atr_macd[-1] * ATRweight_macd * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MACD'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[3] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0: 
                                if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                    if (rsi[-2] > 70 and rsi[-1] < 70):
                                        print('RSI売ります')
                                        value = atr_rsi[-1] * ATRweight_rsi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'RSI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[4] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                    if (D[-2] < K[-2] and D[-1] > K[-1] and D[-1] > 80 and K[-1] > 80):
                                        print('STOCH売ります')
                                        value = atr_stoch[-1] * ATRweight_stoch * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'STOCH'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[5] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                    if (dim[-2] < dip[-2] and dim[-1] > dip[-1] and dip[-1] < adx[-1]):
                                        print('DMI売ります')
                                        value = atr_dmi[-1] * ATRweight_dmi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'DMI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[6] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_ultosc[-1] * ATRweight_ultosc>= 0.03:
                                    if (ultosc[-2] > 70 and ultosc[-1] < 70):
                                        print('ULTOSC売ります')
                                        value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ULTOSC'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                    if indi_number == 15:
                        rule = list(format(value,'015b'))
                        rule = np.array(rule,dtype='int64')
                        #indi表示
                        if rule_number != past_rule:
                            dt_now = datetime.datetime.now()
                            print('---------------------------')
                            print(dt_now)
                            print('rule_number = ',rule_number)
                            print(rule)
                            print('インジケーター')
                            for i in range(len(rule)):
                                if rule[i] == 1:
                                    print(indi_list[i])
                            past_rule = rule_number

                        #buy
                        if rule[0] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if  max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                    if (ema1[-2] < ema2[-2] and ema1[-1] > ema2[-1]): 
                                        print('EMA買います')
                                        value = atr_ema[-1] * ATRweight_ema *1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'EMA'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[1] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if  max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                    if (bband_lower[-2] > df.Close[-2] and bband_lower[-1] < df.Close[-1]): 
                                        print('BBAND買います')
                                        value = atr_bband[-1] * ATRweight_bband *1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'BBAND'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[2] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03:
                                    if (macd[-2] < macdsignal[-2] and macd[-1] > macdsignal[-1] and macd[-1] < 0 and macdsignal[-1] < 0):
                                        print('MACD買います')
                                        value = atr_macd[-1] * ATRweight_macd*1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MACD'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[3] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                    if (rsi[-2] < 30 and rsi[-1] > 30): 
                                        print('RSI買います')
                                        value = atr_rsi[-1] * ATRweight_rsi * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'RSI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[4] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                    if (D[-2] > K[-2] and D[-1] < K[-1] and D[-1] < 20 and K[-1] < 20): 
                                        print('STOCH買います')
                                        value = atr_stoch[-1] * ATRweight_stoch * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'STOCH'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[5] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_willr[-1] * ATRweight_willr >= 0.03:
                                    if (willr[-2] < -80 and willr[-1] > -80): 
                                        print('willr買います')
                                        value = atr_willr[-1] * ATRweight_willr * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'WILLR'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)                        

                        if rule[6] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                    if (dim[-2] > dip[-2] and dim[-1] < dip[-1] and dim[-1] < adx[-1]): 
                                        print('DMI買います')
                                        value = atr_dmi[-1] * ATRweight_dmi * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'DMI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)                        

                        if rule[7] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_cci[-1] * ATRweight_cci >= 0.03:
                                    if (cci[-2] < -100 and cci[-1] > -100): 
                                        print('CCI買います')
                                        value = atr_cci[-1] * ATRweight_cci * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'CCI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[8] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_mom[-1] * ATRweight_mom >= 0.03:
                                    if (mom[-2] < -30 and mom[-1] > -30): 
                                        print('MOM買います')
                                        value = atr_mom[-1] * ATRweight_mom * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MOM'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)                

                        if rule[9] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_roc[-1] * ATRweight_roc >= 0.03:
                                    if (roc[-2] < -30 and roc[-1] > -30): 
                                        print('ROC買います')
                                        value = atr_roc[-1] * ATRweight_roc * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ROC'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                        
                        if rule[10] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_ultosc[-1] * ATRweight_ultosc >= 0.03:
                                    if (ultosc[-2] < 30 and ultosc[-1] > 30): 
                                        print('ULTOSC買います')
                                        value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ULTOSC'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[11] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_tsf[-1] * ATRweight_tsf >= 0.03:
                                    if (tsf[-3] < tsf[-2]  and tsf[-2] < tsf[-1] and df.iat[-1, 3] < tsf[-1] ): 
                                        print('TSF買います')
                                        value = atr_tsf[-1] * ATRweight_tsf * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'TSF'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[12] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_trix[-1] * ATRweight_trix >= 0.03:
                                    if (trix[-2] < 30 and trix[-1] > 30): 
                                        print('TRIX買います')
                                        value = atr_trix[-1] * ATRweight_trix * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'TRIX'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[13] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_aroon[-1] * ATRweight_aroon >= 0.03:
                                    if (aroonup[-2] < aroondown[-2] and aroonup[-1] > aroondown[-1]): 
                                        print('AROONUP買います')
                                        value = atr_aroon[-1] * ATRweight_aroon * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'aroonup'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)                

                        if rule[14] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_mfi[-1] * ATRweight_mfi >= 0.03:
                                    if (mfi[-2] < 20 and mfi[-1] > 20): 
                                        print('MFI買います')
                                        value = atr_mfi[-1] * ATRweight_mfi * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'mfi'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)                    
    
                        #sell
                        if rule[0] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                    if (ema1[-2] > ema2[-2] and ema1[-1] < ema2[-1]):
                                        print('EMA売ります')
                                        value = atr_ema[-1] * ATRweight_ema * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'EMA'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[1] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:    
                                if max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                    if (bband_upper[-2] < df.Close[-2] and bband_upper[-1] > df.Close[-1]):
                                        print('BBAND売ります')
                                        value = atr_bband[-1] * ATRweight_bband * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'BBAND'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[2] == 1:   
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0: 
                                if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03: 
                                    if (macd[-2] > macdsignal[-2] and macd[-1] < macdsignal[-1] and macd[-1] > 0 and macdsignal[-1] > 0):
                                        print('MACD売ります')
                                        value = atr_macd[-1] * ATRweight_macd * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MACD'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[3] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0: 
                                if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                    if (rsi[-2] > 70 and rsi[-1] < 70):
                                        print('RSI売ります')
                                        value = atr_rsi[-1] * ATRweight_rsi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'RSI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[4] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                    if (D[-2] < K[-2] and D[-1] > K[-1] and D[-1] > 80 and K[-1] > 80):
                                        print('STOCH売ります')
                                        value = atr_stoch[-1] * ATRweight_stoch * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'STOCH'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[5] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_willr[-1] * ATRweight_willr >= 0.03:
                                    if (willr[-2] > -20 and willr[-1] < -20):
                                        print('WILLR売ります')
                                        value = atr_willr[-1] * ATRweight_willr * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'WILLR'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[6] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                    if (dim[-2] < dip[-2] and dim[-1] > dip[-1] and dip[-1] < adx[-1]):
                                        print('DMI売ります')
                                        value = atr_dmi[-1] * ATRweight_dmi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'DMI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[7] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_cci[-1] * ATRweight_cci >= 0.03:
                                    if (cci[-2] > 100 and cci[-1] < 100):
                                        print('CCI売ります')
                                        value = atr_cci[-1] * ATRweight_cci * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'CCI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[8] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_mom[-1] * ATRweight_mom >= 0.03:
                                    if (mom[-2] > 30 and mom[-1] < 30):
                                        print('MOM売ります')
                                        value = atr_mom[-1] * ATRweight_mom * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MOM'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                    
                        if rule[9] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_roc[-1] * ATRweight_roc >= 0.03:
                                    if (roc[-2] > 30 and roc[-1] < 30):
                                        print('ROC売ります')
                                        value = atr_roc[-1] * ATRweight_roc * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ROC'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[10] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_ultosc[-1] * ATRweight_ultosc>= 0.03:
                                    if (ultosc[-2] > 70 and ultosc[-1] < 70):
                                        print('ULTOSC売ります')
                                        value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ULTOSC'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[11] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_tsf[-1] * ATRweight_tsf>= 0.03:
                                    if (tsf[-3] > tsf[-2]  and tsf[-2] > tsf[-1] and df.iat[-1, 3] > tsf[-1]):
                                        print('TSF売ります')
                                        value = atr_tsf[-1] * ATRweight_tsf * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'TSF'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[12] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_trix[-1] * ATRweight_trix>= 0.03:
                                    if (trix[-2] > 30 and trix[-1] < 30):
                                        print('TRIX売ります')
                                        value = atr_trix[-1] * ATRweight_trix * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'TRIX'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[13] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_aroon[-1] * ATRweight_aroon>= 0.03:
                                    if (aroonup[-2] > aroondown[-2] and aroonup[-1] < aroondown[-1]):
                                        print('AROONUP売ります')
                                        value = atr_aroon[-1] * ATRweight_aroon * 1000
                                        value = int(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'AROONUP'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)

                        if rule[14] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_mfi[-1] * ATRweight_mfi >= 0.03:
                                    if (mfi[-2] > 80 and mfi[-1] < 80):
                                        print('MFI売ります')
                                        value = atr_mfi[-1] * ATRweight_mfi * 1000
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MFI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_long,  index=True, header=True)
                
                    if data_long == '10S':
                        time.sleep(11)
                    if data_long == '30S':
                        time.sleep(31)
                    if data_long == '1T':
                        time.sleep(61)
                    if data_long == '3T':
                        time.sleep(181)
                    if data_long == '5T':
                        time.sleep(301)
                    if data_long == '10T':
                        time.sleep(601)
                    if data_long == '15T':
                        time.sleep(901)                 
                #単独で使用するとき    
                elif trend_flag == 2:
                    if indi_number == 7:
                        #最適なルールを01に変換
                        rule = list(format(rule_number,'07b'))
                        rule = np.array(rule,dtype='int64')
                        #indi表示
                        if rule_number != past_rule:
                            dt_now = datetime.datetime.now()
                            print('---------------------------')
                            print(dt_now)
                            print('rule_number = ',rule_number)
                            print(rule)
                            print('インジケーター')
                            for i in range(len(rule)):
                                if rule[i] == 1:
                                    print(indi_list[i])
                            past_rule = rule_number
                        #buy
                        if rule[0] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if  max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                    if (ema1[-2] < ema2[-2] and ema1[-1] > ema2[-1]): 
                                        print('EMA買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_ema[-1] * ATRweight_ema *1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'EMA'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[1] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if  max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                    if (bband_lower[-2] > df.Close[-2] and bband_lower[-1] < df.Close[-1]): 
                                        print('BBAND買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_bband[-1] * ATRweight_bband *1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'BBAND'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[2] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03:
                                    if (macd[-2] < macdsignal[-2] and macd[-1] > macdsignal[-1] and macd[-1] < 0 and macdsignal[-1] < 0):
                                        print('MACD買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_macd[-1] * ATRweight_macd*1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MACD'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[3] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                    if (rsi[-2] < 30 and rsi[-1] > 30): 
                                        print('RSI買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_rsi[-1] * ATRweight_rsi * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'RSI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[4] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                    if (D[-2] > K[-2] and D[-1] < K[-1] and D[-1] < 20 and K[-1] < 20): 
                                        print('STOCH買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_stoch[-1] * ATRweight_stoch * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'STOCH'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[5] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                    if (dim[-2] > dip[-2] and dim[-1] < dip[-1] and dim[-1] < adx[-1]): 
                                        print('DMI買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_dmi[-1] * ATRweight_dmi * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'DMI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[6] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_ultosc[-1] * ATRweight_ultosc >= 0.03:
                                    if (ultosc[-2] < 30 and ultosc[-1] > 30): 
                                        print('ULTOSC買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ULTOSC'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        #sell
                        if rule[0] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                    if (ema1[-2] > ema2[-2] and ema1[-1] < ema2[-1]):
                                        print('EMA売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_ema[-1] * ATRweight_ema * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'EMA'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                                    
                        if rule[1] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:    
                                if max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                    if (bband_upper[-2] < df.Close[-2] and bband_upper[-1] > df.Close[-1]):
                                        print('BBAND売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_bband[-1] * ATRweight_bband * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'BBAND'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[2] == 1:   
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0: 
                                if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03: 
                                    if (macd[-2] > macdsignal[-2] and macd[-1] < macdsignal[-1] and macd[-1] > 0 and macdsignal[-1] > 0):
                                        print('MACD売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_macd[-1] * ATRweight_macd * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MACD'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[3] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0: 
                                if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                    if (rsi[-2] > 70 and rsi[-1] < 70):
                                        print('RSI売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_rsi[-1] * ATRweight_rsi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'RSI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[4] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                    if (D[-2] < K[-2] and D[-1] > K[-1] and D[-1] > 80 and K[-1] > 80):
                                        print('STOCH売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_stoch[-1] * ATRweight_stoch * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'STOCH'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[5] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                    if (dim[-2] < dip[-2] and dim[-1] > dip[-1] and dip[-1] < adx[-1]):
                                        print('DMI売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_dmi[-1] * ATRweight_dmi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'DMI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[6] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_ultosc[-1] * ATRweight_ultosc>= 0.03:
                                    if (ultosc[-2] > 70 and ultosc[-1] < 70):
                                        print('ULTOSC売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ULTOSC'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                    if indi_number == 15:
                        rule = list(format(value,'015b'))
                        rule = np.array(rule,dtype='int64')
                        #indi表示
                        if rule_number != past_rule:
                            dt_now = datetime.datetime.now()
                            print('---------------------------')
                            print(dt_now)
                            print('rule_number = ',rule_number)
                            print(rule)
                            print('インジケーター')
                            for i in range(len(rule)):
                                if rule[i] == 1:
                                    print(indi_list[i])
                            past_rule = rule_number
                        #buy
                        if rule[0] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if  max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                    if (ema1[-2] < ema2[-2] and ema1[-1] > ema2[-1]): 
                                        print('EMA買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_ema[-1] * ATRweight_ema *1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'EMA'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[1] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if  max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                    if (bband_lower[-2] > df.Close[-2] and bband_lower[-1] < df.Close[-1]): 
                                        print('BBAND買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_bband[-1] * ATRweight_bband *1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'BBAND'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[2] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03:
                                    if (macd[-2] < macdsignal[-2] and macd[-1] > macdsignal[-1] and macd[-1] < 0 and macdsignal[-1] < 0):
                                        print('MACD買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_macd[-1] * ATRweight_macd*1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MACD'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[3] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                    if (rsi[-2] < 30 and rsi[-1] > 30): 
                                        print('RSI買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_rsi[-1] * ATRweight_rsi * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'RSI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[4] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                    if (D[-2] > K[-2] and D[-1] < K[-1] and D[-1] < 20 and K[-1] < 20): 
                                        print('STOCH買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_stoch[-1] * ATRweight_stoch * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'STOCH'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[5] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_willr[-1] * ATRweight_willr >= 0.03:
                                    if (willr[-2] < -80 and willr[-1] > -80): 
                                        print('willr買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_willr[-1] * ATRweight_willr * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'WILLR'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)                        

                        if rule[6] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                    if (dim[-2] > dip[-2] and dim[-1] < dip[-1] and dim[-1] < adx[-1]): 
                                        print('DMI買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_dmi[-1] * ATRweight_dmi * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'DMI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)                        

                        if rule[7] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_cci[-1] * ATRweight_cci >= 0.03:
                                    if (cci[-2] < -100 and cci[-1] > -100): 
                                        print('CCI買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_cci[-1] * ATRweight_cci * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'CCI'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[8] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_mom[-1] * ATRweight_mom >= 0.03:
                                    if (mom[-2] < -30 and mom[-1] > -30): 
                                        print('MOM買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_mom[-1] * ATRweight_mom * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MOM'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)                

                        if rule[9] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_roc[-1] * ATRweight_roc >= 0.03:
                                    if (roc[-2] < -30 and roc[-1] > -30): 
                                        print('ROC買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_roc[-1] * ATRweight_roc * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ROC'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                        
                        if rule[10] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_ultosc[-1] * ATRweight_ultosc >= 0.03:
                                    if (ultosc[-2] < 30 and ultosc[-1] > 30): 
                                        print('ULTOSC買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ULTOSC'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[11] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_tsf[-1] * ATRweight_tsf >= 0.03:
                                    if (tsf[-3] < tsf[-2]  and tsf[-2] < tsf[-1] and df.iat[-1, 3] < tsf[-1] ): 
                                        print('TSF買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_tsf[-1] * ATRweight_tsf * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'TSF'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[12] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_trix[-1] * ATRweight_trix >= 0.03:
                                    if (trix[-2] < 30 and trix[-1] > 30): 
                                        print('TRIX買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_trix[-1] * ATRweight_trix * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'TRIX'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[13] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_aroon[-1] * ATRweight_aroon >= 0.03:
                                    if (aroonup[-2] < aroondown[-2] and aroonup[-1] > aroondown[-1]): 
                                        print('AROONUP買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_aroon[-1] * ATRweight_aroon * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'aroonup'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)                

                        if rule[14] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_mfi[-1] * ATRweight_mfi >= 0.03:
                                    if (mfi[-2] < 20 and mfi[-1] > 20): 
                                        print('MFI買います')
                                        winsound.Beep(2000, 500)
                                        value = atr_mfi[-1] * ATRweight_mfi * 1000
                                        value = int(value)
                                        order_buy(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('ask =',ask)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'mfi'
                                        order = 'buy'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,ask,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)                    
                        #sell
                        if rule[0] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:
                                if max_weight >= atr_ema[-1] * ATRweight_ema >= 0.03:
                                    if (ema1[-2] > ema2[-2] and ema1[-1] < ema2[-1]):
                                        print('EMA売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_ema[-1] * ATRweight_ema * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'EMA'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[1] == 1:
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:    
                                if max_weight >= atr_bband[-1] * ATRweight_bband >= 0.03:
                                    if (bband_upper[-2] < df.Close[-2] and bband_upper[-1] > df.Close[-1]):
                                        print('BBAND売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_bband[-1] * ATRweight_bband * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'BBAND'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[2] == 1:   
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0: 
                                if max_weight >= atr_macd[-1] * ATRweight_macd >= 0.03: 
                                    if (macd[-2] > macdsignal[-2] and macd[-1] < macdsignal[-1] and macd[-1] > 0 and macdsignal[-1] > 0):
                                        print('MACD売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_macd[-1] * ATRweight_macd * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MACD'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[3] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0: 
                                if max_weight >= atr_rsi[-1] * ATRweight_rsi >= 0.03:
                                    if (rsi[-2] > 70 and rsi[-1] < 70):
                                        print('RSI売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_rsi[-1] * ATRweight_rsi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'RSI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[4] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_stoch[-1] * ATRweight_stoch >= 0.03:
                                    if (D[-2] < K[-2] and D[-1] > K[-1] and D[-1] > 80 and K[-1] > 80):
                                        print('STOCH売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_stoch[-1] * ATRweight_stoch * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'STOCH'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[5] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_willr[-1] * ATRweight_willr >= 0.03:
                                    if (willr[-2] > -20 and willr[-1] < -20):
                                        print('WILLR売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_willr[-1] * ATRweight_willr * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'WILLR'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[6] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_dmi[-1] * ATRweight_dmi >= 0.03:
                                    if (dim[-2] < dip[-2] and dim[-1] > dip[-1] and dip[-1] < adx[-1]):
                                        print('DMI売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_dmi[-1] * ATRweight_dmi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'DMI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[7] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_cci[-1] * ATRweight_cci >= 0.03:
                                    if (cci[-2] > 100 and cci[-1] < 100):
                                        print('CCI売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_cci[-1] * ATRweight_cci * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'CCI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[8] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_mom[-1] * ATRweight_mom >= 0.03:
                                    if (mom[-2] > 30 and mom[-1] < 30):
                                        print('MOM売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_mom[-1] * ATRweight_mom * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MOM'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)
                    
                        if rule[9] == 1: 
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:     
                                if max_weight >= atr_roc[-1] * ATRweight_roc >= 0.03:
                                    if (roc[-2] > 30 and roc[-1] < 30):
                                        print('ROC売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_roc[-1] * ATRweight_roc * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ROC'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[10] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_ultosc[-1] * ATRweight_ultosc>= 0.03:
                                    if (ultosc[-2] > 70 and ultosc[-1] < 70):
                                        print('ULTOSC売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_ultosc[-1] * ATRweight_ultosc * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'ULTOSC'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[11] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_tsf[-1] * ATRweight_tsf>= 0.03:
                                    if (tsf[-3] > tsf[-2]  and tsf[-2] > tsf[-1] and df.iat[-1, 3] > tsf[-1]):
                                        print('TSF売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_tsf[-1] * ATRweight_tsf * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'TSF'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[12] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_trix[-1] * ATRweight_trix>= 0.03:
                                    if (trix[-2] > 30 and trix[-1] < 30):
                                        print('TRIX売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_trix[-1] * ATRweight_trix * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'TRIX'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[13] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_aroon[-1] * ATRweight_aroon>= 0.03:
                                    if (aroonup[-2] > aroondown[-2] and aroonup[-1] < aroondown[-1]):
                                        print('AROONUP売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_aroon[-1] * ATRweight_aroon * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'AROONUP'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                        if rule[14] == 1:    
                            positions=mt5.positions_get(symbol="USDJPY")
                            if len(positions) == 0:  
                                if max_weight >= atr_mfi[-1] * ATRweight_mfi >= 0.03:
                                    if (mfi[-2] > 80 and mfi[-1] < 80):
                                        print('MFI売ります')
                                        winsound.Beep(2000, 500)
                                        value = atr_mfi[-1] * ATRweight_mfi * 1000
                                        value = int(value)
                                        order_sell(value)
                                        entrytime = df.tail(1)
                                        entrytime = entrytime.reset_index()
                                        lasttime = entrytime.iat[0,0]
                                        print('time =',lasttime)
                                        print('bid =',bid)
                                        print('spread =',real_spread)
                                        print('tp & sl =',value*0.1,'pips')
                                        indi = 'MFI'
                                        order = 'sell'
                                        pips = value*0.1
                                        entry = pd.Series( [lasttime, indi, order,bid,pips], index=Entry.columns )
                                        Entry = Entry.append(entry, ignore_index=True)
                                        Entry.to_csv(path_Entry_short,  index=True, header=True)

                    if data_short == '10S':
                        time.sleep(11)
                    if data_short == '30S':
                        time.sleep(31)
                    if data_short == '1T':
                        time.sleep(61)
                    if data_short == '3T':
                        time.sleep(181)
                    if data_short == '5T':
                        time.sleep(301)
                    if data_short == '10T':
                        time.sleep(601)
                    if data_short == '15T':
                        time.sleep(901) 

    except pd.errors.EmptyDataError:
        print('csvファイルが読み取れませんでした．スキップします．')
        continue

    except ValueError:
        print('ValueError')
        continue

    except AssertionError:
        print('AssertionError')
        continue

    except TypeError:
        print('TypeError')
        continue

    except AttributeError:
        print('AttributeError')
        continue

    except OverflowError:
        print('OverflowError')
        continue

    except OSError:
        print('OSError')
        continue

    except IndexError:
        print('IndexError')
        continue