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
def __init__(self, pool_list, dataId_to_ticker_d, ticker_to_dataId_d,start_date,end_date, ref_price): # Keep a reference to the "close" line in the data[0] dataseries self.bar_num=0 #self.index_50_date_stock_dict=self.get_index_50_date_stock() self.dataId_to_ticker_dict = dataId_to_ticker_d self.ticker_to_dataId_dict = ticker_to_dataId_d self.position_list = [] self.pool_list = pool_list self.start_date = start_date self.end_date = end_date self.ref_price = ref_price self.newLowDiv = 100 self.newLowIndex = 0 self.csCount = 0 #mk_view_list order [ticker, cs, sm, ml] global mk_view_list mk_view_list = [] mk_view_list.append(pool_list[0]) for x in range(len(conf_mk_view_col)-1): mk_view_list.append(0) for d in self.datas: ## d.baseline = btind.ExponentialMovingAverage(d, period=21) d.ema20 = btind.ExponentialMovingAverage(d, period=20) d.ema60 = btind.ExponentialMovingAverage(d, period=60) d.priceDiv = PriceDiv(d) self.log('stategy Divergence init :' + d._name)
def __init__(self): super().__init__() 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)
def __init__(self): for d in self.datas: d.fastma = btind.ExponentialMovingAverage(d, period=self.p.fastlength) d.slowma = btind.ExponentialMovingAverage(d, period=self.p.slowlength) d.atr = btind.AverageTrueRange(d, period=14) d.atrp = d.atr/d if self.p.log: self.logfile = open('ma_crossover_strat.txt', 'w') if self.p.recordstats: self.statsfile = Statistics()
def __init__(self): for d in self.datas: d.overma = ZackOverMA(d, avglength=15, sumlength=50) d.fastma = btind.ExponentialMovingAverage(d, period=self.p.fastlength) d.slowma = btind.ExponentialMovingAverage(d, period=self.p.slowlength) d.atr = btind.AverageTrueRange(d, period=14) d.rsi = btind.RelativeStrengthIndex(d, period=14) if self.p.log: self.logfile = open('ma_crossover_strat.txt', 'w') if self.p.recordstats: self.statsfile = Statistics()
def __init__(self): self.rsi = btind.RSI(period=self.params.period) # self.macd = btind.MACD() # self.macd = btind.EMA(9) - btind.EMA(14) # self.signal = btind.EMA(14) self.sma = btind.SimpleMovingAverage(period=21) self.ema = btind.ExponentialMovingAverage(period=14) self.accDe = btind.AccDeOsc(period=14) self.close_over_sma = self.data.close > self.sma self.close_over_ema = self.data.close > self.ema self.sma_ema_diff = self.sma - self.ema self.buy_sig = bt.And(self.close_over_sma, self.close_over_ema, self.sma_ema_diff > 0) self.max_pos = 10 self.overSold = self.rsi < 50 self.overBought = self.rsi > 70 self.oscSig = self.accDe > 0 self.buy_price = [] self.sell_price = [] self.buy_price = [] self.sell_price = [] self.ave_buy = 0 self.ave_sell = 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 and buy price/commission self.order = None self.buyprice = None self.buycomm = None # Add a MovingAverageSimple indicator self.ema1 = btind.ExponentialMovingAverage(self.datas[0], period=self.p.pfast) self.ema2 = btind.ExponentialMovingAverage(self.datas[0], period=self.p.pslow) self.crossover = btind.CrossOver(self.ema1, self.ema2) # crossover signal
def __init__(self, pool_list, dataId_to_ticker_d, ticker_to_dataId_d): # Keep a reference to the "close" line in the data[0] dataseries self.bar_num = 0 #self.index_50_date_stock_dict=self.get_index_50_date_stock() self.dataId_to_ticker_dict = dataId_to_ticker_d self.ticker_to_dataId_dict = ticker_to_dataId_d self.position_list = [] self.pool_list = pool_list for d in self.datas: ## d.baseline = btind.ExponentialMovingAverage(d, period=21) ## d.aroon = btind.AroonUpDown(d, period=14) d.emaSig = btind.ExponentialMovingAverage(d, period=20) d.emaBase = btind.ExponentialMovingAverage(d, period=40) d.schaff = SchaffTrend(d) self.log('stategy data init :' + d._name)
def __init__(self, pool_list, dataId_to_ticker_d, ticker_to_dataId_d): # Keep a reference to the "close" line in the data[0] dataseries self.bar_num=0 #self.index_50_date_stock_dict=self.get_index_50_date_stock() self.dataId_to_ticker_dict = dataId_to_ticker_d self.ticker_to_dataId_dict = ticker_to_dataId_d self.position_list = [] self.pool_list = pool_list self.divUnder = 0 #weight of price divergence for d in self.datas: ## d.baseline = btind.ExponentialMovingAverage(d, period=21) d.ema20 = btind.ExponentialMovingAverage(d, period=20) d.ema60 = btind.ExponentialMovingAverage(d, period=60) d.priceDiv = PriceDiv(d) self.log('stategy data init :' + d._name)
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.__fastEMA = btind.ExponentialMovingAverage() self.__slowEMA = btind.ExponentialMovingAverage() self.long_alert = self.data.close > self.__slowEMA self.short_alert = self.data.close < self.__fastEMA self.long_confirmation = self.__fastEMA > self.__slowEMA self.short_confirmation = self.__fastEMA < self.__slowEMA self.long_signal = self.data.close <= self.__fastEMA self.short_signal = self.data.close >= self.__fastEMA self.buy_sig = bt.And(self.long_alert, self.long_confirmation, self.long_signal) self.sell_sig = bt.And(self.short_alert, self.short_confirmation, self.short_signal)
def set_datalines(self): self.indicators = [] period = self.dim_time self.indicators.append( btind.ExponentialMovingAverage(self.datas[0], period=15)) self.indicators.append(btind.MACDHisto(self.datas[0])) self.indicators.append(btind.RSI(self.datas[0], period=15)) self.indicators.append(btind.BollingerBandsPct(self.datas[0]))
def __init__(self): sma1 = btind.SimpleMovingAverage(self.data) ema1 = btind.ExponentialMovingAverage() close_over_sma = self.data.close > sma1 close_over_ema = self.data.close > ema1 sma_ema_diff = sma1 - ema1 buy_sig = bt.And(close_over_sma, close_over_ema, sma_ema_diff > 0)
def __init__(self, pool_list, dataId_to_ticker_d, ticker_to_dataId_d, start_date, end_date): # Keep a reference to the "close" line in the data[0] dataseries self.bar_num = 0 #self.index_50_date_stock_dict=self.get_index_50_date_stock() self.pool_list = pool_list self.dataId_to_ticker_dict = dataId_to_ticker_d self.ticker_to_dataId_dict = ticker_to_dataId_d self.start_date = start_date self.end_date = end_date self.position_list = [ ] #postion order ["sym", "date", "close", "high", "perc", "exit","edate","eperc","strategy"] self.csCount = 0 self.barDiv = 0 self.periodTD9 = 12 self.pastTD9 = [0] * 20 self.downTD9 = 0 self.hasPosition = False self.entryPrice = 100 self.highPrice = 100 self.newLowDiv = 100 self.newLowBar = 0 self.atrTrend = False self.curStrategy = 0 #0:idle 10:divergence 11: div + 20ma turn up div+20ma is what happen after divergence #20:atr global g_entry_list g_entry_list = [] # add indicators for d in self.datas: ## d.baseline = btind.ExponentialMovingAverage(d, period=21) d.ema20 = btind.ExponentialMovingAverage(d, period=20) d.ema60 = btind.ExponentialMovingAverage(d, period=60) d.macd = btind.MACD(d) d.priceDiv = PriceDiv(d) d.data_obv = OnBalanceVolume(d) d.data_obv20 = btind.SMA(d.data_obv, period=20) d.data_atr = AtrTrend(d) #d.data_bb = btind.BollingerBands(d, period=20, devfactor=2.0) #d.data_kc = KeltnerChannel(d, periodEMA = 20, periodATR = 20, devfactor=1.5 ) #d.data_rg = RGChannel(d) self.log('stategy ATR init :' + d._name)
def __init__(self): self.sma1 = btind.SimpleMovingAverage(self.data) self.ema1 = btind.ExponentialMovingAverage() self.close_over_sma = self.data.close > self.sma1 self.close_over_ema = self.data.close > self.ema1 self.sma_ema_diff = self.sma1 - self.ema1 # 生成交易信号 self.buy_sig = bt.And(self.close_over_sma, self.close_over_ema, self.sma_ema_diff > 0)
def __init__(self, pool_list, dataId_to_ticker_d, ticker_to_dataId_d, start_date, end_date): # Keep a reference to the "close" line in the data[0] dataseries self.bar_num = 0 #self.index_50_date_stock_dict=self.get_index_50_date_stock() self.pool_list = pool_list self.dataId_to_ticker_dict = dataId_to_ticker_d self.ticker_to_dataId_dict = ticker_to_dataId_d self.start_date = start_date self.end_date = end_date self.position_list = [ ] #postion order ["sym", "date", "close", "high", "perc", "exit","edate","eperc"] self.csCount = 0 self.hasPosition = False self.entryPrice = 100 self.highPrice = 100 self.newLowDiv = 100 self.newLowBar = 0 global g_entry_list g_entry_list = [] # add indicators for d in self.datas: ## d.baseline = btind.ExponentialMovingAverage(d, period=21) d.ema20 = btind.ExponentialMovingAverage(d, period=20) d.ema60 = btind.ExponentialMovingAverage(d, period=60) d.macd = btind.MACD(d) d.priceDiv = PriceDiv(d) d.data_obv = OnBalanceVolume(d) d.data_obv20 = btind.SMA(d.data_obv, period=20) d.data_bb = btind.BollingerBands(d, period=14, devfactor=2.0) d.data_kc = KeltnerChannel(d, periodEMA=20, periodATR=20, devfactor=1.5) d.data_rg = RGChannel(d) self.log('stategy data init :' + d._name)
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)
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
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)