Esempio n. 1
0
    def __init__(self):
        # 交易日志
        self.buysellLog = ""

        # 每日收盘价
        self.dataclose = self.datas[0].close

        # 订单
        self.order = None

        self.buyprice = 0
        self.buycomm = 0
        self.buytime = 0

        #10日、60日均线
        self.SAM10 = btind.MovingAverageSimple(
            self.dataclose(0),
            period=self.params.maperiod1,
            subplot=False,
            plotname=str(self.params.maperiod1) + '日均线')
        self.SAM60 = btind.MovingAverageSimple(
            self.dataclose(0),
            period=self.params.maperiod2,
            subplot=False,
            plotname=str(self.params.maperiod2) + '日均线')
        # 均线交叉
        self.Crossover = btind.CrossOver(self.SAM10,
                                         self.SAM60,
                                         plotname='双均线交叉')
Esempio n. 2
0
 def __init__(self):
     super().__init__()
     self.di = btind.DirectionalMovement(self.datas[0], period = self.p.di_period)
     self.ma1 = btind.MovingAverageSimple(self.datas[0], period = self.p.ma1)
     self.ma2 = btind.MovingAverageSimple(self.datas[0], period=self.p.ma2)
     self.bbands = btind.BollingerBands(self.datas[0], period = self.p.band_period, devfactor = self.p.devfactor)
     self.ma = btind.MovingAverageSimple(self.datas[0], period=self.p.band_period)
     range = btind.TrueRange(self.datas[0])
     self.rangema = btind.MovingAverageSimple(range, period = self.p.band_period)
Esempio n. 3
0
    def __init__(self):
        # Keep a reference to the "close" line in the data[0] dataseries
        self.dataclose = self.datas[0].close

        # To keep track of pending orders
        self.order = None

        smaFast = btind.MovingAverageSimple(period=self.params.STMAperiod)
        smaSlow = btind.MovingAverageSimple(period=self.params.LTMAperiod)

        self.buysig = btind.CrossOver(smaFast, smaSlow)
Esempio n. 4
0
  def __init__(self):
    for d in self.datas:
      d.madiff = ZackOverMA(d, avglength=self.p.avglength, sumlength=self.p.sumlength)
      d.ma = btind.MovingAverageSimple(d, period=self.p.avglength)
      d.maslope = d.ma(0) - d.ma(-1)

    self.logfile = open('log.txt', 'w')
Esempio n. 5
0
    def __init__(self):
        super().__init__()

        self.lag = Laguerre(self.datas[0],
                            short_gamma = self.params.short_gamma,
                            long_gamma=self.params.long_gamma,
                            pctile=self.params.pctile,
                            wrnpctile=self.params.wrnpctile,
                            lkbT=self.params.lkbT,
                            lkbB=self.params.lkbB,
                            )
        self.wvf = Vix_Fix_Indicator(self.datas[0],
                            pd = self.params.pd,
                            bbl=self.params.bbl,
                            mult=self.params.mult,
                            lb=self.params.lb,
                            ph=self.params.ph,
                            pl=self.params.pl,
                                     )

        ap = (self.datas[0].high + self.datas[0].low + self.datas[0].close)/3
        esa = btind.ExponentialMovingAverage(ap, period = self.params.n1)
        d = btind.ExponentialMovingAverage(abs(ap - esa), period = self.params.n1)
        ci = (ap - esa) / (0.015 * d)
        self.tci = btind.ExponentialMovingAverage(ci, period = self.params.n2)

        self.ma1 = btind.ZeroLagExponentialMovingAverage(self.datas[0], period = self.params.ma1)
        self.ma2 = btind.MovingAverageSimple(self.datas[0], period=self.params.ma2)

        self.rsi = btind.RelativeStrengthIndex(self.datas[0], period = self.params.rsi_period)
        self.prank= btind.PercentRank(self.rsi, period = self.params.percent_period) * 100

        self.pendingBuy = False
        self.pendingSell = False
Esempio n. 6
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)
Esempio n. 7
0
    def __init__(self):
        for d in self.datas:
            d.overma = ZackOverMA(d,
                                  avglength=self.p.avglength,
                                  sumlength=self.p.sumlength)
            d.atr = btind.AverageTrueRange(d, period=self.p.atrperiod)
            d.atrp = d.atr / d  # atr as a % of stock price
            d.ma = btind.MovingAverageSimple(d, period=self.p.avglength)
            d.maslope = d.ma(0) - d.ma(-1)
            d.avgvolume = btind.MovingAverageSimple(d.volume,
                                                    period=self.p.avglength)
            d.pivot = ZackPivotPoints(d,
                                      avglength=self.p.pivotavglength,
                                      sumlength=self.p.pivotsumlength)
            d.pivot2 = ZPP(d, avglength=9)

            if self.p.log:
                self.logfile = open('overma.txt', 'w')
Esempio n. 8
0
    def __init__(self):
        super().__init__()
        self.ma = btind.MovingAverageSimple(self.datas[0], period = self.params.ma)
        self.ma1 = btind.MovingAverageSimple(self.datas[0], period = self.params.ma1)
        self.ma2 = btind.MovingAverageSimple(self.datas[0], period = self.params.ma2)
        self.atr = btind.AverageTrueRange(self.datas[0])

        self.kst = btind.KnowSureThing(self.datas[0])

        self.macd = btind.MACD(self.datas[0])

        self.trix = btind.TrixSignal(self.datas[0])

        self.ao = btind.AwesomeOscillator(self.datas[0])

        self.tsi = btind.TrueStrengthIndicator(self.datas[0])

        self.psar = btind.ParabolicSAR(self.datas[0])

        self.adx = btind.AverageDirectionalMovementIndex(self.datas[0])

        self.dpo = btind.DetrendedPriceOscillator(self.datas[0])

        self.rsi = btind.RSI(self.datas[0])

        self.accdec = btind.AccelerationDecelerationOscillator(self.datas[0])

        self.bbands = btind.BollingerBands(self.datas[0])

        self.cci = btind.CommodityChannelIndex(self.datas[0])

        self.pgood = btind.PrettyGoodOscillator(self.datas[0])

        self.williamsr = btind.WilliamsR(self.datas[0])

        self.uo = btind.UltimateOscillator(self.datas[0])

        self.stoch = btind.Stochastic(self.datas[0])
Esempio n. 9
0
    def __init__(self):
        for d in self.datas:
            d.pivotpoints = ZackPivotPoints(d,
                                            avglength=self.p.avglength,
                                            sumlength=self.p.sumlength)
            d.sma = btind.MovingAverageSimple(d, period=self.p.malength)
            d.smaslope = d.sma(0) - d.sma(-1)
            d.atr = btind.AverageTrueRange(d, period=self.p.atrlength)
            d.quality = AboveMAAccum(d,
                                     avglength=self.p.qualityavglength,
                                     sumlength=self.p.qualitysumlength)

        if self.p.log:
            self.logfile = open('pivotpoints.txt', 'w')
Esempio n. 10
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)
Esempio n. 11
0
 def __init__(self):
     self.l.ha_close = ha_close = (self.data.open + self.data.close + self.data.high + self.data.low) / 4.0
     self.l.ha_open = ha_open = (self.l.ha_open(-1) + ha_close(-1)) / 2.0
     diff = ha_close(0) - ha_open(0)
     self.lines.diff = btind.MovingAverageSimple(diff, period=5)
Esempio n. 12
0
 def __init__(self):
     smoothFactor = btind.MovingAverageSimple(self.data, period=self.p.smoothPeriod)
     dailyReturn = (self.data(0)-self.data(-1)) / smoothFactor
     self.lines.vol = btind.StandardDeviation(dailyReturn, period=self.p.period)
Esempio n. 13
0
 def __init__(self):
     price = btind.MovingAverageSimple(self.data, period=self.p.period)
     roc = 100 * (price(0) / price(-self.p.period)-1)
     maxvol = btind.Highest(self.data.volume, period=self.p.period)
     self.lines.effort = roc / maxvol
Esempio n. 14
0
    def __init__(self):
        ema = btind.ExponentialMovingAverage(self.data, period=self.p.period)
        sma = btind.MovingAverageSimple(self.data, period=self.p.period)

        self.lines.res = (ema*ema-sma*sma) / (self.data)
Esempio n. 15
0
 def __init__(self):
     super().__init__()
     self.ma1 = btind.MovingAverageSimple(self.datas[0], period = self.params.ma1)
     self.ma2 = btind.MovingAverageSimple(self.datas[0], period = self.params.ma2)
     self.rsi = btind.LaguerreRSI(self.datas[0], period = self.params.period, gamma = self.params.gamma)
Esempio n. 16
0
 def __init__(self):
     self.price = (self.data.close + self.data.high + self.data.low) / 3
     self.r2 = btind.MovingAverageSimple(self.price * 2 - self.data.low,
                                         period=self.p.avglength)
     self.s2 = btind.MovingAverageSimple(self.price * 2 - self.data.high,
                                         period=self.p.avglength)
Esempio n. 17
0
 def __init__(self):
     self.mavg200 = btind.MovingAverageSimple(self.data.close, period=200)
     self.mavg50 = btind.MovingAverageSimple(self.data.close, period=50)
     self.crossover = btind.CrossOver(self.mavg50, self.mavg200)
     self.size = 0
     self.order_percentage = 0.5
Esempio n. 18
0
    def __init__(self, store):
        self.buy_order = None
        self.live_data = False

        # Attach and retrieve values from the MT5 indicator "Examples/Custom Moving Average"
        self.mt5cma = getMTraderIndicator(
            # MTraderStorestore instance
            store,
            # Data feed to run the indicator calculations on
            self.datas[0],
            # Set accessor(s) for the indicator output lines
            (
                "cma", ),
            # MT5 inidicator name
            indicator="Examples/Custom Moving Average",
            # Indicator parameters.
            #   Any omitted values will use the defaults as defind by the indicator.
            #   The parameter "params" must exist. If you want to use only the indicator defaults,
            #   pass an empty list: params=[],
            params=[13, 0, "MODE_SMMA"],
        )()

        # Instantiating backtrader indicator Bollinger Bands and Moving Averages
        #   Important: This needs to come before instantiating a chart window
        #   with backtradermql5.mt5indicator.MTraderChart. Otherwise backtrader will fail.
        self.bb = btind.BollingerBands(self.datas[0])
        self.sma = btind.MovingAverageSimple(self.datas[0])

        # -----> Experimental feature BEGIN
        # The feaure to plot data to MT5 chart windows WILL plot false data at this point in time. More work is needed.
        # Plot the backtrader BollingerBand and SMA indicators to a chart window in MT5

        def addChart(chart, bb, sma):
            # Instantiate new indicator and draw to the main window. The parameter idx=0 specifies wether to plot to the
            # main window (idx=0) or a subwindow (idx=1 for the first subwindow, idx=2 for the second etc.).
            indi0 = ChartIndicator(idx=0, shortname="Bollinger Bands")

            # # Add line buffers
            indi0.addline(
                bb.top,
                style={
                    "linelabel": "Top",
                    "color": "clrBlue",
                },
            )
            indi0.addline(
                bb.mid,
                style={
                    "linelabel": "Middle",
                    "color": "clrYellow",
                },
            )
            indi0.addline(
                bb.bot,
                style={
                    "linelabel": "Bottom",
                    "color": "clrGreen",
                },
            )

            # Add the indicator to the chart and draw the line buffers.
            chart.addchartindicator(indi0)

            # # Instantiate second indicator to draw to the first sub-window and add line buffers
            indi1 = ChartIndicator(idx=1, shortname="Simple Moving Average")
            indi1.addline(
                sma.sma,
                style={
                    "linelabel": "SMA",
                    "color": "clrBlue",
                    "linestyle": "STYLE_DASH",
                    "linewidth": 2
                },
            )
            chart.addchartindicator(indi1)

        # Instantiate a new chart window and plot
        chart = MTraderChart(self.datas[0], realtime=False)
        addChart(chart, self.bb, self.sma)
Esempio n. 19
0
 def __init__(self):
     super().__init__(self)
     ma = btind.MovingAverageSimple(self.data.volume * self.datas[0].close , period = self.params.period) / btind.MovingAverageSimple(self.data.volume, period = self.params.period)
     self.lines.vwma = ma
Esempio n. 20
0
 def __init__(self):
     super().__init__()
     self.ma1 = btind.MovingAverageSimple(self.data, period = self.params.ma1)
     self.ma2 = btind.MovingAverageSimple(self.data, period = self.params.ma2)
     self.ma3 = btind.MovingAverageSimple(self.data1, period = self.params.ma3)
     self.ma4 = btind.MovingAverageSimple(self.data1, period = self.params.ma4)
Esempio n. 21
0
 def __init__(self):
     self.sma = btind.MovingAverageSimple(period=8)
Esempio n. 22
0
 def __init__(self):
   for d in self.datas:
     d.slowma = btind.MovingAverageSimple(d, period=self.p.longperiod)
     d.fastma = btind.MovingAverageSimple(d, period=self.p.shortperiod)
Esempio n. 23
0
 def __init__(self):
     super().__init__()
     self.ma1 = btind.MovingAverageSimple(self.datas[0], period = self.params.ma1)
     self.ma2 = btind.MovingAverageSimple(self.datas[0], period = self.params.ma2)
     self.stoch = btind.Stochastic(self.datas[0], period = self.params.period)