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)
    def __init__(self):
        dmi = btind.DirectionalMovementIndex(self.data, period=self.p.period)
        osc = dmi.plusDI - dmi.minusDI
        hh = btind.Highest(osc, period=self.p.sumperiod)
        ll = btind.Lowest(osc, period=self.p.sumperiod)

        self.lines.stoch = btind.SumN(osc - ll, period=self.p.sumperiod) / btind.SumN(hh - ll, period=self.p.sumperiod) * 100
    def __init__(self):
        price = (self.data.close+self.data.high+self.data.low) / 3
        vol_sum = btind.SumN(self.data.volume, period=self.params.sumlength)
        vol_weighted_price = btind.SumN(price*self.data.volume, period=self.params.sumlength)

        self.lines.szo = SentimentZoneOscillator(vol_weighted_price/vol_sum, length=self.params.szolength)
        self.lines.buy = btfunc.Max(self.p.signal_percent/self.params.szolength,0)
        self.lines.sell = btfunc.Min(-self.p.signal_percent/self.params.szolength,0)
Exemple #4
0
    def __init__(self):
        ma = self.p.movav(self.data, period=self.p.avglength)
        over = btind.SumN(self.data > ma, period=self.p.sumlength)
        under = btind.SumN(self.data < ma, period=self.p.sumlength)

        self.lines.momentum = (over - under) / self.p.sumlength
        self.lines.slope = self.lines.momentum(0) - self.lines.momentum(-1)
        self.lines.zero = bt.LineNum(0)
Exemple #5
0
    def __init__(self):

        sma = btind.SimpleMovingAverage(period=self.p.smaperiod)
        sma1 = btind.SimpleMovingAverage(self.data, period=self.params.period1)
        sma2 = btind.SimpleMovingAverage(period=self.params.period2)

        myindicator = sma2 - sma1 + self.datas[0].close

        self.sma = btind.SimpleMovingAverage(period=self.p.period)

        # see the (delay) notation
        self.cmpval = self.data.close(-1) > self.sma

        datasum = btind.SumN(self.data, period=self.p.period1)

        # using operators /
        av = datasum / self.p.period1
        self.line.sma = av

        # cannot use "and" operators, backtrader provides several methods
        close_over_sma = self.data.close > sma
        self.sma_dist_to_high = self.data.high - sma
        sma_dist_small = self.sma_dist_to_high < 3.5

        sell_sig = bt.And(close_over_sma, sma_dist_small)

        high_or_low = bt.If(sma1 > self.data.close, self.data.low,
                            self.data.high)

        self.buysell = btind.CrossOver(self.data.close, sma, plot=True)

        self.order = None
Exemple #6
0
    def __init__(self):
        price = (self.data.close + self.data.high + self.data.low) / 3
        vol_price = btind.SumN(
            price * self.data.volume, period=self.p.sumlength) / btind.SumN(
                self.data.volume + 1, period=self.p.sumlength)
        r2 = price + self.data.high - self.data.low
        s2 = price - self.data.high + self.data.low

        rslope = r2(0) - r2(-1)
        sslope = s2(0) - s2(-1)
        diff = vol_price(0) - vol_price(-1)

        resistance = btind.MovingAverageWilder(rslope, period=self.p.avglength)
        support = btind.MovingAverageWilder(sslope, period=self.p.avglength)
        difference = btind.MovingAverageWilder(diff, period=self.p.avglength)

        self.lines.final = (resistance + support + difference * 5) / 3
        # self.lines.final = difference
        self.lines.zero = bt.LineNum(0)
 def __init__(self):
     ma = btind.MovingAverageSimple(self.data, period=self.p.avglength)
     # self.lines.accum = btind.Accum((self.data - ma) / ma)
     self.lines.accum = btind.SumN((self.data-ma) / ma, period=self.p.sumlength)
     self.lines.slope = self.accum(0) - self.accum(-1)
 def __init__(self):
     price = (self.data.close+self.data.high+self.data.low) / 3
     vol_sum = btind.SumN(self.data.volume, period=self.p.period)
     self.lines.movav = btind.SumN(price*self.data.volume, period=self.p.period) / vol_sum
Exemple #9
0
 def __init__(self):
     vel = self.data(0) - self.data(-1)
     self.lines.vel = btind.SumN(vel / self.p.period, period=self.p.period)