import pandas as pd
import numpy as np
import re
import datetime
import talib
from backtesting import Strategy
from backtesting.lib import crossover
from backtesting import Backtest
from sklearn import linear_model
import pulp
import csv
import sys
import warnings
warnings.filterwarnings('ignore')#警告文を表示させない

#%matplotlib inline
print('-----------------------------------------------------------')
print('-----------------------------------------------------------')
print('-----------------------------------------------------------')
print('-----------------------------------------------------------')
print('-----------------------------------------------------------')

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]
if  use_data == 'short':
    data = df.iat[0,4]
if  use_data == 'long':
    data = df.iat[0,5]
max_weight = df.iat[0,6]
opt_factor = df.iat[0,7]
indi_number = df.iat[0,8]
flag = 0

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

path_rule = 'C:/Users/xi/MT5/out_dat/rule.csv'
usecols = ['time','open','high','low','close','volume']
sihyou = ['Exposure Time [%]','Equity Final [$]','Equity Peak [$]','Return [%]','Calmar Ratio','Max. Drawdown [%]', 'Avg. Drawdown [%]','Trades','Win Rate [%]','Best Trade [%]','Worst Trade [%]','Avg. Trade [%]','Profit Factor','Expectancy [%]','SQN']

#2^15の中でルール1～16が何番目なのか
r_16 = list([32767,32512,28912,28687,19660,19507,17347,17212,10922,10837,9637,9562,6553,6502,5782,5737])
#2^7の中でルール1～8が何番目なのか
r_8 = list([127,112,76,67,42,37,25,22])

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 Extract(df):
    #Exposure Time [%] ポジションを持っていた期間の割合（ポジションを持っていた期間÷全期間×100）
    num = df.at['Exposure Time [%]','0']
    num = float(num)
    result1.append(num)
    #Equity Final [$] 所持金の最終値 
    num = df.at['Equity Final [$]','0']
    num = float(num)
    result2.append(num)
    #Equity Peak [$] 所持金の最高値
    num = df.at['Equity Peak [$]','0']
    num = float(num)
    result3.append(num)
    #Return [%] 利益率=損益÷開始時所持金×100
    num = df.at['Return [%]','0']
    num = float(num)
    result4.append(num)
    '''
    #Buy & Hold Return [%] （（終了時の終値 - 開始時の終値）÷ 開始時の終値）の絶対値×100
    num = df.at['Buy & Hold Return [%]','0']
    num = float(num)
    result5.append(num)
    #Sharpe Ratio 標準偏差に対するリターンの比率
    num = df.at['Sharpe Ratio','0']
    num = float(num)
    result6.append(num)
    #Sortino Ratio 下方リスクに対するリターンの比率
    num = df.at['Sortino Ratio','0']
    num = float(num)
    result7.append(num)]
    '''
    #Calmar Ratio 最大損失率に対する年間平均収益の比率
    num = df.at['Calmar Ratio','0']
    num = float(num)
    result8.append(num)
    #Max. Drawdown [%] 最大下落率
    num = df.at['Max. Drawdown [%]','0']
    num = float(num)
    result9.append(num)
    #Avg. Drawdown [%] 平均下落率
    num = df.at['Avg. Drawdown [%]','0']
    num = float(num)
    result10.append(num)
    #Trades 取引回数
    num = df.at['# Trades','0']
    num = float(num)
    result11.append(num)
    #Win Rate [%] 勝率=勝ち取引回数÷全取引回数×100
    num = df.at['Win Rate [%]','0']
    num = float(num)
    result12.append(num)
    #Best Trade [%] 1回の取引での利益の最大値÷所持金×100
    num = df.at['Best Trade [%]','0']
    num = float(num)
    result13.append(num)
    #Worst Trade [%] 1回の取引での損失の最大値÷所持金×100
    num = df.at['Worst Trade [%]','0']
    num = float(num)
    result14.append(num)
    #Avg. Trade [%] 損益の平均値÷所持金×100
    num = df.at['Avg. Trade [%]','0']
    num = float(num)
    result15.append(num)
    #Profit Factor 利益率
    num = df.at['Profit Factor','0']
    num = float(num)
    result16.append(num)
    # 期待値=平均利益×勝率＋平均損失×敗率
    num = df.at['Expectancy [%]','0']
    num = float(num)
    result17.append(num)
    # SQN（SystemQualityNumber）
    num = df.at['SQN','0']
    num = float(num)
    result18.append(num)

#回帰分析の関数()
def kaiki(x,y):
    model = linear_model.LinearRegression()
    model.fit(x,y)
    model.coef_
    # 変数coefficientに係数の値を格納
    coefficient = model.coef_
    coefficient_df = pd.DataFrame(coefficient)
    #L8の場合
    coefficient_df.columns=indi
    #L16の場合
    #coefficient_df.columns=indi
    return coefficient_df

#L16の場合
if indi_number == 15:
    #rule1~rule16までのL16直交表作成
    print('-----------------------------------------------------------')
    print('L15直交表作成')
    dt_now = datetime.datetime.now()
    print(dt_now)
    ruleselect = []
    for i in range(len(r_16)):
        rule =list(format(r_16[i],'015b'))
        rule = np.array(rule,dtype='int64')
        ruleselect.append(rule)
    #DataFrame化
    ruleselect_df = pd.DataFrame(ruleselect)
    ruleselect_df.columns=indi

    #2^15-1個の組み合わせすべての直交表作成
    print('-----------------------------------------------------------')
    print('2^15の直交表作成')
    dt_now = datetime.datetime.now()
    print(dt_now)
    ruleall = []
    for i in range(32768):
        rule =list(format(i,'015b'))
        rule = np.array(rule,dtype='int64')
        ruleall.append(rule)
    #DataFrame化
    ruleall_df = pd.DataFrame(ruleall)
    ruleall_df.columns=indi
    #ndarray化
    ruleall_array = ruleall_df.values

#L8の場合
if indi_number == 7:
    #rule1~rule8までのL8直交表作成
    print('---------------------------------------------------')
    print('L8直交表作成')
    dt_now = datetime.datetime.now()
    print(dt_now)
    ruleselect = []
    for i in range(len(r_8)):
        rule =list(format(r_8[i],'07b'))
        rule = np.array(rule,dtype='int64')
        ruleselect.append(rule)
    #DataFrame化
    ruleselect_df = pd.DataFrame(ruleselect)
    ruleselect_df.columns=indi

    #2^7個の組み合わせすべての直交表作成
    print('---------------------------------------------------')
    print('2^7の直交表作成')
    dt_now = datetime.datetime.now()
    print(dt_now)
    ruleall = []
    for i in range(128):
        rule =list(format(i,'07b'))
        rule = np.array(rule,dtype='int64')
        ruleall.append(rule)
    #DataFrame化
    ruleall_df = pd.DataFrame(ruleall)
    ruleall_df.columns=indi
    #ndarray化
    ruleall_array = ruleall_df.values

while True:
    try:
        print('---------------------------------------------------')
        print('データ読み込み開始')
        dt_now = datetime.datetime.now()
        print(dt_now)
        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']

        #長期の場合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 data == '10S':
            if td.seconds < 30:
                flag = 1
                df["time"] = pd.to_datetime(df["time"])
                df = df.set_index('time')
            else:
                flag = 0
        if data == '30S':
            if td.seconds < 90:
                flag = 1
                df["time"] = pd.to_datetime(df["time"])
                df = df.set_index('time')
            else:
                flag = 0
        if data == '1T':
            if td.seconds < 180:
                flag = 1
                df["time"] = pd.to_datetime(df["time"])
                df = df.set_index('time')
            else:
                flag = 0
        if data == '3T':
            if td.seconds < 540:
                flag = 1
                df["time"] = pd.to_datetime(df["time"])
                df = df.set_index('time')
            else:
                flag = 0
        if data == '5T':
            if td.seconds < 900:
                flag = 1
                df["time"] = pd.to_datetime(df["time"])
                df = df.set_index('time')
            else:
                flag = 0
        if data == '10T':
            if td.seconds < 1800:
                flag = 1
                df["time"] = pd.to_datetime(df["time"])
                df = df.set_index('time')
            else:
                flag = 0
        if data == '15T':
            if td.seconds < 2700:
                flag = 1
                df["time"] = pd.to_datetime(df["time"])
                df = df.set_index('time')
            else:
                flag = 0

        print('NaN回避')        
        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:
                #12個の目的変数(評価指標)の配列作成
                result1 = []
                result2 = []
                result3 = []
                result4 = []
                #result5 = []
                #result6 = []
                #result7 = []
                result8 = []
                result9 = []
                result10 = []
                result11 = []
                result12 = []
                result13 = []
                result14 = []
                result15 = []
                result16 = []
                result17 = []
                result18 = []
                df_ = df.tail(use)

                #---------------------------------------------------------------
                #L16の場合
                if indi_number == 15:
                    #ここからL16のルールのクラス
                    #全部
                    class rule16_1(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        atrvalue_willr = ATRvalue_willr
                        atrvalue_dmi = ATRvalue_dmi
                        atrvalue_cci = ATRvalue_cci
                        atrvalue_mom = ATRvalue_mom
                        atrvalue_roc = ATRvalue_roc
                        atrvalue_ultosc = ATRvalue_ultosc
                        atrvalue_tsf = ATRvalue_tsf
                        atrvalue_trix = ATRvalue_trix
                        atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi 

                        atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        atrweight_willr = ATRweight_willr
                        atrweight_dmi = ATRweight_dmi
                        atrweight_cci = ATRweight_cci
                        atrweight_mom = ATRweight_mom
                        atrweight_roc = ATRweight_roc
                        atrweight_ultosc = ATRweight_ultosc
                        atrweight_tsf = ATRweight_tsf
                        atrweight_trix = ATRweight_trix
                        atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi 
                        
                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        willrvalue = WillRvalue
                        dmivalue = DMIvalue
                        ccivalue = CCIvalue
                        momvalue = MOMvalue
                        rocvalue = ROCvalue  
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3
                        tsfvalue = TSFvalue
                        trixvalue = TRIXvalue
                        aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight
                        



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy if
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #EMA,BBAND,MACD,RSI,STOCH,WillR,DMI
                    class rule16_2(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        atrvalue_willr = ATRvalue_willr
                        atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_cci = ATRvalue_cci
                        #atrvalue_mom = ATRvalue_mom
                        #atrvalue_roc = ATRvalue_roc
                        #atrvalue_ultosc = ATRvalue_ultosc
                        #atrvalue_tsf = ATRvalue_tsf
                        #atrvalue_trix = ATRvalue_trix
                        #atrvalue_aroon = ATRvalue_aroon
                        #atrvalue_mfi = ATRvalue_mfi 

                        atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        atrweight_willr = ATRweight_willr
                        atrweight_dmi = ATRweight_dmi
                        #atrweight_cci = ATRweight_cci
                        #atrweight_mom = ATRweight_mom
                        #atrweight_roc = ATRweight_roc
                        #atrweight_ultosc = ATRweight_ultosc
                        #atrweight_tsf = ATRweight_tsf
                        #atrweight_trix = ATRweight_trix
                        #atrweight_aroon = ATRweight_aroon
                        #atrweight_mfi = ATRweight_mfi 

                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        willrvalue = WillRvalue
                        dmivalue = DMIvalue
                        #ccivalue = CCIvalue
                        #momvalue = MOMvalue
                        #rocvalue = ROCvalue  
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3
                        #tsfvalue = TSFvalue
                        #trixvalue = TRIXvalue
                        #aroonvalue = AROONvalue
                        #mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            #self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            #self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            #self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            #self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            #self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            #self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            #self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            #self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            #self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            #self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            #self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            #self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #EMA,BBAND,MACD,CCI,MOM,ROC,ULTOSC
                    class rule16_3(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_willr = ATRvalue_willr
                        #atrvalue_dmi = ATRvalue_dmi
                        atrvalue_cci = ATRvalue_cci
                        atrvalue_mom = ATRvalue_mom
                        atrvalue_roc = ATRvalue_roc
                        atrvalue_ultosc = ATRvalue_ultosc
                        #atrvalue_tsf = ATRvalue_tsf
                        #atrvalue_trix = ATRvalue_trix
                        #atrvalue_aroon = ATRvalue_aroon
                        #atrvalue_mfi = ATRvalue_mfi 

                        atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        #atrweight_willr = ATRweight_willr
                        #atrweight_dmi = ATRweight_dmi
                        atrweight_cci = ATRweight_cci
                        atrweight_mom = ATRweight_mom
                        atrweight_roc = ATRweight_roc
                        atrweight_ultosc = ATRweight_ultosc
                        #atrweight_tsf = ATRweight_tsf
                        #atrweight_trix = ATRweight_trix
                        #atrweight_aroon = ATRweight_aroon
                        #atrweight_mfi = ATRweight_mfi 

                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        #willrvalue = WillRvalue
                        #dmivalue = DMIvalue
                        ccivalue = CCIvalue
                        momvalue = MOMvalue
                        rocvalue = ROCvalue  
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3
                        #tsfvalue = TSFvalue
                        #trixvalue = TRIXvalue
                        #aroonvalue = AROONvalue
                        #mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            #self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            #self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            #self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            #self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            #self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            #self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            #self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            #self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #EMA,BBAND,MACD,TSF,TRIX,AROON,MFI
                    class rule16_4(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_willr = ATRvalue_willr
                        #atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_cci = ATRvalue_cci
                        #atrvalue_mom = ATRvalue_mom
                        #atrvalue_roc = ATRvalue_roc
                        #atrvalue_ultosc = ATRvalue_ultosc
                        atrvalue_tsf = ATRvalue_tsf
                        atrvalue_trix = ATRvalue_trix
                        atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi 

                        atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        #atrweight_willr = ATRweight_willr
                        #atrweight_dmi = ATRweight_dmi
                        #atrweight_cci = ATRweight_cci
                        #atrweight_mom = ATRweight_mom
                        #atrweight_roc = ATRweight_roc
                        #atrweight_ultosc = ATRweight_ultosc
                        atrweight_tsf = ATRweight_tsf
                        atrweight_trix = ATRweight_trix
                        atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi

                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        #willrvalue = WillRvalue
                        #dmivalue = DMIvalue
                        #ccivalue = CCIvalue
                        #momvalue = MOMvalue
                        #rocvalue = ROCvalue  
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3
                        tsfvalue = TSFvalue
                        trixvalue = TRIXvalue
                        aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight

                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            #self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            #self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            #self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            #self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_mfi))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #EMA,RSI,STOCH,CCI,MOM,TSF,TRIX
                    class rule16_5(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_willr = ATRvalue_willr
                        #atrvalue_dmi = ATRvalue_dmi
                        atrvalue_cci = ATRvalue_cci
                        atrvalue_mom = ATRvalue_mom
                        #atrvalue_roc = ATRvalue_roc
                        #atrvalue_ultosc = ATRvalue_ultosc
                        atrvalue_tsf = ATRvalue_tsf
                        atrvalue_trix = ATRvalue_trix
                        #atrvalue_aroon = ATRvalue_aroon
                        #atrvalue_mfi = ATRvalue_mfi 

                        atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        #atrweight_willr = ATRweight_willr
                        #atrweight_dmi = ATRweight_dmi
                        atrweight_cci = ATRweight_cci
                        atrweight_mom = ATRweight_mom
                        #atrweight_roc = ATRweight_roc
                        #atrweight_ultosc = ATRweight_ultosc
                        atrweight_tsf = ATRweight_tsf
                        atrweight_trix = ATRweight_trix
                        #atrweight_aroon = ATRweight_aroon
                        #atrweight_mfi = ATRweight_mfi 

                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        #willrvalue = WillRvalue
                        #dmivalue = DMIvalue
                        ccivalue = CCIvalue
                        momvalue = MOMvalue
                        #rocvalue = ROCvalue  
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3
                        tsfvalue = TSFvalue
                        trixvalue = TRIXvalue
                        #aroonvalue = AROONvalue
                        #mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            #self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            #self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            #self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            #self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            #self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            #self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #EMA,RSI,STOCH,ROC,ULTOSC,AROON,MFI
                    class rule16_6(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_willr = ATRvalue_willr
                        #atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_cci = ATRvalue_cci
                        #atrvalue_mom = ATRvalue_mom
                        atrvalue_roc = ATRvalue_roc
                        atrvalue_ultosc = ATRvalue_ultosc
                        #atrvalue_tsf = ATRvalue_tsf
                        #atrvalue_trix = ATRvalue_trix
                        atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi 

                        atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        #atrweight_willr = ATRweight_willr
                        #atrweight_dmi = ATRweight_dmi
                        #atrweight_cci = ATRweight_cci
                        #atrweight_mom = ATRweight_mom
                        atrweight_roc = ATRweight_roc
                        atrweight_ultosc = ATRweight_ultosc
                        #atrweight_tsf = ATRweight_tsf
                        #atrweight_trix = ATRweight_trix
                        atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi 

                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        #willrvalue = WillRvalue
                        #dmivalue = DMIvalue
                        #ccivalue = CCIvalue
                        #momvalue = MOMvalue
                        rocvalue = ROCvalue  
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3
                        #tsfvalue = TSFvalue
                        #trixvalue = TRIXvalue
                        aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            #self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            #self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            #self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            #self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            #self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            #self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #EMA,WillR,DMI,CCI,MOM,AROON,MFI
                    class rule16_7(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        atrvalue_willr = ATRvalue_willr
                        atrvalue_dmi = ATRvalue_dmi
                        atrvalue_cci = ATRvalue_cci
                        atrvalue_mom = ATRvalue_mom
                        #atrvalue_roc = ATRvalue_roc
                        #atrvalue_ultosc = ATRvalue_ultosc
                        #atrvalue_tsf = ATRvalue_tsf
                        #atrvalue_trix = ATRvalue_trix
                        atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi 

                        atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        atrweight_willr = ATRweight_willr
                        atrweight_dmi = ATRweight_dmi
                        atrweight_cci = ATRweight_cci
                        atrweight_mom = ATRweight_mom
                        #atrweight_roc = ATRweight_roc
                        #atrweight_ultosc = ATRweight_ultosc
                        #atrweight_tsf = ATRweight_tsf
                        #atrweight_trix = ATRweight_trix
                        atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi 

                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        willrvalue = WillRvalue
                        dmivalue = DMIvalue
                        ccivalue = CCIvalue
                        momvalue = MOMvalue
                        #rocvalue = ROCvalue  
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3
                        #tsfvalue = TSFvalue
                        #trixvalue = TRIXvalue
                        aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            #self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            #self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            #self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            #self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            #self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            #self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #EMA,WillR,DMI,ROC,ULTOSC,TSF,TRIX
                    class rule16_8(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        atrvalue_willr = ATRvalue_willr
                        atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_cci = ATRvalue_cci
                        #atrvalue_mom = ATRvalue_mom
                        atrvalue_roc = ATRvalue_roc
                        atrvalue_ultosc = ATRvalue_ultosc
                        atrvalue_tsf = ATRvalue_tsf
                        atrvalue_trix = ATRvalue_trix
                        #atrvalue_aroon = ATRvalue_aroon
                        #atrvalue_mfi = ATRvalue_mfi 

                        atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        atrweight_willr = ATRweight_willr
                        atrweight_dmi = ATRweight_dmi
                        #atrweight_cci = ATRweight_cci
                        #atrweight_mom = ATRweight_mom
                        atrweight_roc = ATRweight_roc
                        atrweight_ultosc = ATRweight_ultosc
                        atrweight_tsf = ATRweight_tsf
                        atrweight_trix = ATRweight_trix
                        #atrweight_aroon = ATRweight_aroon
                        #atrweight_mfi = ATRweight_mfi 

                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        willrvalue = WillRvalue
                        dmivalue = DMIvalue
                        #ccivalue = CCIvalue
                        #momvalue = MOMvalue
                        rocvalue = ROCvalue  
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3
                        tsfvalue = TSFvalue
                        trixvalue = TRIXvalue
                        #aroonvalue = AROONvalue
                        #mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            #self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            #self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            #self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            #self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            #self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            #self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * SELF.ATRWEIGHT_MACD) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #BBAND,RSI,WillR,CCI,ROC,TSF,AROON
                    class rule16_9(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        atrvalue_willr = ATRvalue_willr
                        #atrvalue_dmi = ATRvalue_dmi
                        atrvalue_cci = ATRvalue_cci
                        #atrvalue_mom = ATRvalue_mom
                        atrvalue_roc = ATRvalue_roc
                        #atrvalue_ultosc = ATRvalue_ultosc
                        atrvalue_tsf = ATRvalue_tsf
                        #atrvalue_trix = ATRvalue_trix
                        atrvalue_aroon = ATRvalue_aroon
                        #atrvalue_mfi = ATRvalue_mfi 

                        #atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        atrweight_willr = ATRweight_willr
                        #atrweight_dmi = ATRweight_dmi
                        atrweight_cci = ATRweight_cci
                        #atrweight_mom = ATRweight_mom
                        atrweight_roc = ATRweight_roc
                        #atrweight_ultosc = ATRweight_ultosc
                        atrweight_tsf = ATRweight_tsf
                        #atrweight_trix = ATRweight_trix
                        atrweight_aroon = ATRweight_aroon
                        #atrweight_mfi = ATRweight_mfi 

                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        willrvalue = WillRvalue
                        #dmivalue = DMIvalue
                        ccivalue = CCIvalue
                        #momvalue = MOMvalue
                        rocvalue = ROCvalue  
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3
                        tsfvalue = TSFvalue
                        #trixvalue = TRIXvalue
                        aroonvalue = AROONvalue
                        #mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                        # self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            #self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            #self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            #self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            #self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            #self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            #self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))


                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #BBAND,RSI,WillR,MOM,ULTOSC,TRIX,MFI
                    class rule16_10(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        atrvalue_willr = ATRvalue_willr
                        #atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_cci = ATRvalue_cci
                        atrvalue_mom = ATRvalue_mom
                        #atrvalue_roc = ATRvalue_roc
                        atrvalue_ultosc = ATRvalue_ultosc
                        #atrvalue_tsf = ATRvalue_tsf
                        atrvalue_trix = ATRvalue_trix
                        #atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi 

                        #atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        atrweight_willr = ATRweight_willr
                        #atrweight_dmi = ATRweight_dmi
                        #atrweight_cci = ATRweight_cci
                        atrweight_mom = ATRweight_mom
                        #atrweight_roc = ATRweight_roc
                        atrweight_ultosc = ATRweight_ultosc
                        #atrweight_tsf = ATRweight_tsf
                        atrweight_trix = ATRweight_trix
                        #atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi 

                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        willrvalue = WillRvalue
                        #dmivalue = DMIvalue
                        #ccivalue = CCIvalue
                        momvalue = MOMvalue
                        #rocvalue = ROCvalue  
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3
                        #tsfvalue = TSFvalue
                        trixvalue = TRIXvalue
                        #aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            #self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            #self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            #self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            #self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            #self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            #self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #BBAND,STOCH,DMI,CCI,ROC,TRIX,MFI
                    class rule16_11(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_willr = ATRvalue_willr
                        atrvalue_dmi = ATRvalue_dmi
                        atrvalue_cci = ATRvalue_cci
                        #atrvalue_mom = ATRvalue_mom
                        atrvalue_roc = ATRvalue_roc
                        #atrvalue_ultosc = ATRvalue_ultosc
                        #atrvalue_tsf = ATRvalue_tsf
                        atrvalue_trix = ATRvalue_trix
                        #atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi 

                        #atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        #atrweight_willr = ATRweight_willr
                        atrweight_dmi = ATRweight_dmi
                        atrweight_cci = ATRweight_cci
                        #atrweight_mom = ATRweight_mom
                        atrweight_roc = ATRweight_roc
                        #atrweight_ultosc = ATRweight_ultosc
                        #atrweight_tsf = ATRweight_tsf
                        atrweight_trix = ATRweight_trix
                        #atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi

                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        #willrvalue = WillRvalue
                        dmivalue = DMIvalue
                        ccivalue = CCIvalue
                        #momvalue = MOMvalue
                        rocvalue = ROCvalue  
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3
                        #tsfvalue = TSFvalue
                        trixvalue = TRIXvalue
                        #aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            #self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            #self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            #self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            #self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            #self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            #self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_mfi))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #BBAND,STOCH,DMI,MOM,ULTOSC,TSF,AROON
                    class rule16_12(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_willr = ATRvalue_willr
                        atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_cci = ATRvalue_cci
                        atrvalue_mom = ATRvalue_mom
                        #atrvalue_roc = ATRvalue_roc
                        atrvalue_ultosc = ATRvalue_ultosc
                        atrvalue_tsf = ATRvalue_tsf
                        #atrvalue_trix = ATRvalue_trix
                        atrvalue_aroon = ATRvalue_aroon
                        #atrvalue_mfi = ATRvalue_mfi 

                        #atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        #atrweight_willr = ATRweight_willr
                        atrweight_dmi = ATRweight_dmi
                        #atrweight_cci = ATRweight_cci
                        atrweight_mom = ATRweight_mom
                        #atrweight_roc = ATRweight_roc
                        atrweight_ultosc = ATRweight_ultosc
                        atrweight_tsf = ATRweight_tsf
                        #atrweight_trix = ATRweight_trix
                        atrweight_aroon = ATRweight_aroon
                        #atrweight_mfi = ATRweight_mfi 

                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        #willrvalue = WillRvalue
                        dmivalue = DMIvalue
                        #ccivalue = CCIvalue
                        momvalue = MOMvalue
                        #rocvalue = ROCvalue  
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3
                        tsfvalue = TSFvalue
                        #trixvalue = TRIXvalue
                        aroonvalue = AROONvalue
                        #mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            #self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            #self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            #self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            #self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            #self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            #self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                #if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #MACD,RSI,DMI,CCI,ULTOSC,TSF,MFI
                    class rule16_13(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_willr = ATRvalue_willr
                        atrvalue_dmi = ATRvalue_dmi
                        atrvalue_cci = ATRvalue_cci
                        #atrvalue_mom = ATRvalue_mom
                        #atrvalue_roc = ATRvalue_roc
                        atrvalue_ultosc = ATRvalue_ultosc
                        atrvalue_tsf = ATRvalue_tsf
                        #atrvalue_trix = ATRvalue_trix
                        #atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi 

                        #atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        #atrweight_willr = ATRweight_willr
                        atrweight_dmi = ATRweight_dmi
                        atrweight_cci = ATRweight_cci
                        #atrweight_mom = ATRweight_mom
                        #atrweight_roc = ATRweight_roc
                        atrweight_ultosc = ATRweight_ultosc
                        atrweight_tsf = ATRweight_tsf
                        #atrweight_trix = ATRweight_trix
                        #atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi 

                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        #willrvalue = WillRvalue
                        dmivalue = DMIvalue
                        ccivalue = CCIvalue
                        #momvalue = MOMvalue
                        #rocvalue = ROCvalue  
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3
                        tsfvalue = TSFvalue
                        #trixvalue = TRIXvalue
                        #aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            #self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            #self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            #self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            #self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            #self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            #self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            #self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            #self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                #if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                #if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #MACD,RSI,DMI,MOM,ROC,TRIX,AROON
                    class rule16_14(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_willr = ATRvalue_willr
                        atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_cci = ATRvalue_cci
                        atrvalue_mom = ATRvalue_mom
                        atrvalue_roc = ATRvalue_roc
                        #atrvalue_ultosc = ATRvalue_ultosc
                        #atrvalue_tsf = ATRvalue_tsf
                        atrvalue_trix = ATRvalue_trix
                        atrvalue_aroon = ATRvalue_aroon
                        #atrvalue_mfi = ATRvalue_mfi 

                        #atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        #atrweight_willr = ATRweight_willr
                        atrweight_dmi = ATRweight_dmi
                        #atrweight_cci = ATRweight_cci
                        atrweight_mom = ATRweight_mom
                        atrweight_roc = ATRweight_roc
                        #atrweight_ultosc = ATRweight_ultosc
                        #atrweight_tsf = ATRweight_tsf
                        atrweight_trix = ATRweight_trix
                        atrweight_aroon = ATRweight_aroon
                        #atrweight_mfi = ATRweight_mfi 

                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        #willrvalue = WillRvalue
                        dmivalue = DMIvalue
                        #ccivalue = CCIvalue
                        momvalue = MOMvalue
                        rocvalue = ROCvalue  
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3
                        #tsfvalue = TSFvalue
                        trixvalue = TRIXvalue
                        aroonvalue = AROONvalue
                        #mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            #self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            #self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            #self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            #self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:    
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:   
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:    
                                #if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:   
                                #if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:    
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:    
                                #if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:    
                                if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:    
                                if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:    
                                #if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:    
                                #if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:    
                                if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:    
                                if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:    
                                #if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                #if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                #if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                #if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                #if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            #if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                #if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #MACD,STOCH,WillR,CCI,ULTOSC,TRIX,AROON,MFI
                    class rule16_15(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        atrvalue_willr = ATRvalue_willr
                        #atrvalue_dmi = ATRvalue_dmi
                        atrvalue_cci = ATRvalue_cci
                        #atrvalue_mom = ATRvalue_mom
                        #atrvalue_roc = ATRvalue_roc
                        atrvalue_ultosc = ATRvalue_ultosc
                        #atrvalue_tsf = ATRvalue_tsf
                        atrvalue_trix = ATRvalue_trix
                        atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi 

                        #atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        atrweight_willr = ATRweight_willr
                        #atrweight_dmi = ATRweight_dmi
                        atrweight_cci = ATRweight_cci
                        #atrweight_mom = ATRweight_mom
                        #atrweight_roc = ATRweight_roc
                        atrweight_ultosc = ATRweight_ultosc
                        #atrweight_tsf = ATRweight_tsf
                        atrweight_trix = ATRweight_trix
                        atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi 

                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        willrvalue = WillRvalue
                        #dmivalue = DMIvalue
                        ccivalue = CCIvalue
                        #momvalue = MOMvalue
                        #rocvalue = ROCvalue  
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3
                        #tsfvalue = TSFvalue
                        trixvalue = TRIXvalue
                        aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            #self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            #self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            #self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            #self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            #self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            #self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:    
                                #if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:    
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:    
                                #if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:    
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:    
                                if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:    
                                #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:    
                                if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:    
                                #if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:    
                                #if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:    
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:    
                                #if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:    
                                if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:    
                                if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:    
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                #if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                #if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:
                                if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                #if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:
                                if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            #if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:
                                #if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            #if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:
                                #if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            #if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:
                                #if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:
                                if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:
                                if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))

                    #MACD,STOCH,WillR,MOM,ROC,TSF,MFI
                    class rule16_16(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        atrvalue_willr = ATRvalue_willr
                        #atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_cci = ATRvalue_cci
                        atrvalue_mom = ATRvalue_mom
                        atrvalue_roc = ATRvalue_roc
                        #atrvalue_ultosc = ATRvalue_ultosc
                        atrvalue_tsf = ATRvalue_tsf
                        #atrvalue_trix = ATRvalue_trix
                        #atrvalue_aroon = ATRvalue_aroon
                        atrvalue_mfi = ATRvalue_mfi

                        #atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        atrweight_willr = ATRweight_willr
                        #atrweight_dmi = ATRweight_dmi
                        #atrweight_cci = ATRweight_cci
                        atrweight_mom = ATRweight_mom
                        atrweight_roc = ATRweight_roc
                        #atrweight_ultosc = ATRweight_ultosc
                        atrweight_tsf = ATRweight_tsf
                        #atrweight_trix = ATRweight_trix
                        #atrweight_aroon = ATRweight_aroon
                        atrweight_mfi = ATRweight_mfi  

                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        willrvalue = WillRvalue
                        #dmivalue = DMIvalue
                        #ccivalue = CCIvalue
                        momvalue = MOMvalue
                        rocvalue = ROCvalue  
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3
                        tsfvalue = TSFvalue
                        #trixvalue = TRIXvalue
                        #aroonvalue = AROONvalue
                        mfivalue = MFIvalue

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_willr = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_willr)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_cci = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_cci)
                            self.atr_mom = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mom)
                            self.atr_roc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_roc)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)
                            self.atr_tsf = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_tsf)
                            #self.atr_trix = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_trix)
                            #self.atr_aroon = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_aroon)
                            self.atr_mfi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_mfi)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.willr = self.I(WillR, self.data['High'], self.data['Low'], self.data['Close'], self.willrvalue)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.cci = self.I(CCI, self.data['High'], self.data['Low'], self.data['Close'], self.ccivalue)
                            self.mom = self.I(MOM, self.data['Close'], self.momvalue)
                            self.roc = self.I(ROC, self.data['Close'], self.rocvalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            self.tsf = self.I(TSF, self.data['Close'], self.tsfvalue)
                            #self.trix = self.I(TRIX, self.data['Close'], self.trixvalue)
                            #self.aroondown, self.aroonup = self.I(AROON, self.data['High'], self.data['Low'], self.aroonvalue)
                            self.mfi = self.I(MFI, self.data['High'], self.data['Low'], self.data['Close'], self.data['Volume'], self.mfivalue)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:   
                                #if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:    
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:    
                                #if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:    
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:    
                                if (self.willr[-2] < -80 and self.willr[-1] > -80): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_willr * self.atrweight_willr) + (spread * 0.01), sl = self.data['Close'] - (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:    
                                #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:    
                                #if (self.cci[-2] < -100 and self.cci[-1] > -100): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_cci * self.atrweight_cci) + (spread * 0.01), sl = self.data['Close'] - (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:   
                                if (self.mom[-2] < -30 and self.mom[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mom * self.atrweight_mom) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:    
                                if (self.roc[-2] < -30 and self.roc[-1] > -30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_roc * self.atrweight_roc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:    
                                #if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                #    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:    
                                if (self.tsf[-3] < self.tsf[-2]  and self.tsf[-2] < self.tsf[-1] and self.data['Close'] < self.tsf[-1] ): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf) + (spread * 0.01), sl = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:    
                                #if (self.trix[-2] < 0 and self.trix[-1] > 0): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_trix * self.atrweight_trix) + (spread * 0.01), sl = self.data['Close'] - (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:   
                                #if (self.aroonup[-2] < self.aroondown[-2] and self.aroonup[-1] > self.aroondown[-1]): 
                                #    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon) + (spread * 0.01), sl = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:    
                                if (self.mfi[-2] < 20 and self.mfi[-1] > 20): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi))

                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                #if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:    
                                #if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:    
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:   
                                #if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:    
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_willr * self.atrweight_willr >= 0.03:    
                                if (self.willr[-2] > -20 and self.willr[-1] < -20):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_willr * self.atrweight_willr) - (spread * 0.01), sl = self.data['Close'] + (self.atr_willr * self.atrweight_willr))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:    
                                #if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_cci * self.atrweight_cci >= 0.03:   
                                #if (self.cci[-2] > 100 and self.cci[-1] < 100):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_cci * self.atrweight_cci) - (spread * 0.01), sl = self.data['Close'] + (self.atr_cci * self.atrweight_cci))
                            if self.w >= self.atr_mom * self.atrweight_mom >= 0.03:    
                                if (self.mom[-2] > 30 and self.mom[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mom * self.atrweight_mom) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mom * self.atrweight_mom))
                            if self.w >= self.atr_roc * self.atrweight_roc >= 0.03:    
                                if (self.roc[-2] > 30 and self.roc[-1] < 30):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_roc * self.atrweight_roc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_roc * self.atrweight_roc))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:    
                                #if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            if self.w >= self.atr_tsf * self.atrweight_tsf >= 0.03:    
                                if (self.tsf[-3] > self.tsf[-2]  and self.tsf[-2] > self.tsf[-1] and self.data['Close'] > self.tsf[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_tsf * self.atrweight_tsf) - (spread * 0.01), sl = self.data['Close'] + (self.atr_tsf * self.atrweight_tsf))
                            #if self.w >= self.atr_trix * self.atrweight_trix >= 0.03:    
                                #if (self.trix[-2] > 30 and self.trix[-1] < 30):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_trix * self.atrweight_trix) - (spread * 0.01), sl = self.data['Close'] + (self.atr_trix * self.atrweight_trix))
                            #if self.w >= self.atr_aroon * self.atrweight_aroon >= 0.03:   
                                #if (self.aroonup[-2] > self.aroondown[-2] and self.aroonup[-1] < self.aroondown[-1]):
                                #    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_aroon * self.atrweight_aroon) - (spread * 0.01), sl = self.data['Close'] + (self.atr_aroon * self.atrweight_aroon))
                            if self.w >= self.atr_mfi * self.atrweight_mfi >= 0.03:   
                                if (self.mfi[-2] > 80 and self.mfi[-1] < 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_mfi * self.atrweight_mfi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_mfi * self.atrweight_mfi))


                        print('-----------------------------------------------------------')
                        print('ルール16通りのバックテスト開始')
                        dt_now = datetime.datetime.now()
                        print(dt_now)

                        #rule16_1(32767)バックテスト
                        bt = Backtest(df_, rule16_1, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                
                        #rule16_2(32512)バックテスト
                        bt = Backtest(df_, rule16_2, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                        
                        #rule16_3(28912)バックテスト
                        bt = Backtest(df_, rule16_3, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                        
                        #rule16_4(28687)バックテスト
                        bt = Backtest(df_, rule16_4, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                        
                        #rule16_5(19660)バックテスト
                        bt = Backtest(df_, rule16_5, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                    
                        #rule16_6(19507)バックテスト
                        bt = Backtest(df_, rule16_6, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                        
                        #rule16_7(17347)バックテスト
                        bt = Backtest(df_, rule16_7, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                        
                        #rule16_8(17212)バックテスト
                        bt = Backtest(df_, rule16_8, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)

                        #rule16_9(10922)バックテスト
                        bt = Backtest(df_, rule16_9, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)

                        #rule16_10(10837)バックテスト
                        bt = Backtest(df_, rule16_10, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                    
                        #rule16_11(9637)バックテスト
                        bt = Backtest(df_, rule16_11, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)

                        #rule16_12(9562)バックテスト
                        bt = Backtest(df_, rule16_12, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                    
                        #rule16_13(6553)バックテスト
                        bt = Backtest(df_, rule16_13, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)

                        #rule16_14(6502)バックテスト
                        bt = Backtest(df_, rule16_14, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                        
                        #rule16_15(5782)バックテスト
                        bt = Backtest(df_, rule16_15, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)

                        #rule16_16(5737)バックテスト
                        bt = Backtest(df_, rule16_16, cash=100000, commission=spread, trade_on_close=True)
                        output = bt.run()
                        output.to_csv(path_rule, index=True, header=True)
                        df = pd.read_csv(path_rule, index_col=0)
                        Extract(df)
                #---------------------------------------------------------------
                #L8の場合
                if indi_number == 7:
                    #ここからL8のルールのクラス
                    #全部
                    class rule8_1(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        atrvalue_dmi = ATRvalue_dmi
                        atrvalue_ultosc = ATRvalue_ultosc

                        atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        atrweight_dmi = ATRweight_dmi
                        atrweight_ultosc = ATRweight_ultosc
                        
                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        dmivalue = DMIvalue
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                        
                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            
                    #EMA,BBAND,MACD
                    class rule8_2(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_ultosc = ATRvalue_ultosc

                        atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        #atrweight_dmi = ATRweight_dmi
                        #atrweight_ultosc = ATRweight_ultosc
                        
                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        #dmivalue = DMIvalue
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                            #   if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                            #   if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                            #        self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                            #   if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                            #   if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                            #        self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                        
                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                            #   if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                            #   if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                            #   if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                            #   if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            
                    #EMA,RSI,STOCH
                    class rule8_3(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_ultosc = ATRvalue_ultosc

                        atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        #atrweight_dmi = ATRweight_dmi
                        #atrweight_ultosc = ATRweight_ultosc
                        
                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        #dmivalue = DMIvalue
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                            #   if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                            #   if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                            #   if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                            #   if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                            #        self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                        
                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                            #   if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                            #   if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                            #   if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                            #   if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            
                    #EMA,DMI,ULTOSC
                    class rule8_4(Strategy):
                        atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        atrvalue_dmi = ATRvalue_dmi
                        atrvalue_ultosc = ATRvalue_ultosc

                        atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        atrweight_dmi = ATRweight_dmi
                        atrweight_ultosc = ATRweight_ultosc
                        
                        emavalue1 = EMAvalue1
                        emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        dmivalue = DMIvalue
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3

                        w = max_weight



                        def init(self):
                            self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)

                            self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            

                        def next(self):
                            #buy
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                            #   if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                            #   if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                            #   if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                            #   if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                            #        self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                        
                            #sell
                            if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                                if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                            #   if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                            #   if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                            #   if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                            #   if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            
                    #BBAND,RSI,DMI
                    class rule8_5(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_ultosc = ATRvalue_ultosc

                        #atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        atrweight_dmi = ATRweight_dmi
                        #atrweight_ultosc = ATRweight_ultosc
                        
                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        dmivalue = DMIvalue
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                            #   if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                            #       self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                            #   if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                            #   if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                            #        self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                            #   if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                            #        self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                        
                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                            #   if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                            #       self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                            #   if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                            #   if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                            #   if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            
                    #BBAND,STOCH,ULTOSC
                    class rule8_6(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        atrvalue_bband = ATRvalue_bband
                        #atrvalue_macd = ATRvalue_macd
                        #trvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_dmi = ATRvalue_dmi
                        atrvalue_ultosc = ATRvalue_ultosc

                        #atrweight_ema = ATRweight_ema
                        atrweight_bband = ATRweight_bband
                        #atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        #atrweight_dmi = ATRweight_dmi
                        atrweight_ultosc = ATRweight_ultosc
                        
                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        bbandvalue = BBANDvalue
                        #macdvalue1 = MACDvalue1
                        #macdvalue2 = MACDvalue2
                        #macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        #dmivalue = DMIvalue
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            #self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            #self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                            #   if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                            #       self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                            #   if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                            #       self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                            #   if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                            #   if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                        
                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                            #   if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                            #       self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                                if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            #if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                            #   if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                            #   if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                            #       self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                            #   if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            
                    #MACD,RSI,ULTOSC
                    class rule8_7(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        atrvalue_rsi = ATRvalue_rsi
                        #atrvalue_stoch = ATRvalue_stoch
                        #atrvalue_dmi = ATRvalue_dmi
                        atrvalue_ultosc = ATRvalue_ultosc

                        #atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        atrweight_rsi = ATRweight_rsi
                        #atrweight_stoch = ATRweight_stoch
                        #atrweight_dmi = ATRweight_dmi
                        atrweight_ultosc = ATRweight_ultosc
                        
                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        rsivalue = RSIvalue
                        #stochvalue1 = STOCHvalue1
                        #stochvalue2 = STOCHvalue2
                        #dmivalue = DMIvalue
                        ultoscvalue1 = ULTOSCvalue1
                        ultoscvalue2 = ULTOSCvalue2
                        ultoscvalue3 = ULTOSCvalue3

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            #self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            #self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            #self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            #self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                            #   if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                            #      self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01) sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                            #   if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                            #   if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                            #        self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                            #if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                            #       self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                        
                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                            #   if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                            #       self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                            #   if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                            #       self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                                if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            #if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                            #   if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            #if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                            #   if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                                if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))
                            
                    #MACD,STOCH,DMI
                    class rule8_8(Strategy):
                        #atrvalue_ema = ATRvalue_ema
                        #atrvalue_bband = ATRvalue_bband
                        atrvalue_macd = ATRvalue_macd
                        #atrvalue_rsi = ATRvalue_rsi
                        atrvalue_stoch = ATRvalue_stoch
                        atrvalue_dmi = ATRvalue_dmi
                        #atrvalue_ultosc = ATRvalue_ultosc

                        #atrweight_ema = ATRweight_ema
                        #atrweight_bband = ATRweight_bband
                        atrweight_macd = ATRweight_macd
                        #atrweight_rsi = ATRweight_rsi
                        atrweight_stoch = ATRweight_stoch
                        atrweight_dmi = ATRweight_dmi
                        #atrweight_ultosc = ATRweight_ultosc
                        
                        #emavalue1 = EMAvalue1
                        #emavalue2 = EMAvalue2
                        #bbandvalue = BBANDvalue
                        macdvalue1 = MACDvalue1
                        macdvalue2 = MACDvalue2
                        macdvalue3 = MACDvalue3
                        #rsivalue = RSIvalue
                        stochvalue1 = STOCHvalue1
                        stochvalue2 = STOCHvalue2
                        dmivalue = DMIvalue
                        #ultoscvalue1 = ULTOSCvalue1
                        #ultoscvalue2 = ULTOSCvalue2
                        #ultoscvalue3 = ULTOSCvalue3

                        w = max_weight



                        def init(self):
                            #self.atr_ema = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ema)
                            #self.atr_bband = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_bband)
                            self.atr_macd = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_macd)
                            #self.atr_rsi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_rsi)
                            self.atr_stoch = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_stoch)
                            self.atr_dmi = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_dmi)
                            #self.atr_ultosc = self.I(ATR, self.data['High'], self.data['Low'], self.data['Close'], self.atrvalue_ultosc)

                            #self.ema1 = self.I(EMA, self.data['Close'], self.emavalue1)
                            #self.ema2 = self.I(EMA, self.data['Close'], self.emavalue2)
                            #self.bband_upper, self.bband_middle, self.bband_lower = self.I(BBAND, self.data['Close'], self.bbandvalue)
                            self.macd, self.macdsignal, self.macdhist = self.I(MACD, self.data['Close'], self.macdvalue1, self.macdvalue2, self.macdvalue3)
                            #self.rsi = self.I(RSI, self.data['Close'], self.rsivalue)
                            self.K, self.D = self.I(STOCH, self.data['High'], self.data['Low'], self.data['Close'], self.stochvalue1, self.stochvalue2)
                            self.adx, self.dip, self.dim = self.I(DMI, self.data['High'], self.data['Low'], self.data['Close'], self.dmivalue)
                            #self.ultosc = self.I(ULTOSC, self.data['High'], self.data['Low'], self.data['Close'], self.ultoscvalue1, self.ultoscvalue2, self.ultoscvalue3)
                            

                        def next(self):
                            #buy
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                            #   if (self.ema1[-2] < self.ema2[-2] and self.ema1[-1] > self.ema2[-1]): 
                            #       self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ema * self.atrweight_ema) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                            #   if (self.bband_lower[-2] > self.data.Close[-2] and self.bband_lower[-1] < self.data.Close[-1]): 
                            #       self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_bband * self.atrweight_bband) + (spread * 0.01), sl = self.data['Close'] - (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] < self.macdsignal[-2] and self.macd[-1] > self.macdsignal[-1] and self.macd[-1] < 0 and self.macdsignal[-1] < 0):
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_macd * self.atrweight_macd) + (spread * 0.01), sl = self.data['Close'] - (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                            #   if (self.rsi[-2] < 30 and self.rsi[-1] > 30): 
                            #        self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] > self.K[-2] and self.D[-1] < self.K[-1] and self.D[-1] < 20 and self.K[-1] < 20): 
                                    self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch) + (spread * 0.01), sl = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] > self.dip[-2] and self.dim[-1] < self.dip[-1] and self.dim[-1] < self.adx[-1]): 
                                    self.buy(limit=self.data['Close'],tp = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi) + (spread * 0.01), sl = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                            #   if (self.ultosc[-2] < 50 and self.ultosc[-1] > 50): 
                            #        self.buy(limit=self.data['Close'], tp = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc) + (spread * 0.01), sl = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc))
                        
                            #sell
                            #if self.w >= self.atr_ema * self.atrweight_ema >= 0.03:
                            #   if (self.ema1[-2] > self.ema2[-2] and self.ema1[-1] < self.ema2[-1]):
                            #       self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ema * self.atrweight_ema) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ema * self.atrweight_ema))
                            #if self.w >= self.atr_bband * self.atrweight_bband >= 0.03:
                            #   if (self.bband_upper[-2] < self.data.Close[-2] and self.bband_upper[-1] > self.data.Close[-1]):
                            #       self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_bband * self.atrweight_bband) - (spread * 0.01), sl = self.data['Close'] + (self.atr_bband * self.atrweight_bband))
                            if self.w >= self.atr_macd * self.atrweight_macd >= 0.03:
                                if (self.macd[-2] > self.macdsignal[-2] and self.macd[-1] < self.macdsignal[-1] and self.macd[-1] > 0 and self.macdsignal[-1] > 0):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_macd * self.atrweight_macd) - (spread * 0.01), sl = self.data['Close'] + (self.atr_macd * self.atrweight_macd))
                            #if self.w >= self.atr_rsi * self.atrweight_rsi >= 0.03:
                            #   if (self.rsi[-2] > 70 and self.rsi[-1] < 70):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_rsi * self.atrweight_rsi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_rsi * self.atrweight_rsi))
                            if self.w >= self.atr_stoch * self.atrweight_stoch >= 0.03:
                                if (self.D[-2] < self.K[-2] and self.D[-1] > self.K[-1] and self.D[-1] > 80 and self.K[-1] > 80):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_stoch * self.atrweight_stoch) - (spread * 0.01), sl = self.data['Close'] + (self.atr_stoch * self.atrweight_stoch))
                            if self.w >= self.atr_dmi * self.atrweight_dmi >= 0.03:
                                if (self.dim[-2] < self.dip[-2] and self.dim[-1] > self.dip[-1] and self.dip[-1] < self.adx[-1]):
                                    self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_dmi * self.atrweight_dmi) - (spread * 0.01), sl = self.data['Close'] + (self.atr_dmi * self.atrweight_dmi))
                            #if self.w >= self.atr_ultosc * self.atrweight_ultosc >= 0.03:
                            #   if (self.ultosc[-2] > 50 and self.ultosc[-1] < 50):
                            #        self.sell(limit=self.data['Close'], tp = self.data['Close'] - (self.atr_ultosc * self.atrweight_ultosc) - (spread * 0.01), sl = self.data['Close'] + (self.atr_ultosc * self.atrweight_ultosc))

                    print('---------------------------------------------------')
                    print('ルール8通りのバックテスト開始')
                    dt_now = datetime.datetime.now()
                    #print(dt_now)

                    #rule8_1(32767)バックテスト
                    bt = Backtest(df_, rule8_1, cash=100000, commission=spread*0.0001, trade_on_close=True)
                    output = bt.run()
                    #print(output)
                    output.to_csv(path_rule, index=True, header=True)
                    df = pd.read_csv(path_rule, index_col=0)
                    Extract(df)
            
                    #rule8_2(32512)バックテスト
                    bt = Backtest(df_, rule8_2, cash=100000, commission=spread*0.0001, trade_on_close=True)
                    output = bt.run()
                    #print(output)
                    output.to_csv(path_rule, index=True, header=True)
                    df = pd.read_csv(path_rule, index_col=0)
                    Extract(df)
                    
                    #rule8_3(28912)バックテスト
                    bt = Backtest(df_, rule8_3, cash=100000, commission=spread*0.0001, trade_on_close=True)
                    output = bt.run()
                    #print(output)
                    output.to_csv(path_rule, index=True, header=True)
                    df = pd.read_csv(path_rule, index_col=0)
                    Extract(df)
                    
                    #rule8_4(28687)バックテスト
                    bt = Backtest(df_, rule8_4, cash=100000, commission=spread*0.0001, trade_on_close=True)
                    output = bt.run()
                    #print(output)
                    output.to_csv(path_rule, index=True, header=True)
                    df = pd.read_csv(path_rule, index_col=0)
                    Extract(df)
                    
                    #rule8_5(19660)バックテスト
                    bt = Backtest(df_, rule8_5, cash=100000, commission=spread*0.0001, trade_on_close=True)
                    output = bt.run()
                    #print(output)
                    output.to_csv(path_rule, index=True, header=True)
                    df = pd.read_csv(path_rule, index_col=0)
                    Extract(df)
                
                    #rule8_6(19507)バックテスト
                    bt = Backtest(df_, rule8_6, cash=100000, commission=spread*0.0001, trade_on_close=True)
                    output = bt.run()
                    #print(output)
                    output.to_csv(path_rule, index=True, header=True)
                    df = pd.read_csv(path_rule, index_col=0)
                    Extract(df)
                    
                    #rule8_7(17347)バックテスト
                    bt = Backtest(df_, rule8_7, cash=100000, commission=spread*0.0001, trade_on_close=True)
                    output = bt.run()
                    #print(output)
                    output.to_csv(path_rule, index=True, header=True)
                    df = pd.read_csv(path_rule, index_col=0)
                    Extract(df)
                    
                    #rule8_8(17212)バックテスト
                    bt = Backtest(df_, rule8_8, cash=100000, commission=spread*0.0001, trade_on_close=True)
                    output = bt.run()
                    #print(output)
                    output.to_csv(path_rule, index=True, header=True)
                    df = pd.read_csv(path_rule, index_col=0)
                    Extract(df)   

                #目的変数のlistをDataFrame化
                result1_df = pd.DataFrame(result1)
                result1_df.columns = ['Exposure Time [%]']#小さい方がいい

                result2_df = pd.DataFrame(result2)
                result2_df.columns = ['Equity Final [$]']

                result3_df = pd.DataFrame(result3)
                result3_df.columns = ['Equity Peak [$]']

                result4_df = pd.DataFrame(result4)
                result4_df.columns = ['Return [%]']
                '''
                result5_df = pd.DataFrame(result5)
                result5_df.columns = ['Buy & Hold Return [%]']
                
                result6_df = pd.DataFrame(result6)
                result6_df.columns = ['Sharpe Ratio']

                result7_df = pd.DataFrame(result7)
                result7_df.columns = ['Sortino Ratio']
                '''
                result8_df = pd.DataFrame(result8)
                result8_df.columns = ['Calmar Ratio']

                result9_df = pd.DataFrame(result9)
                result9_df.columns = ['Max. Drawdown [%]']#小さい方がいい

                result10_df = pd.DataFrame(result10)
                result10_df.columns = ['Avg. Drawdown [%]']#小さい方がいい

                result11_df = pd.DataFrame(result11)
                result11_df.columns = ['Trades']#小さい方がいい

                result12_df = pd.DataFrame(result12)
                result12_df.columns = ['Win Rate [%]']

                result13_df = pd.DataFrame(result13)
                result13_df.columns = ['Best Trade [%]']

                result14_df = pd.DataFrame(result14)
                result14_df.columns = ['Worst Trade [%]']#小さい方がいい

                result15_df = pd.DataFrame(result15)
                result15_df.columns = ['Avg. Trade [%]']

                result16_df = pd.DataFrame(result16)
                result16_df.columns = ['Profit Factor']

                result17_df = pd.DataFrame(result17)
                result17_df.columns = ['Expectancy [%]']

                result18_df = pd.DataFrame(result18)
                result18_df.columns = ['SQN']

                #NaNが入っていた場合抜けるようにする？
                #if result1_df が　NaN　を含まない:
                #   if result2_df が　NaN　を含まない:
                #       if result3_df が　NaN　を含まない:
                #                   ・
                #                   ・
                #                   ・
                #           if result18_df が　NaN　を含まない:
                #               ・回帰分析
                #               ・すべての組み合わせの予測値算出
                #               ・DEA
                #               
                #のようにすればNaNがあったらその先しなくなるのでは
                if (result1_df.isnull().values.sum() != 0)  == False:
                    if (result2_df.isnull().values.sum() != 0)  == False:
                        if (result3_df.isnull().values.sum() != 0)  == False:
                            if (result4_df.isnull().values.sum() != 0)  == False:
                                if (result8_df.isnull().values.sum() != 0)  == False:
                                    if (result9_df.isnull().values.sum() != 0)  == False:
                                        if (result10_df.isnull().values.sum() != 0)  == False:
                                            if (result11_df.isnull().values.sum() != 0)  == False:
                                                if(result12_df.isnull().values.sum() != 0)  == False:
                                                    if (result13_df.isnull().values.sum() != 0)  == False:
                                                        if (result14_df.isnull().values.sum() != 0)  == False:
                                                            if (result15_df.isnull().values.sum() != 0)  == False:
                                                                if (result16_df.isnull().values.sum() != 0)  == False:
                                                                    if (result17_df.isnull().values.sum() != 0)  == False:
                                                                        if (result18_df.isnull().values.sum() != 0)  == False:
                                                                            #print(dt_now)
                                                                            #評価指標1つ1つについて回帰分析
                                                                            keisuu1 = kaiki(ruleselect_df,result1_df)
                                                                            keisuu2 = kaiki(ruleselect_df,result2_df)
                                                                            keisuu3 = kaiki(ruleselect_df,result3_df)
                                                                            keisuu4 = kaiki(ruleselect_df,result4_df)
                                                                            #keisuu5 = kaiki(ruleselect_df,result5_df)
                                                                            #keisuu6 = kaiki(ruleselect_df,result6_df)
                                                                            #keisuu7 = kaiki(ruleselect_df,result7_df)
                                                                            keisuu8 = kaiki(ruleselect_df,result8_df)
                                                                            keisuu9 = kaiki(ruleselect_df,result9_df)
                                                                            keisuu10 = kaiki(ruleselect_df,result10_df)
                                                                            keisuu11 = kaiki(ruleselect_df,result11_df)
                                                                            keisuu12 = kaiki(ruleselect_df,result12_df)
                                                                            keisuu13 = kaiki(ruleselect_df,result13_df)
                                                                            keisuu14 = kaiki(ruleselect_df,result14_df)
                                                                            keisuu15 = kaiki(ruleselect_df,result15_df)
                                                                            keisuu16 = kaiki(ruleselect_df,result16_df)
                                                                            keisuu17 = kaiki(ruleselect_df,result17_df)
                                                                            keisuu18 = kaiki(ruleselect_df,result18_df)
                                                                            #回帰分析の結果をすべてくっつけて1つにする
                                                                            hyouka_df = pd.concat([keisuu1, keisuu2, keisuu3, keisuu4, keisuu8, keisuu9, keisuu10, keisuu11, keisuu12, keisuu13, keisuu14, keisuu15, keisuu16, keisuu17, keisuu18])
                                                                            hyouka_df = hyouka_df.reset_index(drop=True)#index振り直し
                                                                            
                                                                            #ndarray化
                                                                            hyouka_array = hyouka_df.values

                                                                            #転置
                                                                            hyouka_array = hyouka_array.T

                                                                            print('---------------------------------------------------')
                                                                            print('全ての組み合わせに対して係数から指標の値を計算開始')
                                                                            dt_now = datetime.datetime.now()
                                                                            #print(dt_now)
                                                                            #組み合わせすべてで係数から16個の指標の値を計算
                                                                            hyoukaall = np.dot(ruleall_array,hyouka_array)
                                                                            hyoukaall_df = pd.DataFrame(hyoukaall)
                                                                            hyoukaall_df.columns=sihyou
                                                                            
                                                                            #全値の絶対値をとる
                                                                            dea_df = np.fabs(hyoukaall_df)
                                                                            #dea_df.to_csv("C:/Users/xi/MT5/out_dat/hyouka.csv", index=True, header=True)

                                                                            print('---------------------------------------------------')
                                                                            print('最適なルールを選択開始')
                                                                            dt_now = datetime.datetime.now()
                                                                            #print(dt_now)
                                                                            if indi_number == 7:
                                                                                num_in = 5#入力の数
                                                                                num_out = 10#出力の数
                                                                                if indi_number == 7:
                                                                                    num_rule = 128#支店の数
                                                                                if indi_number == 15:
                                                                                    num_rule = 32768#支店の数
                                                                                of_values = []

                                                                                in_df = dea_df[['Exposure Time [%]','Max. Drawdown [%]','Avg. Drawdown [%]','Trades','Worst Trade [%]']].copy()#入力のデータを格納
                                                                                
                                                                                out_df = dea_df[['Equity Final [$]','Equity Peak [$]','Return [%]','Calmar Ratio','Win Rate [%]','Best Trade [%]','Avg. Trade [%]','Profit Factor','Expectancy [%]','SQN']].copy()#出力のデータを格納
                                                                                
                                                                                #変数宣言(重みlamda)
                                                                                lamda_list = []#一つの支店の入力の変数を格納するリスト

                                                                                for j in  range(num_rule):#支店の数だけ繰り返し
                                                                                    exec(f"lamda_{j} = pulp.LpVariable('lamda_{j}', 0, 50 ,'Continuous')")
                                                                                    exec(f"lamda_list.append(lamda_{j})")

                                                                                #DataFrame化
                                                                                lamda_list_df = pd.DataFrame(lamda_list)
                                                                                lamda_list_df = lamda_list_df.T

                                                                                theta = pulp.LpVariable('theta', 0, 50 ,'Continuous')

                                                                                #開始時間
                                                                                dt1 = datetime.datetime.now()
                                                                                print('---------------------------------------------------')
                                                                                print("目的関数算出開始")
                                                                                for i in range(num_rule):#支店の数だけ繰り返し
                                                                                    #rint('-----------------------------------------------------------')
                                                                                    #print(f"ルール{i+1}の目的関数算出開始")

                                                                                    #線形計画問題の宣言
                                                                                    #problem = pulp.LpProblem('DEA_problem',pulp.LpMinimize)
                                                                                    problem = pulp.LpProblem()

                                                                                    #目的関数
                                                                                    problem += theta

                                                                                    #制約条件
                                                                                    for j in range(num_in):#入力について

                                                                                        string = 0
                                                                                        string_all = 0
                                                                                        for k in range(num_rule):
                                                                                            exec(f"string = + in_df.iat[{k},j] * lamda_list_df.iat[0,{k}] ")
                                                                                            string_all += string

                                                                                        problem += theta * in_df.iat[i,j] - (string_all) >= 0

                                                                                    for j in range(num_out):#出力について

                                                                                        string = 0
                                                                                        string_all = 0
                                                                                        for k in range(num_rule):
                                                                                            exec(f"string = out_df.iat[{k},j] * lamda_list_df.iat[0,{k}] ")
                                                                                            string_all += string
                                                                                        
                                                                                        problem += out_df.iat[i,j] - (string_all) <= 0

                                                                                    for j in range(len(lamda_list)):#lamdaはすべて0以上
                                                                                        problem += lamda_list_df.iat[0,j] >= 0

                                                                                    solver = pulp.PULP_CBC_CMD(msg=0)#変な表示を非表示に
                                                                                    #計算
                                                                                    problem.solve(solver)

                                                                                    value = pulp.value(problem.objective)
                                                                                    if not value:
                                                                                        of_values.append(0.0)
                                                                                        #print(f"ルール{i+1}の目的関数値 = {0.0}")
                                                                                    else:
                                                                                        of_values.append(value)
                                                                                        #print(f"ルール{i+1}の目的関数値 = {value}")

                                                                                #終了時間
                                                                                dt2 = datetime.datetime.now()
                                                                                print('---------------------------------------------------')
                                                                                print("処理にかかった時間")
                                                                                td = dt2 - dt1
                                                                                print(td)  

                                                                                #目的関数値のリストをデータフレーム化し名前を付ける(目的関数：Objective function？)
                                                                                of_values_df = pd.DataFrame(of_values)
                                                                                of_values_df.columns = ['of_value']

                                                                                #2^7の直交表とくっつける
                                                                                all_df = pd.concat([dea_df,of_values_df], axis = 1)

                                                                                #目的間数値が1.0のものだけ抜き出したデータフレームを作成
                                                                                df_large = all_df.query('of_value >= 1.0')

                                                                            #抜き出したものの中でopt_factorの値が一番大きいルールのindex番号(ルールの番号)を抜き出す
                                                                            max_value = []
                                                                            num = df_large[opt_factor].idxmax()
                                                                            num = np.array(num,dtype='int64')
                                                                            max_value.append(num)
                                                                            max_value_df = pd.DataFrame(max_value)
                                                                            best = max_value_df.tail(1)
                                                                            print(best)
                                                                            best.to_csv("C:/Users/xi/MT5/out_dat/Strategy.csv", index=True, header=True)

                                                                            # 実際に売買をするプログラムへ  
            
    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


