def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataopen = self.datas[0].open self.datahigh = self.datas[0].high self.datalow = self.datas[0].low self.dataclose = self.datas[0].close self.sma5 = bt.indicators.SMA((self.datahigh + self.datalow) / 2, period=5, plot=False) self.sma25 = bt.indicators.SMA((self.datahigh + self.datalow) / 2, period=20, plot=False) self.smaco = btind.CrossOver(self.sma5, self.sma25) self.direc = bt.indicators.DirectionalMovement(self.datas[0], period=20, plot=False) self.direcco = btind.CrossOver(self.direc.plusDI, self.direc.minusDI, plot=False) self.highest = bt.indicators.Highest(self.datahigh, period=3) self.lowest = bt.indicators.Lowest(self.datalow, period=3) self.ao = bt.indicators.AwesomeOscillator(self.datas[0], fast=12, slow=26) self.aosma9 = bt.indicators.SMA(self.ao, period=9, plot=False) self.aosma12 = bt.indicators.SMA(self.ao, period=9, plot=False) # To keep track of pending orders self.order = None
def __init__(self): # To control operation entries self.orderid = None # Indicators poc = SimpleMovingAverage1(self.data0.POC, period=1, plotname='POC', subplot=False) ppoc = SimpleMovingAverage1(self.data0.PPOC, period=1, plotname='PPOC', subplot=False) #sma80 = btind.SimpleMovingAverage(self.data1.close, period=80, plotname='SMA80') #sma240 = btind.SimpleMovingAverage(self.data1.close, period=240, plotname='SMA240') self.atr = bt.talib.ATR(self.data0.high, self.data0.low, self.data0.close, timeperiod=14) #self.rsi = btind.RSI_EMA(self.data1.close, period=14) #self.macd = btind.MACDHistogram(self.data1.close) #self.ematr = btind.ExponentialMovingAverage(self.atr, period=89) self.signal1 = btind.CrossOver(self.data0.close, poc, plot=False) self.signal2 = btind.CrossOver(self.data0.close, ppoc, plot=False) #self.sma80_slope = Slope(sma80, period=self.p.pslope, plot=False) #self.sma240_slope = Slope(sma240, period=self.p.pslope, plot=False) #self.macd_slope = Slope(self.macd, period=self.p.pslope, plot=False) #self.rsi_slope = Slope(self.rsi, period=self.p.pslope, plot=False) self.flag = True self.flag1 = False self.flag2 = False
def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataopen = self.datas[0].open self.datahigh = self.datas[0].high self.datalow = self.datas[0].low self.dataclose = self.datas[0].close self.highest = bt.indicators.Highest(self.datahigh, period=self.params.period_high) self.lowest = bt.indicators.Lowest(self.datalow, period=self.params.period_low) self.diff = self.highest - self.lowest self.diff236 = self.diff * 0.236 self.diff382 = self.diff * 0.382 self.diff50 = self.diff * 0.50 self.diff618 = self.diff * 0.618 self.diff764 = self.diff * 0.764 self.diff50co = btind.CrossOver(self.dataclose, self.highest - self.diff50) self.diff38co = btind.CrossOver(self.dataclose, self.highest - self.diff382) self.diff61co = btind.CrossOver(self.dataclose, self.highest - self.diff618) self.diff76co = btind.CrossOver(self.dataclose, self.highest - self.diff764) self.rsi = bt.indicators.RSI_EMA(self.dataclose, period=self.params.period_rsi) # To keep track of pending orders self.order = None
def __init__(self): self.dataclose = self.datas[0].close self.order = None #self.macd = bt.indicators.MACD(self.datas[0]) #self.sma05 = btind.SMA(self.datas[0],period = self.params.mapperiod,subplot=False) self.sma20 = btind.SMA(self.datas[0], period=self.params.mapperiod02, subplot=False) self.bbrands = btind.BBands(self.datas[0], subplot=False) self.max20 = bt.talib.MAX(self.datas[0], period=self.params.mapperiod02, plot=False) self.min20 = bt.talib.MIN(self.datas[0], period=self.params.mapperiod02, plot=False) self.atr = btind.ATR(self.datas[0], plot=False) self.signaltop = btind.CrossOver(self.dataclose, self.bbrands.top, plot=False) self.signalcrossover = btind.CrossOver(self.dataclose, self.sma20, plot=False) self.signallow = btind.CrossOver(self.datas[0], self.bbrands.bot) self.signaltop = btind.CrossOver(self.datas[0], self.bbrands.top) self.buyprice = None self.buycomm = None
def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataopen = self.datas[0].open self.datahigh = self.datas[0].high self.datalow = self.datas[0].low self.dataclose = self.datas[0].close self.highest = bt.indicators.Highest(self.datahigh, period=4) self.lowest = bt.indicators.Lowest(self.datalow, period=4) self.diff = self.highest - self.lowest self.diff236 = self.diff * 0.236 self.diff382 = self.diff * 0.382 self.diff50 = self.diff * 0.50 self.diff618 = self.diff * 0.618 self.diff764 = self.diff * 0.764 self.diff50co = btind.CrossOver(self.dataclose, self.highest - self.diff50) self.diff38co = btind.CrossOver(self.dataclose, self.highest - self.diff382) self.diff61co = btind.CrossOver(self.dataclose, self.highest - self.diff618) self.diff76co = btind.CrossOver(self.dataclose, self.highest - self.diff764) self.fpp = bt.indicators.FibonacciPivotPoint(_autoplot=False) # To keep track of pending orders self.order = None
def __init__(self): # To control operation entries self.orderid = None # Indicators poc = btind.SimpleMovingAverage( self.data0.POC, period=1, plotname='POC', subplot=False, ) ppoc = btind.SimpleMovingAverage( self.data0.PPOC, period=1, plotname='PPOC', subplot=False, ) self.atr = bt.talib.ATR(self.data0.high, self.data0.low, self.data0.close, timeperiod=14) #self.rsi = bt.talib.RSI(self.data0.close, timeperiod=14) #self.macd = bt.talib.MACD(self.data0.close) self.ematr = btind.ExponentialMovingAverage(self.atr, period=89) self.signal1 = btind.CrossOver(self.data0.close, poc, plot=False) self.signal2 = btind.CrossOver(self.data0.close, ppoc, plot=False) self.flag = True self.flag1 = False
def __init__(self): self.ma_signal = 0 self.sar_signal = 0 self.MA = self.data1 self.sar = self.data2 self.bb = self.data3 self.ma_cross = btind.CrossOver(self.data, self.MA) self.sar_cross = btind.CrossOver(self.data, self.sar) self.bb_status = self.bb > self.data
def __init__(self): # To control operation entries self.orderid = None self.set_tradehistory(True) # Indicators poc = SimpleMovingAverage1(self.data0.POC, period=1, plotname='POC', subplot=False) ppoc = SimpleMovingAverage1(self.data0.PPOC, period=1, plotname='PPOC', subplot=False) poc3w = SimpleMovingAverage1(self.data0.POC3w, period=1, plotname='POC3w', subplot=False) pocw = SimpleMovingAverage1(self.data0.POCw, period=1, plotname='POCw', subplot=False) sma80 = btind.SimpleMovingAverage(self.data1.close, period=80, plotname='SMA80') sma240 = btind.SimpleMovingAverage(self.data1.close, period=240, plotname='SMA240') self.atr = bt.talib.ATR(self.data0.high, self.data0.low, self.data0.close, timeperiod=14) self.rsi = btind.RSI_EMA(self.data1.close, period=14) self.macd = btind.MACDHistogram(self.data1.close) #self.ematr = btind.ExponentialMovingAverage(self.atr, period=89) self.signal1 = btind.CrossOver(self.data0.close, poc, plot=False) self.signal2 = btind.CrossOver(self.data0.close, ppoc, plot=False) self.sma80_slope = Slope(sma80, period=self.p.pslope, plot=False) self.sma240_slope = Slope(sma240, period=self.p.pslope, plot=False) self.macd_slope = Slope(self.macd, period=self.p.pslope, plot=False) self.rsi_slope = Slope(self.rsi, period=self.p.pslope, plot=False) self.diffPOC = (self.data0.POC - self.data0.PPOC) self.diffPOC3w = (self.data0.POC - self.data0.POC3w) self.diffPOCw = (self.data0.POC - self.data0.POCw) self.diffClPOC = (self.data0.close - self.data0.POC) #self.diffClPPOC = (self.data0.close - self.data0.PPOC) self.diffClPOC3w = (self.data0.close - self.data0.POC3w) self.diffClPPOC3w = (self.data0.close - self.data0.PPOC3w) self.diffClPOCw = (self.data0.close - self.data0.POCw) self.diffClPPOCw = (self.data0.close - self.data0.PPOCw) self.diffSMA = (sma80 - sma240) self.flag = True self.counter = 0 self.nlost = 0
def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataopen = self.datas[0].open self.datahigh = self.datas[0].high self.datalow = self.datas[0].low self.dataclose = self.datas[0].close self.sma5 = bt.indicators.SMA(self.dataclose, period=5, plotname='mysma') self.sma25 = bt.indicators.SMA(self.dataclose, period=20, plotname='mysma') #self.smaco = btind.CrossOver(self.sma5,self.sma25) self.direc = bt.indicators.DirectionalMovement(self.datas[0], period=20, plot=False) self.he = bt.indicators.HurstExponent(self.dataclose, period=20) self.direcco = btind.CrossOver(self.direc.plusDI, self.direc.minusDI, plot=False) self.highest = bt.indicators.Highest(self.datahigh, period=3) self.lowest = bt.indicators.Lowest(self.datalow, period=3) # To keep track of pending orders self.order = None
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='双均线交叉')
def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataopen = self.datas[0].open self.datahigh = self.datas[0].high self.datalow = self.datas[0].low self.dataclose = self.datas[0].close self.sma5 = bt.indicators.SMA((self.datahigh+self.datalow)/2, period=5, plot=False) self.sma25 = bt.indicators.SMA((self.datahigh+self.datalow)/2, period=20, plot=False) self.smaco = btind.CrossOver(self.sma5,self.sma25) self.direc = bt.indicators.DirectionalMovement(self.datas[0],period=20,plot=False) self.direcco = btind.CrossOver(self.direc.plusDI,self.direc.minusDI,plot=False) self.stoc = bt.indicators.StochasticFull() # To keep track of pending orders self.order = None
def __init__(self): self.sma_vel = btind.SMA(period=self.p.Med_vel) self.sma_len = btind.SMA(period=self.p.Med_len) self.buysig = btind.CrossOver(self.sma_vel, self.sma_len) self.dataclose = self.datas[0].close
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
def __init__(self): sma_fast = self.p._movav(period=self.p.fast) sma_slow = self.p._movav(period=self.p.slow) self.dataclose = self.datas[0].close self.order = None self.buysig = btind.CrossOver(sma_fast, sma_slow) self.sellsig = btind.PercentChange() == 5
def __init__(self): self.orderid = None # to control operation entries fast_ema = btind.EMA(period=self.p.fast) slow_ema = btind.EMA(period=self.p.slow) long_ema = btind.EMA(period=self.p.long) self.signal = btind.CrossOver(fast_ema, slow_ema) self.log(f'Initial portfolio value of {self.broker.get_value():.2f}\n')
def __init__(self): # To control operation entries self.orderid = None # Create SMA on 2nd data sma = btind.MovAv.SMA(self.data1, period=self.p.period) # Create a CrossOver Signal from close an moving average self.signal = btind.CrossOver(self.data1.close, sma)
def __init__(self): # SimpleMovingAverage on main data sma = btind.SMA(period=self.p.smaperiod) # CrossOver (1: up, -1: down) close / sma self.crossover = btind.CrossOver(self.data.close, sma, plot=True) # Set to None: new ordersa allowed self.order = None
def __init__(self): # SimpleMovingAverage on main data # Equivalent to -> sma = btind.SMA(self.data, period=self.p.smaperiod) sma = btind.SMA(period=self.p.smaperiod) # CrossOver (1: up, -1: down) close / sma self.buysell = btind.CrossOver(self.data.close, sma, plot=True) # Sentinel to None: new ordersa allowed self.order = None
def __init__(self): count = 0 for d in self.getdatanames(): # self.kma[d] = btind.ExponentialMovingAverage(self.getdatabyname(d), period=10) self.kma[d] = KMA(self.getdatabyname(d)) self.crossover[d] = btind.CrossOver(self.kma[d].kma, self.datas[count].close) self.intersects[d] = 0 count += 1
def __init__(self): sma_fast = self.p._movav(period=self.p.fast) sma_slow = self.p._movav(period=self.p.slow) self.dataclose = self.datas[0].close self.buysig = btind.CrossOver(sma_fast, sma_slow) self.order = None self.buyprice = None self.buycomm = None self.order_number = 0
def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataclose = self.datas[0].close sma_fast = btind.SMA(period=self.p.fast) sma_slow = btind.SMA(period=self.p.slow) self.buysig = btind.CrossOver( sma_fast, sma_slow) #10일과 30일 이동평균의 교차점 찾아줌, -1혹은 1 output print('-----------------------------------------------') print(" This is test strategy ") print('-----------------------------------------------')
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)
def __init__(self): super(CrossOver5, self).__init__() self.entermarkt_desc = '快速均线上穿慢速均线' self.leavemarkt_desc = '入市后n天自动离市' sma_fast = bt.indicators.MovAv.SMA(period=self.p.fast) sma_slow = bt.indicators.MovAv.SMA(period=self.p.slow) self.buysig = btind.CrossOver(sma_fast, sma_slow)
def __init__(self): # To control operation entries self.orderid = None # Create SMA on 2nd data sma = btind.MovAv.SMA(self.data, period=self.p.period) # Create a CrossOver Signal from close an moving average self.signal = btind.CrossOver(self.data.close, sma) self.signal.csv = self.p.csvcross logging.basicConfig(filename='my.log', level=logging.DEBUG)
def __init__(self): #keep a log of where we are in the datafeed self.dataclose = self.datas[0].close #create fast and slow moving averages self.ma_fast = btind.SMA(period=5) self.ma_slow = btind.SMA(period=30) # set values for when the fast ma crosses the slow ma w backtrader's indicator # -1 is bearish, 1 is bullish self.crossover = btind.CrossOver(self.ma_fast, self.ma_slow)
def __init__(self): # 12 hour sma self.sma_12hr = btind.SimpleMovingAverage(period=self.p.pfast) # 30 day sma self.sma_30day = btind.SimpleMovingAverage(period=self.p.pslow) self.gsma = btind.CrossOver(self.sma_12hr, self.sma_30day) # used to determine if order has executed self.order = None # self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma_12hr, sma_30day)) self.dataclose = self.datas[0].close
def __init__(self): super(DonchLongOnly1, self).__init__() # To control operation entries self.order = None self.startcash = self.broker.getvalue() self.accpoints = 0 self.donch = DonchianChannel(self.data, period=self.p.period) self.signal = btind.CrossOver(self.data.close, self.donch.l.bas) self.init_tradeid()
def __init__(self): super(CrossOver4, self).__init__() sma_fast = bt.indicators.MovAv.SMA(period=self.p.fast) sma_slow = bt.indicators.MovAv.SMA(period=self.p.slow) # self.adx = btind.AverageDirectionalMovementIndex(period=18) self.name = 'CrossOver4' # btind.BollingerBands() # btind.AverageDirectionalMovementIndex(period=9) self.buysig = btind.CrossOver(sma_fast, sma_slow)
def __init__(self): super(CrossOver3, self).__init__() self.log('======Crossover3 init=======', isprint=True) sma_fast = bt.indicators.MovAv.SMA(period=self.p.fast) sma_slow = bt.indicators.MovAv.SMA(period=self.p.slow) # self.adx = btind.AverageDirectionalMovementIndex(period=18) # self.adx = btind.AverageDirectionalMovementIndex(period=9) # btind.MACD() # btind.BollingerBands() # btind.AverageDirectionalMovementIndex(period=9) self.buysig = btind.CrossOver(sma_fast, sma_slow)
def __init__(self): # To control operation entries self.orderid = None # Indicators poc = btind.SimpleMovingAverage(self.data0.POC, period=1, plotname='POC') ppoc = btind.SimpleMovingAverage(self.data0.PPOC, period=1, plotname='PPOC') self.atr = bt.talib.ATR(self.data0.high, self.data0.low, self.data0.close, period=14) self.ematr = btind.ExponentialMovingAverage(self.atr, period=89) self.dataclose = self.data0.close self.anchor = 3.0 self.expand = 1.0 self.signal1 = btind.CrossOver(self.dataclose, poc, plotname='POC') self.signal2 = btind.CrossOver(self.dataclose, ppoc, plotname='PPOC') #self.trailing = True self.flag = True