For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Variable change confusion



  • class scale(bt.Indicator):
        lines = ('output',)
        params = (('value', 5),)
    
        def __init__(self):
            self.h = btind.Highest(self.data, period=252)
            self.l = btind.Lowest(self.data, period=252)
            self.min = .2
            self.max = .8
        def next(self):
            self.lines.output[0] = (((self.max-self.min)* (self.data-self.l))/(self.h-self.l))+ self.min
    class gamma1(bt.Indicator):
        lines = ('energy',)
    
        params = (('value', 5),)
        
        def __init__(self):
            self.o = (self.data.open+self.data.close[-1])/2
            self.h = bt.If(self.data.high  > self.data.close(-1),self.data.high, self.data.close(-1))
            self.l = bt.If(self.data.low  < self.data.close(-1),self.data.low, self.data.close(-1))
            self.c = (self.o+self.h+self.l+self.data.close)/4
            self.m  = bt.If(self.h > self.c(-1), self.h, self.c(-1))
            self.n = bt.If(self.l < self.c(-1), self.l, self.c(-1))
            self.a = self.m - self.n
            self.b = btind.SumN(self.a, period=3)
            self.hl = btind.Highest(self.h, period=3)-btind.Lowest(self.l, period=3)
            
            
        def next(self):
            z = self.b[0]/self.hl[0]
            y = math.log(z,10)
            r = math.log(10, 10)
            g = y/r
            #k = bt.DivByZero(y,r)
            self.lines.energy[0] = g/(math.log(3,10)/ math.log(10,10))
    class gamma3(bt.Indicator):
        lines = ('energy',)
    
        params = (('value', 5),)
        
        def __init__(self):
            self.o = (self.data.open+self.data.close[-1])/2
            self.h = bt.If(self.data.high  > self.data.close(-1),self.data.high, self.data.close(-1))
            self.l = bt.If(self.data.low  < self.data.close(-1),self.data.low, self.data.close(-1))
            self.c = (self.o+self.h+self.l+self.data.close)/4
            self.m  = bt.If(self.data.high > self.data.close(-1), self.data.high, self.data.close(-1))
            self.n = bt.If(self.data.low < self.data.close(-1), self.data.low, self.data.close(-1))
            self.a = self.m - self.n
            self.b = btind.SumN(self.a, period=8)
            self.hl = btind.Highest(self.data.high, period=8)-btind.Lowest(self.data.low, period=8)
            
            
        def next(self):
            z = self.b[0]/self.hl[0]
            y = math.log(z,10)
            r = math.log(8, 10)
            #k = bt.DivByZero(y,r)
            self.lines.energy[0] = y/r
    class CLaguerreRSI(bt.Indicator):
        alias = ('CLRSI',)
        lines = ('lrsi',)
        params = (('e', 0.5),)
    
        plotinfo = dict(
            plotymargin=0.15,
            plotyticks=[0.0, 0.2, 0.5, 0.8, 1.0]
        )
        def __init__(self):
            self.addminperiod(6)
            self.l0 = [0, 0]
            self.l1 = [0, 0]
            self.l2 = [0, 0]
            self.l3 = [0, 0]
            self.gamma2 = gamma1(self.data)
            self.gamma = scale(self.gamma2.energy(0))
            self.practicegamma = gamma3(self.data)
            self.o = (self.data.open+self.data.close[-1])/2
            self.h = bt.If(self.data.high  > self.data.close(-1),self.data.high, self.data.close(-1))
            self.l = bt.If(self.data.low  < self.data.close(-1),self.data.low, self.data.close(-1))
            self.c = (self.o+self.h+self.l+self.data.close)/4
            super(CLaguerreRSI, self).__init__()
    
        def next(self):
            self.l0.insert(0, ((1 - self.gamma.output[0]) * self.c +
                               self.gamma.output[0] * self.l0[0]))
            self.l1.insert(0, (-self.gamma.output[0] * self.l0[0] + self.l0[1] +
                               self.gamma.output[0] * self.l1[0]))
            self.l2.insert(0, (-self.gamma.output[0] * self.l1[0] + self.l1[1] +
                               self.gamma.output[0] * self.l2[0]))
            self.l3.insert(0, (-self.gamma.output[0] * self.l2[0] + self.l2[1] +
                               self.gamma.output[0] * self.l3[0]))
            del self.l0[2:]
            del self.l1[2:]
            del self.l2[2:]
            del self.l3[2:]
            cd = 0
            cu = 0
            if self.l0[0] >= self.l1[0]:
                cu = self.l0[0] - self.l1[0]
            else:
                cd = self.l1[0] - self.l0[0]
    
            if self.l1[0] >= self.l2[0]:
                cu = cu + self.l1[0] - self.l2[0]
            else:
                cd = cd + self.l2[0] - self.l1[0]
    
            if self.l2[0] >= self.l3[0]:
                cu = cu + self.l2[0] - self.l3[0]
            else:
                cd = cd + self.l3[0] - self.l2[0]
            
            aRSI = 0
            if cu+cd != 0 and (cu / (cu + cd)) > .9:
                aRSI = 1
            else:
                aRSI = cu / (cu + cd)
                
            #aRSI = cu / (cu + cd)
            #print(cu / (cu + cd))
            self.lines.lrsi[0] = aRSI
    

    I made the original Mobius Laguerre RSI however I wanted to test a version with an adaptive FE. However, when I change the gamma from self.practicegamma.energy[0] to self.gamma.output[0] the self.l0, self.l1 etc lists began to return nan values. I can't figure out why. The only thing I changed from the my working laguerre RSI is the type of gamma values for l0, l2. Both self.practicegamma.energy[0] and self.gamma.output[0] return the proper values so I know that is not the issue. Therefore the issue must be when I insert values into self.l0, self.l1 etc. However, the error only occurs when I change self.practicegamma.energy[0] to self.gamma.output[0]. Majorly confused here.

    Any help is appreciated.


Log in to reply
 

});