Ejemplo n.º 1
0
 def __init__(self):
     price = (self.data.high + self.data.low + self.data.close) / 3
     pricema = self.p.movav(price, period=self.p.period)
     posmf = btind.If(price(0) > price(-1), price*self.data.volume, 0)
     negmf = btind.If(price(0) < price(-1), price*self.data.volume, 0)
     mfi = bt.DivByZero(btind.SumN(posmf, period=self.p.period), btind.SumN(negmf, period=self.p.period))
     self.lines.mfi = 100 - 100 / (1 + mfi)
Ejemplo n.º 2
0
    def __init__(self):
        upday = btind.UpDay(self.data.close)
        downday = btind.DownDay(self.data.close)

        adup = btind.If(upday, self.data.volume, 0.0)
        addown = btind.If(downday, 0 - self.data.volume, 0.0)

        self.lines.obv = btind.Accum(adup + addown)

        super(OnBalanceVolume, self).__init__()
Ejemplo n.º 3
0
    def __init__(self):
        macd = self.p.movav(self.data, period=self.p.fastPeriod) - self.p.movav(self.data, period=self.p.slowPeriod)
        high = btind.Highest(self.data, period=self.p.kPeriod)
        low = btind.Lowest(self.data, period=self.p.kPeriod)
        fastk1= btind.If(high-low > 0, (self.data(0)-low) / (high-low) * 100, 0)
        fastd1 = self.p.movav(fastk1, period=self.p.dPeriod)

        high2 = btind.Highest(fastd1, period=self.p.kPeriod)
        low2 = btind.Lowest(fastd1, period=self.p.kPeriod)
        fastk2 = btind.If(high2-low2 > 0, (fastd1(0)-low2) / (high2-low2) * 100, 0)
        self.lines.trend = self.p.movav(fastk2, period=self.p.dPeriod)
Ejemplo n.º 4
0
 def __init__(self):
     avgvol = btind.ExponentialMovingAverage(self.data.volume,
                                             period=self.p.avgvollength)
     priceUp = btind.If(
         self.data.volume(0) > avgvol(0),
         btind.If(
             self.data(0) > self.data(-1),
             (self.data(0) - self.data(-1)) / self.data(0), 0), 0)
     priceDown = btind.If(
         self.data.volume(0) > avgvol(0),
         btind.If(
             self.data(0) < self.data(-1),
             (self.data(-1) - self.data(0)) / self.data(0), 0), 0)
     self.lines.up = self.p.movav(priceUp, period=self.p.period)
     self.lines.down = self.p.movav(priceDown, period=self.p.period)
Ejemplo n.º 5
0
    def __init__(self):
        diff = self.data.high(0) - self.data.low(0)
        avg = btind.MovingAverageSimple(diff, period=self.p.period)

        self.lines.cv = btind.If(
            avg(-self.p.rocperiod) == 0, 100,
            (avg(0) - avg(-self.p.rocperiod)) / avg(-self.p.rocperiod) * 100)
Ejemplo n.º 6
0
 def __init__(self):
     longRoc = 100 * (self.data(0) / self.data(-self.p.slowPeriod) - 1)
     shortRoc = 100 * (self.data(0) / self.data(-self.p.fastPeriod) - 1)
     Z = btind.DivByZero(
         pow(longRoc(0) * longRoc(0) + 100, 0.5),
         pow(shortRoc(0) * shortRoc(0), 0.5) + self.p.scaleFactor)
     B = btind.If(
         self.data(0) > self.data(-self.p.slowPeriod), 100 * Z(0),
         -100 * Z(0))
     self.lines.pfe = self.p.movav(B, period=self.p.period)
Ejemplo n.º 7
0
    def __init__(self):
        delta = self.data-self.data(-1)
        delta2 = abs(self.data-self.data(-1))

        rma = self.p.movav(delta, period=self.p.rPeriod)
        rma2 = self.p.movav(delta2, period=self.p.rPeriod)
        sma = self.p.movav(rma, period=self.p.sPeriod)
        sma2 = self.p.movav(rma2, period=self.p.sPeriod)
        uma = self.p.movav(sma, period=self.p.uPeriod)
        uma2 = self.p.movav(sma2, period=self.p.uPeriod)

        self.lines.erg = btind.If(uma2 > 0, 100*uma / uma2, 0)
        self.lines.signal = self.p.movav(self.lines.erg, period=self.p.triggerPeriod)
Ejemplo n.º 8
0
    def __init__(self):

        hl2 = (self.data.high + self.data.low) / 2
        #ttr = bt.indicators.TrueRange(self.data)
        #ttr = bt.Max(self.data.high- self.data.low,
        #             bt.Max(abs(self.data.high(0) - self.data.close(-1)),
        #                    abs(self.data.low(0) - self.data.close(-1))))

        #atr2 = RelativeMovingAverage(ttr, period=self.p.ATRPeriod)
        #atr30 = bt.ind.SMA(ttr, period=30)
        #atr20 = bt.ind.SMA(ttr, period=20)
        #atr2 = atr30 - atr20 + bt.ind.SMA(ttr, period=self.p.ATRPeriod)
        #atr2 = bt.ind.EMA(ttr, period=self.p.ATRPeriod)
        atr2 = bt.indicators.AverageTrueRange(self.data,
                                              period=self.p.ATRPeriod)
        upSrc = hl2 - (self.p.Multiplier * atr2)
        #up := close[1] > up1 ? max(up,up1) : up
        self.lines.up = btind.If(
            self.data.close(-1) > upSrc(-1), bt.Max(upSrc, upSrc(-1)), upSrc)

        dnSrc = hl2 + (self.p.Multiplier * atr2)
        #dn := close[1] < dn1 ? min(dn, dn1) : dn
        self.lines.dn = btind.If(
            self.data.close(-1) < dnSrc(-1), bt.Min(dnSrc, dnSrc(-1)), dnSrc)
        """
        trd = self.data.close - self.data.close + 1
        trd2 = btind.If(trd(-1) < 0,
                        btind.If(self.data.close > dn,1,trd2(-1)),
                        btind.If(self.data.close < up, -1, trd2(-1)))
        #trd2 = btind.If((trd(-1) < 0) and (self.data.close(0) > dn(0)),
        #1, btind.If(trd(-1) > 0 and self.data.close(0) < up(0), -1, 0))

        self.lines.trend = trd2
        #btind.If((trd(-1) < 0) and (self.data.close > dn),
        #               1,  btind.If(trd(-1) > 0 and self.data.close < up, -1, 0))
        """
        super(AtrTrend, self).__init__()