Exemplo n.º 1
0
    def __init__(self):
                    
        # Price Channels
        self.dmi = DirectionalMovementIndex(self.data0, period=self.p.period)
        self.adx_ma = SMA(self.dmi.adx(0), period=2)
        
        # self.adx_ta = bt.talib.ADX(self.data.high,self.data.low,self.data.close,timeperiod=14)
        ## Consitions
        self.adx_cup = crossover.CrossUp(self.dmi.adx(0), self.adx_ma.sma(0))
        self.adx_cdown = crossover.CrossDown(self.dmi.adx(0), self.adx_ma.sma(0))
        
        self.counter_up = And(self.dmi.plusDI(0) > self.dmi.minusDI(0), self.dmi.adx(0) > self.adx_ma.sma(0))
        self.counter_down = And(self.dmi.plusDI(0) < self.dmi.minusDI(0), self.dmi.adx(0) > self.adx_ma.sma(0))
         
        self.pgm_cond = And(self.dmi.plusDI(0) > self.dmi.minusDI(0), self.adx_cup(0) == 1)
        self.plm_cond = And(self.dmi.plusDI(0) < self.dmi.minusDI(0), self.adx_cup(0) == 1)
        
        self.run_once = True
        self.bbh_hhv = 0
        self.rbl_llv = 0

        self.plotlines.range_cond._plotskip = True
        self.plotlines.comparator._plotskip = True
        self.plotlines.pgm._plotskip = True
        self.plotlines.plm._plotskip = True     
Exemplo n.º 2
0
    def __init__(self):

        # print('Initializing RSC for Data :', self.data0._name)
        # self.benchmark = self.getdatabyname(self.p.benchmark_name)
        l_data = len(self.data0.array)
        l_bench = len(self.data1.array)

        if l_data != l_bench:
            raise Exception(
                f"Data Error in : {self.data0._name}, Please ensure data length is same for the benchmark & stock."
            )

        # print('Length of Stock :',l_data, 'Length of Benchmark :', l_bench)

        # self.data.close.get(size=1, ago=-1)
        # a = self.data1.close(-502)

        # Price Channels
        self.rsc = self.data0.close / self.data1.close
        self.rsc_ma = SMA(self.rsc, period=10)

        ## Up / Down cond
        self.rsc_cup = crossover.CrossUp(self.rsc, self.rsc_ma)
        self.rsc_cdown = crossover.CrossDown(self.rsc, self.rsc_ma)

        self.up = And(self.rsc > self.rsc_ma)
        self.down = And(self.rsc < self.rsc_ma)

        self.first_start = True
        self.rsh_hhv = 0
        self.rsl_llv = 0
        # print('Done Initializing RSC for Data :', self.data0._name)

        self.plotlines.range_cond._plotskip = True
        self.plotlines.comparator._plotskip = True
Exemplo n.º 3
0
    def __init__(self):
                    
        # Price Channels
        self.pdi = PlusDirectionalIndicator(self.data, period=14)
        self.mdi = MinusDirectionalIndicator(self.data, period=14)
        self.adx = AverageDirectionalMovementIndex(self.data, period=14)

        ## HHPC5 - LLPC5
        self.pdih_condition = crossover.CrossDown(self.pdi, self.mdi)
        self.mdil_condition = crossover.CrossUp(self.pdi, self.mdi)
        
        self.up = And(self.pdi.plusDI > self.mdi.minusDI)
        self.down = And(self.pdi.plusDI < self.mdi.minusDI)
         
        self.first_start = True
Exemplo n.º 4
0
    def __init__(self):

        hi, lo = self.data.high, self.data.low
        if self.params.lookback:
            hi.lo = hi(self.params.lookback), lo(self.params.lookback)

        # Price Channels
        self.pchannel = pchannel.priceChannel(self.data0,
                                              period=self.params.period,
                                              subplot=False)
        self.lines.pch = self.pchannel.lines.pch
        self.lines.pcl = self.pchannel.lines.pcl
        self.hhllpc = hhpc.PC(self.data0, period=5, subplot=False)
        self.lines.hhpc = self.hhllpc.lines.hhpc
        self.lines.llpc = self.hhllpc.lines.llpc

        # Conditions Low < PCL and High > PCH
        # Can you please check which condition is correct?

        # CONDITION 1 - Checks crossover with the price channel of previous bar
        # (This is how Harsh Bhaiya checks in HHPC)
        # self.hhhpc_condition = crossover.CrossDown(self.data.low, self.pcl(-1))
        # self.lllpc_condition = crossover.CrossUp(self.data.high, self.pch(-1))

        # Condition 2 - Checks crossover with the price channel of current bar
        self.hhhpc_condition = crossover.CrossDown(self.data.low,
                                                   self.lines.llpc)
        self.lllpc_condition = crossover.CrossUp(self.data.high,
                                                 self.lines.hhpc)

        # Checking candles where High >= HHPC, Low <= LLPC
        self.overhhpc = Cmp(self.data0.high, self.lines.hhpc)
        self.underllpc = Cmp(self.lines.llpc, self.data0.low)

        # Miscellenaous Variables
        self.start = True
        self.hstart = 0  # Start of range of HHHPC. Changes when HHHPC condition met.
        self.lstart = 0  # For LLLPC

        self.hfirst = True  # 1st time condition met for HHHPC. Different behaviour
        self.lfirst = True  # For LLLPC

        # Useless transfer variables because I can't figure out
        # how to assign "Highest" to HHHPC[0] and same for LLLPC
        self.temph = Highest(hi, period=self.params.period, subplot=False)
        self.templ = Lowest(lo, period=self.params.period, subplot=False)
Exemplo n.º 5
0
    def __init__(self):

        hi, lo = self.data.high, self.data.low
        if self.p.lookback:  # move backwards as needed
            hi, lo = hi(self.p.lookback), lo(self.p.lookback)

        # Price Channels
        self.pch = basicops.Highest(hi, period=self.p.period, plotskip=True)
        self.pcl = basicops.Lowest(lo, period=self.p.period, plotskip=True)

        ## HHPC5 - LLPC5
        self.pch_condition = crossover.CrossUp(self.data.high(0), self.pch(0))
        self.pcl_condition = crossover.CrossDown(self.data.low(0), self.pcl(0))

        self.range_lowest = 0
        self.range_highest = 0

        self.first_start = True

        self.plotlines.comparator._plotskip = True
Exemplo n.º 6
0
    def __init__(self):
        # Mix-in & directly from object -> does not necessarily need super
        # super(EnvelopeMixIn, self).__init__()

        hi, lo = self.data.high, self.data.low
        if self.p.lookback:  # move backwards as needed
            hi, lo = hi(self.p.lookback), lo(self.p.lookback)

        # Price Channels
        self.pch = basicops.Highest(hi, period=self.p.period, subplot=False)
        self.pcl = basicops.Lowest(lo, period=self.p.period, subplot=False)

        ## HHPC5 - LLPC5
        self.pch_condition = crossover.CrossUp(self.data.high(0), self.pch(0))
        self.pcl_condition = crossover.CrossDown(self.data.low(0), self.pcl(0))

        self.first_start = True

        self.plotlines.pch_counter._plotskip = True
        self.plotlines.pcl_counter._plotskip = True
        self.plotlines.hhpc._plotskip = True