Ejemplo n.º 1
0
    def __init__(self):
        self.dataclose = self.datas[0].close
        self.volume = self.datas[0].volume

        self.order = None
        self.buyprice = None
        self.buycomm = None

        # 9个交易日内最高价
        self.high_nine = bt.indicators.Highest(self.data.high, period=9)
        # 9个交易日内最低价
        self.low_nine = bt.indicators.Lowest(self.data.low, period=9)
        # 计算rsv值
        self.rsv = 100 * bt.DivByZero(self.data_close - self.low_nine,
                                      self.high_nine - self.low_nine,
                                      zero=None)
        # 计算rsv的3周期加权平均值,即K值
        self.K = bt.indicators.EMA(self.rsv, period=3, plot=False)
        # D值=K值的3周期加权平均值
        self.D = bt.indicators.EMA(self.K, period=3, plot=False)
        # J=3*K-2*D
        self.J = 3 * self.K - 2 * self.D

        # MACD策略参数
        me1 = EMA(self.data, period=12)
        me2 = EMA(self.data, period=26)
        self.macd = me1 - me2
        self.signal = EMA(self.macd, period=9)
        bt.indicators.MACDHisto(self.data)
Ejemplo n.º 2
0
    def __init__(self):
        self.fast_EMA = EMA(self.data, period=self.params.fast_LBP)
        self.slow_EMA = EMA(self.data, period=self.params.slow_LBP)

        self.MACD = self.fast_EMA - self.slow_EMA
        self.Signal = EMA(self.MACD, period=self.params.signal_LBP)
        self.Crossing = bt.indicators.CrossOver(self.MACD,
                                                self.Signal,
                                                plotname='Buy_Sell_Line')
        self.Hist = self.MACD - self.Signal
Ejemplo n.º 3
0
    def __init__(self):
        self.dataclose = self.datas[0].close
        self.volume = self.datas[0].volume

        self.order = None
        self.buyprice = None
        self.buycomm = None

        me1 = EMA(self.data, period=12)
        me2 = EMA(self.data, period=26)
        self.macd = me1 - me2
        self.signal = EMA(self.macd, period=9)

        bt.indicators.MACDHisto(self.data)
Ejemplo n.º 4
0
    def __init__(self):
        self.dataclose = self.datas[0].close
        self.datahigh = self.datas[0].high
        self.datalow = self.datas[0].low
        self.dataopen = self.datas[0].open
        self.volume = self.datas[0].volume

        self.order = None
        self.buyprice = None
        self.buycomm = None
        self.params.profits = []

        self.sma20 = bt.indicators.SimpleMovingAverage(self.datas[0], period=20)

        me1 = EMA(self.data, period=12)
        me2 = EMA(self.data, period=26)
        self.macd = me1 - me2
        self.signal = EMA(self.macd, period=9)

        bt.indicators.MACDHisto(self.data)
Ejemplo n.º 5
0
 def next(self):
     hc1 = abs(
         self.data.high.get(self.p.ago, size=self.p.period) -
         self.data.close.get(self.p.ago + 1, size=self.p.period))
     lc1 = abs(
         self.data.low.get(self.p.ago, size=self.p.period) -
         self.data.close.get(self.p.ago + 1, size=self.p.period))
     hl = self.data.high.get(self.p.ago,
                             size=self.p.period) - self.data.low.get(
                                 self.p.ago, size=self.p.period)
     self.lines.atr[0] = EMA(max(hc1, lc1, hl), period=self.p.period)
Ejemplo n.º 6
0
    def __init__(self):
        # Keep references
        self.seconds = self.datas[0]
        self.minutes = self.datas[1]

        # To keep track of pending orders and buy price/commission
        self.order = None
        self.pending_entry_order = False

        # Add a Fractal indicator
        self.fractal = FI.Fractal(
            self.minutes, period=self.p.fractal_period, dolog=self.p.dolog
        )

        # Add a Fractal Momentum indicator
        self.momentum = FI.FractalMomentum(
            self.minutes, period=self.p.fractal_period, plot=True, subplot=True
        )

        # Add EMAs on Fractal Momentum indicator lines
        self.up_momentum_ema_ind = EMA(
            self.momentum.l.up_momentum, period=self.p.fractal_period, plotname='Up Momentum'
        )
        self.up_momentum_ema_ind.plotlines = dict(
            ema=dict(color='green', fillstyle='full', _name='Up Momentum')
        )
    
        self.down_momentum_ema_ind = EMA(
            self.momentum.l.down_momentum, period=self.p.fractal_period, plotname='Down Momentum'
        )
        self.up_momentum_ema_ind.plotlines = dict(
            ema=dict(color='red', fillstyle='full', _name='Down Momentum')
        )

        # Add a CD on the EMA indicators (up - down)
        self.momentum_cd = FI.FractalMomentumCD(
            up=self.up_momentum_ema_ind.l.ema, down=self.down_momentum_ema_ind.l.ema, period=self.p.fractal_period
        )
Ejemplo n.º 7
0
    def __init__(self):
        sma_ind = SMA(self.data.close, period=self.p.maperiod, plot=True)
        ema_ind = EMA(self.data.close, period=self.p.maperiod, plot=True)

        close_over_sma = self.data.close > sma_ind
        # close_over_ema = self.data.close > ema_ind

        close_under_sma = self.data.close < sma_ind
        # close_under_ema = self.data.close < ema_ind

        sma_over_ema = sma_ind > ema_ind
        sma_under_ema = sma_ind < ema_ind

        self.l.buy_sig = bt.And(close_over_sma, sma_over_ema)
        self.l.sell_sig = bt.And(close_under_sma, sma_under_ema)
 def __init__(self):
     me1 = EMA(self.data, period=self.p.period_me1)
     me2 = EMA(self.data, period=self.p.period_me2)
     self.l.macd = me1 - me2
     self.l.signal = EMA(self.l.macd, period=self.p.period_signal)
     self.l.histo = self.l.macd - self.l.signal
 def __init__(self, period=9):
     ema1 = EMA(self.data, period=12)
     ema2 = EMA(self.data, period=26)
     self.l.value = ema1 - ema2
Ejemplo n.º 10
0
 def __init__(self):
     #self.holding = False
     self.dataclose = self.datas[0].close
     self.macd = MACD(first_period=12, second_period=26)
     self.ema = EMA(self.macd, period=self.p.compare_period)
Ejemplo n.º 11
0
 def __init__(self, first_period=12, second_period=26):
     ema1 = EMA(self.data, period=self.p.first_period)
     ema2 = EMA(self.data, period=self.p.second_period)
     self.l.value = ema1 - ema2