def __init__(self): self.ichi = bt.indicators.Ichimoku(self.datas[0], tenkan=self.params.tenkan, kijun=self.params.kijun, senkou=self.params.senkou, senkou_lead=self.params.senkou_lead, chikou=self.params.chikou) # Cross of tenkan and kijun - #1.0 if the 1st data crosses the 2nd data upwards - long #-1.0 if the 1st data crosses the 2nd data downwards - short self.tkcross = bt.indicators.CrossOver(self.ichi.tenkan_sen, self.ichi.kijun_sen) if len(self.data.close) > 0 and len( self.ichi.sencou_span_a) > 0 and len( self.ichi.senkou_span_b) > 0: self.long = bt.And( (self.data.close[0] > self.ichi.senkou_span_a[0]), (self.data.close[0] > self.ichi.senkou_span_b[0]), (self.tkcross == 1)) self.short = bt.And( (self.data.close[0] < self.ichi.senkou_span_a[0]), (self.data.close[0] < self.ichi.senkou_span_b[0]), (self.tkcross == -1)) else: self.long = (self.tkcross == 1) self.short = (self.tkcross == -1)
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 long_sma = bt.indicators.SimpleMovingAverage( self.datas[0], period=self.params.long_period) short_sma = bt.indicators.SimpleMovingAverage( self.datas[0], period=self.params.short_period) # self.cross_up_value = CrossOverValue(self.short_sma, self.long_sma) self.maturn = MATurn(short_sma, long_sma) # 전날 종가가 파란점 아래면 1.0 self.below_maturn_before = self.data.close(-1) < self.maturn.lines.maturn(-1) # 오늘 파란점의 값이 바뀌었고, 저가가 파란점 위면 1.0 self.above_maturn_now = bt.And(self.data.low > self.maturn.lines.maturn, self.maturn.lines.maturn(-1) != self.maturn.lines.maturn) # 이게 1.0이면 이제 매수 타이밍 잡아야 함을 의미함 self.pre_buy_signal = bt.And(self.below_maturn_before, self.above_maturn_now) self.pre_buy_signal_maturn = 0 self.barup_cnt = 0
def __init__(self): self.sma1 = bt.ind.SMA(period=5) # fast moving average self.sma2 = bt.ind.SMA(period=10) # slow moving average self.sma3 = bt.ind.SMA(period=20) # slow moving average # self.sma4 = bt.ind.SMA(period=30) # slow moving average self.sma_cdl1 = bt.ind.CrossDown(self.sma1, self.sma2, plotname='sma_crossdown_level1') self.long_head0 = self.datas[0].close > self.sma1 self.long_head1 = self.sma1 > self.sma2 self.long_head2 = self.sma2 > self.sma3 self.long_headl1 = bt.And(self.long_head0, self.long_head1) self.long_headl2 = bt.And(self.long_head0, self.long_head1, self.long_head2) bt.LinePlotterIndicator(self.long_headl2, name='long_head_level2') self.obv = bt.talib.OBV(self.datas[0].close, self.datas[0].volume) self.obv5 = bt.ind.SMA(self.obv, period=5) self.obv10 = bt.ind.SMA(self.obv, period=10) self.obv_cul1 = bt.ind.CrossOver(self.obv5, self.obv10, plotname='obv_crossup_level1') self.mom1 = self.datas[0].close > self.datas[0].close(-1) self.mom2 = self.datas[0].close(-1) > self.datas[0].close(-2) self.mom3 = self.datas[0].close(-2) > self.datas[0].close(-3) # self.mom4= self.datas[0].close (-3) > self.datas[0].close (-4) # self.mom5= self.sma1(-4) > self.sma1(-5) self.moml1 = bt.And(self.mom1, self.mom2, self.mom3)
def __init__(self): super().__init__() self.broker.set_coc(True) self.dataclose={} self.dataopen={} self.datalow={} self.datahigh={} self.volume={} self.order={} self.trade_sig={} self.signal1={} self.signal2={} self.signal3={} self.close_sig={} self.w_portfolio=w_portfolio self.w_close=[0]*num self.option_ratio=option_ratio[opt] self.sma5 = bt.indicators.SMA(self.data, period=5) self.sma10 = bt.indicators.SMA(self.data, period=10) self.sma20 = bt.indicators.SMA(self.data, period=20) self.sma30 = bt.indicators.SMA(self.data, period=30) self.sma60 = bt.indicators.SMA(self.data, period=60) vix=Vix() vixRatio10=VixRatio10() crossOver=bt.Or(bt.And(self.sma5/self.sma10<1,self.sma20/self.sma60<1,\ vixRatio10<=vixRatio10_buy[opt]),\ bt.And(self.sma5/self.sma10<1,self.sma20/self.sma60<1,\ vix<=self.p.vix_upBound)) crossDown=bt.Or(vixRatio10>=self.p.vixRatio10_sell,\ self.sma5/self.sma10>self.p.smaRatio_sell) if opt6: percent=Percentile() cover_call=percent<=0.2 protect_put=percent>=0.8 collar=bt.And(percent<0.8,percent>0.2) # Keep a reference to the "close" line in the data dataseries for i,data in enumerate(self.datas): self.dataclose[i] = self.datas[i].close self.dataopen[i]=self.datas[i].open self.datalow[i]=self.datas[i].low self.datahigh[i]=self.datas[i].high self.volume[i]=abs(self.datas[i].volume) # To keep track of pending orders and buy price/commission self.order[i] = None self.buyprice = None self.buycomm = None self.bar_executed=None self.trade_sig[i]=crossOver self.close_sig[i]=crossDown if opt6: self.signal1[i]=cover_call self.signal2[i]=protect_put self.signal3[i]=collar
def __init__(self): sma1 = btind.SimpleMovingAverage(self.data) ema1 = btind.ExponentialMovingAverage(self.data) close_over_sma = self.data.close > sma1 close_over_ema = self.data.close > ema1 sma_ema_diff = sma1 - ema1 self.buy_sig = bt.And(close_over_sma, close_over_ema, sma_ema_diff > 0) close_under_sma = self.data.close < sma1 close_under_ema = self.data.close < ema1 self.sell_sig = bt.And(close_under_ema, close_under_sma, (sma1 - ema1) < 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): self.sma5 = btind.SimpleMovingAverage(period=5) # 5日均线 self.sma10 = btind.SimpleMovingAverage(period=10) # 10日均线 # bt.And 中所有条件都满足时返回 1;有一个条件不满足就返回 0 self.And = bt.And(self.data > self.sma5, self.data > self.sma10, self.sma5 > self.sma10) # bt.Or 中有一个条件满足时就返回 1;所有条件都不满足时返回 0 self.Or = bt.Or(self.data > self.sma5, self.data > self.sma10, self.sma5 > self.sma10) # bt.If(a, b, c) 如果满足条件 a,就返回 b,否则返回 c self.If = bt.If(self.data > self.sma5, 1000, 5000) # bt.All,同 bt.And self.All = bt.All(self.data > self.sma5, self.data > self.sma10, self.sma5 > self.sma10) # bt.Any,同 bt.Or self.Any = bt.Any(self.data > self.sma5, self.data > self.sma10, self.sma5 > self.sma10) # bt.Max,返回同一时刻所有指标中的最大值 self.Max = bt.Max(self.data, self.sma10, self.sma5) # bt.Min,返回同一时刻所有指标中的最小值 self.Min = bt.Min(self.data, self.sma10, self.sma5) # bt.Sum,对同一时刻所有指标进行求和 self.Sum = bt.Sum(self.data, self.sma10, self.sma5) # bt.Cmp(a,b), 如果 a>b ,返回 1;否则返回 -1 self.Cmp = bt.Cmp(self.data, self.sma5)
def __init__(self): atr = bt.indicators.AverageTrueRange(period=self.p.lookback_period) change = self.data.close - self.data.open body_multiplier = (change / atr) body_up_trig = body_multiplier(-1) > self.p.body_multiplier_min body_dn_trig = body_multiplier(-1) < -self.p.body_multiplier_min body_size = abs(change) / (self.data.high - self.data.low) * 100.0 fits_min = body_size > self.p.body_percent_min fits_max = body_size < self.p.body_percent_max fits = bt.And(fits_min, fits_max) precheck_dn = bt.And(body_up_trig, fits) precheck_up = bt.And(body_dn_trig, fits) r_dn = bt.And(precheck_dn, self.data.close < self.data.close(-1)) r_up = bt.And(precheck_up, self.data.close > self.data.close(-1)) self.lines.fade = bt.If(r_dn, self.data.high, bt.If(r_up, self.data.low, np.NaN))
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): 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): 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 __init__(self): dsma = bt.ind.SMA(self.dnames.days, period=5) dsignal = bt.ind.CrossOver(self.dnames.days, dsma) msma = bt.ind.SMA(self.dnames.minutes, period=10) msignal = bt.ind.CrossOver(msma, self.dnames.minutes) self.osignal = bt.And(msignal, dsignal())
def __init__(self): slowSMA = bt.ind.SMA(period = self.p.p_slow) self.buy_con = bt.And( bt.ind.CrossUp( bt.ind.SMA(period = self.p.p_fast), slowSMA), #slowSMA == bt.ind.Highest(slowSMA, period = self.p.p_high_period, plot = False) ) self.order = None
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): self.dataclose = self.datas[0].close self.order = None self.buyprice = None self.buycomm = None self.sma1 = bt.indicators.SMA(self.datas[0], period=self.params.sma1) self.sma2 = bt.indicators.SMA(self.datas[0], period=self.params.sma2) self.ema = bt.indicators.EMA(self.datas[0], period=self.params.ema) self.buysig = bt.And(self.sma1 > self.sma2, self.sma1 > self.ema)
def __init__(self): cpy = copy.copy(self.data) #Make a copy tmp = bt.If( self.data(0) == self.data(-1), cpy(-1) + 0.000001, self.data(0)) #Peak shift self.lines.zigzag_peak = bt.If( bt.And(tmp(-1) > tmp(-2), tmp(-1) > tmp(0)), self.data(-1), float('nan')) cpy = copy.copy(self.data) tmp = bt.If( self.data(0) == self.data(-1), cpy(-1) - 0.000001, self.data(0)) #Valley shift self.lines.zigzag_valley = bt.If( bt.And(tmp(-1) < tmp(-2), tmp(-1) < tmp(0)), self.data(-1), float('nan')) self.lines.zigzag = bt.If( self.zigzag_peak, self.zigzag_peak, bt.If(self.zigzag_valley, self.zigzag_valley, float('nan')))
def create_indicators(self, name): stochastic = bt.indicators.Stochastic(self.getdatabyname(name)) up = bt.indicators.UpMove(self.getdatabyname(name)) upMove = up.upmove > 0 buy = bt.And(bt.indicators.CrossUp(stochastic.percK, stochastic.percD), upMove) return { 'st': stochastic, 'up':up, 'buy': buy, 'sell': bt.indicators.CrossDown(stochastic.percK, stochastic.percD) }
def __init__(self): self.macd = bt.indicators.MACD(period_me1=5, period_me2=8, period_signal=12) self.badf = self.macd.macd > self.data(0) self.macd_buy = bt.And( self.macd.macd(0) > self.macd.macd(-1), self.macd.signal(0) > self.macd.signal(-1), self.macd.macd(0) > self.macd.signal(0))
def __init__(self): wick_range = self.data.high - self.data.low body_high = bt.Max(self.data.close, self.data.open) body_low = bt.Min(self.data.close, self.data.open) body_range = body_high - body_low wick_buy = (body_low - self.data.low) >= ( self.p.wick_multiplier_min * body_range) wick_sell = (self.data.high - body_high) >= ( self.p.wick_multiplier_min * body_range) # be careful, if wick range = 0 then close-low = 0 ; so avoiding divide # by zero list this is correct close_percent = (self.data.close - self.data.low) / bt.If( wick_range == 0.0, 0.1, wick_range) close_buy = (close_percent >= (1 - self.p.close_percent_max)) close_sell = (close_percent <= self.p.close_percent_max) self.lines.wick = bt.If(bt.And(wick_buy, close_buy), self.data.low, bt.If(bt.And(wick_sell, close_sell), self.data.high, np.NaN) )
def __init__(self): self.addminperiod(self.p.period_kc*2) bands = bt.indicators.BollingerBands(self.data, period=self.p.period, devfactor=self.p.mult) self.l.ma = ma = self.p.movav(self.data,period=self.p.period_kc) atr = bt.indicators.ATR(self.data,period=self.p.period_kc) rma = self.p.movav(atr.atr, period=self.p.period_kc) uKC = ma + rma*self.p.mult_kc lKC = ma - rma*self.p.mult_kc bool = bt.And(bands.bot>lKC, bands.top<uKC) self.l.sqz = bt.If(bool,0.0,1.0)
def __init__(self): self.dataclose = self.datas[0].close self.bbands = btind.BollingerBands(period=20, devfactor=2) self.stoch = btind.Stochastic(period=14, period_dfast=3, period_dslow=3) self.orders = list() self.short_signal = bt.And(self.dataclose > self.bbands.top, self.stoch.percK > 80) self.long_signal = bt.And(self.dataclose < self.bbands.bot, self.stoch.percK < 20) self.close_long_signal = self.dataclose >= self.bbands.top self.close_short_signal = self.dataclose <= self.bbands.bot self.loss_perc = 0.025
def __init__(self): self.strat = self._owner # alias for clarity self.smaShort = bt.ind.SMA(self.data, period=self.p.period_short) self.smaMid = bt.ind.SMA(self.data, period=self.p.period_middle) self.smaLong = bt.ind.SMA(self.data, period=self.p.period_long) self.emaShort = bt.ind.EMA(self.data, period=self.p.period_short) self.emaMid = bt.ind.EMA(self.data, period=self.p.period_middle) self.emaLong = bt.ind.EMA(self.data, period=self.p.period_long) self.boll = bt.ind.BollingerBands(self.data) self.bollDiff = self.boll.top - self.boll.bot self.bollSignal = bt.ind.EMA(self.bollDiff, period=self.p.period_short) self.l.BollRange = bt.If(bt.And(self.bollDiff/self.p.boll_range_ThresholdValue > self.bollSignal, self.data > self.boll.mid), 1, 0) self.l.BollRange = bt.If( bt.And(self.bollDiff / self.p.boll_range_ThresholdValue > self.bollSignal, self.data < self.boll.mid), -1, self.l.BollRange) self.bollHisto = self.bollDiff - self.bollSignal jxmj_cs = abs(self.data / self.smaShort - 1)*100 jxmj_sm = abs(self.smaShort / self.smaMid - 1) * 100 jxmj_ml = abs(self.smaMid / self.smaLong - 1) * 100 self.JXMJ = JXMJDayFsumIndicator(bt.Max(jxmj_cs,jxmj_sm,jxmj_ml), period=self.p.period_jxmj).l.JXMJFsum self.l.JXMJ = bt.If( bt.And(self.JXMJ > self.p.jxmj_ThresholdValue, self.smaMid > self.smaLong), 1, 0) self.l.JXMJHoldState = self.data - self.data self.l.JXMJBuySellPoint = self.data - self.data self.lastClosePrice = 0 dfgl_cs = self.data - self.emaShort dfgl_sm = self.emaShort - self.emaMid dfgl_ml = self.emaMid - self.emaLong self.dfgl = bt.ind.PercentRank(abs(dfgl_sm), period=self.p.period_dfgl) self.l.DFGL = bt.If( bt.And(self.dfgl > self.p.dfgl_ThresholdValue, dfgl_sm > 0), 1, 0) self.holdStateLow = 9999 self.holdStateHigh = 0
def __init__(self): dsma = bt.ind.SMA(self.dnames.days, period=5) self.dsignal = dsignal = bt.ind.CrossOver(self.dnames.days, dsma) dsignal.plotinfo.plotname = 'MSignal' msma = bt.ind.SMA(self.dnames.minutes, period=10) self.msignal = msignal = bt.ind.CrossOver(msma, self.dnames.minutes) msignal.plotinfo.plotname = 'DSignal' # mixing signals from 2 timeframes self.osignal = bt.And(msignal, dsignal.lines[0]()) # Plotting it pi = bt.LinePlotterIndicator(self.osignal, name='osignal') pi.plotinfo.plotname = 'OSignal'
def __init__(self): # Let the indicator get enough data self.addminperiod(self.p.period) # Plot horizontal Line self.plotinfo.plotyhlines = [0] # Aliases to avoid long lines c = self.data.close h = self.data.high l = self.data.low v = self.data.volume self.data.ad = bt.If(bt.Or(bt.And(c == h, c == l), h == l), 0, ((2 * c - l - h) / (h - l)) * v) self.lines.money_flow = bt.indicators.SumN(self.data.ad, period=self.p.period) / bt.indicators.SumN( self.data.volume, period=self.p.period)
def __init__(self, **kwargs): # for arg in kwargs.keys(): self.last_date = self.datas[2].datetime.date(-1) self.logy = pd.DataFrame() self.order = None self.kontext = self.datas[:len(self.params.kontext_list)] self.stocks = self.datas[len(self.params.kontext_list) + 1:] for d in self.kontext: d.lines.SMA = bt.talib.SMA(d.close, timeperiod=self.params.kontext_period) d.lines.SMA_comp = d.lines.SMA < d.close for i, d in enumerate(self.kontext): if i == len(self.kontext) - 1: break else: self.konfil = bt.And(self.kontext[i].lines.SMA_comp, self.kontext[i + 1].lines.SMA_comp) for d in self.stocks: d.lines.MoScore = self.Ranking(dat=d) d.lines.SMA = bt.indicators.SimpleMovingAverage( d.close, period=self.params.period_SMA)
def __init__(self, strategy=None): self.log = logging.getLogger(__name__) if strategy is not None and isinstance(strategy, bt.Strategy): self.strategy = strategy else: self.log.error( 'something goes wrong during {} init : pls check parameters') sys.exit(1) self.prev = self.min_max_inter_flag = 0 self.ref_min = self.ref_max = self.lookback = 1 self.c_inter_max = self.c_inter_min = 0 self.test_max = [] self.test_min = [] self.test_ref_max = [] self.test_ref_min = [] # da rimuovere (per ora serve ad attivare prenext()) ... ma come ??? self.down = bt.And( self.data.low(0) < self.data.low(-self.lookback), self.data.high(0) <= self.data.high(-self.lookback))
def __init__(self): self.strat = self._owner # alias for clarity self.smaShort = bt.ind.SMA(self.data, period=self.p.period_short) self.smaMid = bt.ind.SMA(self.data, period=self.p.period_middle) self.smaLong = bt.ind.SMA(self.data, period=self.p.period_long) self.emaShort = bt.ind.EMA(self.data, period=self.p.period_short) self.emaMid = bt.ind.EMA(self.data, period=self.p.period_middle) self.emaLong = bt.ind.EMA(self.data, period=self.p.period_long) self.smaVolumeShort = bt.ind.SMA(self.data.volume, period=self.p.period_volumeShort) self.boll = bt.ind.BollingerBands(self.data) self.bollDiff = self.boll.top - self.boll.bot self.bollSignal = bt.ind.EMA(self.bollDiff, period=self.p.period_short) self.l.BollRange = bt.If( bt.And( self.bollDiff / self.p.boll_range_ThresholdValue > self.bollSignal, self.data > self.boll.mid), 1, 0) self.l.BollRange = bt.If( bt.And( self.bollDiff / self.p.boll_range_ThresholdValue > self.bollSignal, self.data < self.boll.mid), -1, self.l.BollRange) self.bollHisto = self.bollDiff - self.bollSignal self.boll_signal_Pct = self.bollDiff / self.bollSignal self.natr = bt.ind.ATR(self.data, period=self.p.period_short) / self.data self.natrEmaShort = bt.ind.EMA(self.natr) self.natr_ema_Pct = self.natr / self.natrEmaShort smaMin = bt.ind.Min(self.smaShort, self.smaMid, self.smaLong) smaMax = bt.ind.Max(self.smaShort, self.smaMid, self.smaLong) emaMin = bt.ind.Min(self.emaShort, self.emaMid, self.emaLong) emaMax = bt.ind.Max(self.emaShort, self.emaMid, self.emaLong) smaIntense = bt.If( (smaMax - smaMin) < self.data * self.p.jxmj_ThresholdPctLimit, True, False) emaIntense = bt.If( (emaMax - emaMin) < self.data * self.p.jxmj_ThresholdPctLimit, True, False) self.l.priceIntense = bt.And(smaIntense, emaIntense) self.l.bollIntense = JXMJDayFsumIndicator( self.boll_signal_Pct, period=self.p.period_short, func=lambda d: fsum( (x < 1) for x in d) > self.p.period_short * 0.7 or fsum( (x < 1.1) for x in d) > self.p.jxmj_ThresholdValue) self.l.natrIntense = JXMJDayFsumIndicator( self.natr_ema_Pct, period=self.p.period_short, func=lambda d: fsum( (x < 1) for x in d) > self.p.period_short * 0.7 or fsum( (x < 1.1) for x in d) > self.p.jxmj_ThresholdValue) self.l.JXMJ = bt.If( bt.And(self.priceIntense, bt.And(self.bollIntense, self.natrIntense)), 1, 0) self.l.JXMJHoldState = self.data - self.data self.l.JXMJBuySellPoint = self.data - self.data self.lastClosePrice = 0 dfgl_cs = self.data - self.emaShort dfgl_sm = self.emaShort - self.emaMid dfgl_ml = self.emaMid - self.emaLong self.dfgl = bt.ind.PercentRank(abs(dfgl_sm), period=self.p.period_dfgl) self.l.DFGL = bt.If( bt.And(self.dfgl > self.p.dfgl_ThresholdValue, dfgl_sm > 0), 1, 0) self.holdStateLow = 9999 self.holdStateHigh = 0