예제 #1
0
    def __init__(self):
        super().__init__()

        self.kst = btind.KnowSureThing(self.datas[0], rma1=self.params.kst_rma1, rma2=self.params.kst_rma2, rma3=self.params.kst_rma3,
                                       rma4=self.params.kst_rma4,
                                       rp1=self.params.kst_period, rp2=self.params.kst_period, rp3=self.params.kst_period,
                                       rp4=self.params.kst_period)

        self.macd = btind.MACD(
            self.datas[0], period_me1=self.params.macd_period_me1, period_me2=self.params.macd_period_me2,
            period_signal=self.params.macd_period_signal)

        # self.trix = btind.Trix(
        #     self.datas[0], period=self.params.trix_period)

        # self.tsi = btind.TrueStrengthIndicator(
        #     self.datas[0], period1=self.params.tsi_period1, period2=self.params.tsi_period2, pchange=self.params.tsi_pchange)

        self.ao = btind.AwesomeOscillator(
            self.datas[0], fast=self.params.ao_fast, slow=self.params.ao_slow)

        # self.adx = btind.AverageDirectionalMovementIndex(self.datas[0], period=self.params.adx_period)

        # self.dpo = btind.DetrendedPriceOscillator(self.datas[0])
        #
        self.psar = btind.ParabolicSAR(self.datas[0])
예제 #2
0
    def __init__(self):
        # Add indicators to add load

        btind.SMA(period=self.p.smaperiod)
        btind.MACD(period_me1=self.p.macdperiod1,
                   period_me2=self.p.macdperiod2,
                   period_signal=self.p.macdperiod3)
예제 #3
0
 def __init__(self):
     btind.SMA()
     btind.Stochastic()
     btind.RSI()
     btind.MACD()
     btind.CCI()
     TestInd().plotinfo.plot = False
예제 #4
0
 def __init__(self):
     btind.SMA()
     btind.Stochastic()
     btind.RSI()
     btind.MACD()
     btind.CCI()
     TestInd().plotinfo.plot = False
     sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
     crossover = bt.ind.CrossOver(sma1, sma2)
     self.signal_add(bt.SIGNAL_LONG, crossover)
예제 #5
0
    def __init__(self):

        #keep a log of where we are in the datafeed
        self.dataclose = self.datas[0].close

        #create fast and slow moving averages
        self.ma_fast = btind.SMA(period=self.p.smafast)
        self.ma_slow = btind.SMA(period=self.p.smaslow)
        self.macd = btind.MACD(self.data,
                               period_me1=self.p.macd1,
                               period_me2=self.p.macd2,
                               period_signal=self.p.macdsig)

        # set values for when the fast ma crosses the slow ma w backtrader's indicator
        # -1 is bearish, 1 is bullish
        self.crossover = btind.CrossOver(self.ma_fast, self.ma_slow)
예제 #6
0
파일: atr_srn.py 프로젝트: cujeu/bt
    def __init__(self, pool_list, dataId_to_ticker_d, ticker_to_dataId_d,
                 start_date, end_date):
        # Keep a reference to the "close" line in the data[0] dataseries
        self.bar_num = 0
        #self.index_50_date_stock_dict=self.get_index_50_date_stock()
        self.pool_list = pool_list
        self.dataId_to_ticker_dict = dataId_to_ticker_d
        self.ticker_to_dataId_dict = ticker_to_dataId_d
        self.start_date = start_date
        self.end_date = end_date
        self.position_list = [
        ]  #postion order ["sym", "date", "close", "high", "perc", "exit","edate","eperc","strategy"]
        self.csCount = 0
        self.barDiv = 0
        self.periodTD9 = 12
        self.pastTD9 = [0] * 20
        self.downTD9 = 0

        self.hasPosition = False
        self.entryPrice = 100
        self.highPrice = 100
        self.newLowDiv = 100
        self.newLowBar = 0
        self.atrTrend = False
        self.curStrategy = 0  #0:idle 10:divergence 11: div + 20ma turn up div+20ma is what happen after divergence
        #20:atr

        global g_entry_list
        g_entry_list = []

        # add indicators
        for d in self.datas:
            ## d.baseline = btind.ExponentialMovingAverage(d, period=21)
            d.ema20 = btind.ExponentialMovingAverage(d, period=20)
            d.ema60 = btind.ExponentialMovingAverage(d, period=60)
            d.macd = btind.MACD(d)
            d.priceDiv = PriceDiv(d)
            d.data_obv = OnBalanceVolume(d)
            d.data_obv20 = btind.SMA(d.data_obv, period=20)
            d.data_atr = AtrTrend(d)
            #d.data_bb = btind.BollingerBands(d, period=20, devfactor=2.0)
            #d.data_kc = KeltnerChannel(d, periodEMA = 20, periodATR = 20, devfactor=1.5 )
            #d.data_rg = RGChannel(d)

            self.log('stategy ATR init :' + d._name)
예제 #7
0
    def __init__(self):
        sma = btind.SMA(subplot=self.params.smasubplot)

        macd = btind.MACD()
        # In SMA we passed plot directly as kwarg, here the plotinfo.plot
        # attribute is changed - same effect
        macd.plotinfo.plot = not self.params.nomacdplot

        # Let's put rsi on stochastic/sma or the other way round
        stoc = btind.Stochastic()
        rsi = btind.RSI()
        if self.params.stocrsi:
            stoc.plotinfo.plotmaster = rsi
            stoc.plotinfo.plotlinelabels = self.p.stocrsilabels
        elif self.params.rsioverstoc:
            rsi.plotinfo.plotmaster = stoc
        elif self.params.rsioversma:
            rsi.plotinfo.plotmaster = sma
예제 #8
0
    def __init__(self, pool_list, dataId_to_ticker_d, ticker_to_dataId_d,
                 start_date, end_date):
        # Keep a reference to the "close" line in the data[0] dataseries
        self.bar_num = 0
        #self.index_50_date_stock_dict=self.get_index_50_date_stock()
        self.pool_list = pool_list
        self.dataId_to_ticker_dict = dataId_to_ticker_d
        self.ticker_to_dataId_dict = ticker_to_dataId_d
        self.start_date = start_date
        self.end_date = end_date
        self.position_list = [
        ]  #postion order ["sym", "date", "close", "high", "perc", "exit","edate","eperc"]
        self.csCount = 0

        self.hasPosition = False
        self.entryPrice = 100
        self.highPrice = 100
        self.newLowDiv = 100
        self.newLowBar = 0

        global g_entry_list
        g_entry_list = []

        # add indicators
        for d in self.datas:
            ## d.baseline = btind.ExponentialMovingAverage(d, period=21)
            d.ema20 = btind.ExponentialMovingAverage(d, period=20)
            d.ema60 = btind.ExponentialMovingAverage(d, period=60)
            d.macd = btind.MACD(d)
            d.priceDiv = PriceDiv(d)
            d.data_obv = OnBalanceVolume(d)
            d.data_obv20 = btind.SMA(d.data_obv, period=20)
            d.data_bb = btind.BollingerBands(d, period=14, devfactor=2.0)
            d.data_kc = KeltnerChannel(d,
                                       periodEMA=20,
                                       periodATR=20,
                                       devfactor=1.5)
            d.data_rg = RGChannel(d)

            self.log('stategy data init :' + d._name)
예제 #9
0
    def __init__(self):
        super().__init__()
        self.rsi = btind.RelativeStrengthIndex(self.datas[0], period = self.params.rsi_period)
        self.prank_rsi= btind.PercentRank(self.rsi, period = self.params.percent_period) * 100

        self.macd = btind.MACD(self.datas[0], period_me1 = self.params.period1, period_me2 = self.params.period2)
        self.prank_macd = btind.PercentRank(self.macd, period=self.params.percent_period) * 100

        self.buy_limit_rsi = self.params.rsi_limit
        self.sell_limit_rsi = 100 - self.buy_limit_rsi

        self.buy_limit_rsi2 = self.params.rsi_limit2
        self.sell_limit_rsi2 = 100 - self.buy_limit_rsi2

        self.buy_limit_macd = self.params.macd_limit
        self.sell_limit_macd = 100 - self.buy_limit_macd

        self.buy_limit_macd2 = self.params.macd_limit2
        self.sell_limit_macd2 = 100 - self.buy_limit_macd2

        self.pendingBuy = False
        self.pendingSell = False
예제 #10
0
    def __init__(self):
        super().__init__()
        self.ma = btind.MovingAverageSimple(self.datas[0], period = self.params.ma)
        self.ma1 = btind.MovingAverageSimple(self.datas[0], period = self.params.ma1)
        self.ma2 = btind.MovingAverageSimple(self.datas[0], period = self.params.ma2)
        self.atr = btind.AverageTrueRange(self.datas[0])

        self.kst = btind.KnowSureThing(self.datas[0])

        self.macd = btind.MACD(self.datas[0])

        self.trix = btind.TrixSignal(self.datas[0])

        self.ao = btind.AwesomeOscillator(self.datas[0])

        self.tsi = btind.TrueStrengthIndicator(self.datas[0])

        self.psar = btind.ParabolicSAR(self.datas[0])

        self.adx = btind.AverageDirectionalMovementIndex(self.datas[0])

        self.dpo = btind.DetrendedPriceOscillator(self.datas[0])

        self.rsi = btind.RSI(self.datas[0])

        self.accdec = btind.AccelerationDecelerationOscillator(self.datas[0])

        self.bbands = btind.BollingerBands(self.datas[0])

        self.cci = btind.CommodityChannelIndex(self.datas[0])

        self.pgood = btind.PrettyGoodOscillator(self.datas[0])

        self.williamsr = btind.WilliamsR(self.datas[0])

        self.uo = btind.UltimateOscillator(self.datas[0])

        self.stoch = btind.Stochastic(self.datas[0])
예제 #11
0
    def __init__(self):
        # To control operation entries
        self.orderid = list()
        self.order = None

        self.counttostop = 0
        self.datastatus = 0

        self.state = np.empty([4, 8])
        self.stateFilled = 0
        self.agent = Agent(8, 4)
        # Create SMA on 2nd data
        self.ema = bt.indicators.MovAv.EMA(self.data, period=self.p.smaperiod)
        #self.ema = bt.indicators.MovAv.SMA(self.data, period=self.p.smaperiod)
        self.macd = btind.MACD(self.data)
        self.williamad = btind.WilliamsAD(self.data)
        self.bollinger = btind.BollingerBands(self.data,
                                              period=self.p.smaperiod)

        self.currentOrder = None
        print('--------------------------------------------------')
        print('Strategy Created')
        print('--------------------------------------------------')
예제 #12
0
 def __init__(self):
     self.oss = btind.MACD(
         self.datas[0], period_me1=self.params.period_me1, period_me2=self.params.period_me2,
         period_signal=self.params.period_signal)
     super().__init__()
예제 #13
0
 def __init__(self):
     super().__init__()
     self.addminperiod(27)
     self.MACD = btind.MACD(self.datas[0], period_me1 = self.p.period_me1, period_me2 = self.p.period_me2)