Пример #1
0
 def __init__(self):
     btind.SMA()
     btind.Stochastic()
     btind.RSI()
     btind.MACD()
     btind.CCI()
     TestInd().plotinfo.plot = False
Пример #2
0
Файл: s.py Проект: expo7/Project
    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
Пример #3
0
 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]))
Пример #4
0
 def __init__(self):
     btind.SMA()
     btind.Stochastic()
     btind.RSI()
     btind.MACD()
     btind.CCI()
     TestInd().plotinfo.plot = False
     sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
     crossover = bt.ind.CrossOver(sma1, sma2)
     self.signal_add(bt.SIGNAL_LONG, crossover)
Пример #5
0
    def __init__(self):
        sma = btind.SMA(subplot=self.params.smasubplot)

        macd = btind.MACD()
        # In SMA we passed plot directly as kwarg, here the plotinfo.plot
        # attribute is changed - same effect
        macd.plotinfo.plot = not self.params.nomacdplot

        # Let's put rsi on stochastic/sma or the other way round
        stoc = btind.Stochastic()
        rsi = btind.RSI()
        if self.params.stocrsi:
            stoc.plotinfo.plotmaster = rsi
            stoc.plotinfo.plotlinelabels = self.p.stocrsilabels
        elif self.params.rsioverstoc:
            rsi.plotinfo.plotmaster = stoc
        elif self.params.rsioversma:
            rsi.plotinfo.plotmaster = sma
Пример #6
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])
Пример #7
0
	def __init__(self):
		
		#Set program start time
		start_time=datetime.now().time()
		print('Program start at {}'.format(start_time))
	
		#print(self.params.sma1, self.p.ema1, self.params.atrperiod) #Proof deep copy worked for params
		
		#initialize counters for prenext/next
		self.nextcounter = 0	
		self.counter = 0
		self.counttostop = 0
		self.datastatus = 0
		self.prenext_done = False
		self.bought = 0
		self.sold = 0
		self.target_long_price = 0
		self.target_short_price = 0
		self.trade_open_counter = 0
		self.trade_close_counter = 0	
		self.trade_total_counter = 0
		self.lost_counter = 0 
		self.won_counter = 0
		
		#Define dictionaries and lists to be accessed from all timeframes
		self.atr_list =[]
		self.inds = dict()
		self.gap_dict=dict()
		self.rnghigh_dict = dict()
		self.rnglow_dict= dict()
		self.longstop_dict = dict()
		self.shortstop_dict = dict()
		self.target_long_dict = dict()
		self.target_short_dict = dict()
		self.size_dict = dict()
		self.inorder_dict = dict()		
		self.sup_dict = dict()
		self.res_dict = dict()
		self.pos_dict = defaultdict(list)
				
		#Create/Instantiate objects to access user input parameters
		modelp = UserInputs.model_params()
		indp = UserInputs.ind_params()
		datalist = UserInputs.datalist('hist')
		ibdatalist = UserInputs.datalist('ib')
		
		#Determine interval for timeframe looping
		if not modelp.get('live_status'):
			data_feed_count = len(self.datas)
			ticker_count = len(datalist)
			self.ticker_interval = int(data_feed_count/ticker_count) #Needs to be an integer
		elif modelp.get('live_status'):   
			data_feed_count = len(self.datas)
			ticker_count = len(ibdatalist)
			self.ticker_interval = int(data_feed_count/ticker_count) #Needs to be an integer
		
		#************************INITITIALIZE INDICATORS*********************************************************
		#Initialize dictionary's
		for x in range(0, len(self.datas), self.ticker_interval):
			
			d = self.datas[x]
			print(d._name)
			
			if not (d._name[:-1]=='VIX' or d._name[:-1]=='TICK-NYSE'):
				#Order dictionaries
				self.target_long_dict[d._name] = dict()
				self.target_short_dict[d._name] = dict()
				self.inorder_dict[d._name] = dict()
				self.target_long_dict[d._name] = 0
				self.target_short_dict[d._name] = 0
				self.inorder_dict[d._name] = False
	
		for i, d in enumerate(self.datas): 	
			if not (d._name[:-1]=='VIX' or d._name[:-1]=='TICK-NYSE'):
				#Sizing dictionary
				self.size_dict[d._name] = dict()
				self.size_dict[d._name] = 0
				
				#For support/resistance dictionaries
				self.sup_dict[d._name] = dict()
				self.res_dict[d._name] = dict()
				self.sup_dict[d._name] = 0
				self.res_dict[d._name] = 10000
				
				#For all indicators
				self.inds[d._name] = dict()

				#Moving Average Indicators - FAST, SLOW, and CROSS
				self.inds[d._name]['sma1'] = btind.SMA(d,
														period=indp.get('sma1'),
														plot=False)
														
				self.inds[d._name]['sma2'] = btind.SMA(d,
														period=indp.get('sma2'),
														plot=True)										
				
				self.inds[d._name]['ema1'] = btind.EMA(d,
														period=indp.get('ema1'),
														plot=False)
															
				self.inds[d._name]['ema2'] = btind.EMA(d,
														period=indp.get('ema2'),
														plot=False)
													
				self.inds[d._name]['ema3'] = btind.EMA(d,
														period=indp.get('ema3'),
														plot=False)
				
				#This will double pre-next 												
				self.inds[d._name]['cross'] = btind.CrossOver(self.inds[d._name]['ema2'],
														self.inds[d._name]['ema3'],
														plot=False)
					
				#RSI
				self.inds[d._name]['rsi']= btind.RSI(d,
													safediv=True,
													plot=True)
							
				#AVERAGE TRUE RANGE INDICATOR
				self.inds[d._name]['atr'] = btind.ATR(d,
												period=indp.get('atrperiod'),
												plot=False)

				#Bollinger Band
				self.inds[d._name]['bollinger'] = btind.BollingerBands(d,
															period=indp.get('bollinger_period'),
															devfactor = indp.get('bollinger_dist'),
															plot=False)
			
				#Stochastics
				self.inds[d._name]['stochastic'] = btind.StochasticFast(d,
															period=indp.get('stoch_per'),
															period_dfast= indp.get('stoch_fast'),
															safediv=True,
															plot=True)
				
				#ADX
				self.inds[d._name]['adx'] = btind.ADX(d,plot=True)
						
				"""											
				#Pivots
				self.inds[d._name]['pivots'] = btind.pivotpoint.PivotPoint(d,
															plot=False)
				"""												
				#Average Volume Indicator
				self.inds[d._name]['avg_volume'] = btind.Average(d.volume,
															period=indp.get('avg_per'),
															plot=False)
				
				#Highest and Lowest Values of Period Indicator
				self.inds[d._name]['highest'] = btind.Highest(d.high,
															period=indp.get('breakout_per'),
															plot=False)
																								
				self.inds[d._name]['lowest'] = btind.Lowest(d.low,
															period=indp.get('breakout_per'),
															plot=False)
				
				#Slope indicators
				self.inds[d._name]['slope']= btind.Slope(d.close,
														period=indp.get('slope_period'),
														plot=False)
														
				self.inds[d._name]['slope_sma1'] = 	btind.Slope(self.inds[d._name]['sma1'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_SMA1')
														
				self.inds[d._name]['slope_of_slope_sma1'] = 	btind.Slope(self.inds[d._name]['slope_sma1'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_of_Slope_SMA1')
														
				self.inds[d._name]['slope_sma_width'] = btind.Slope(self.inds[d._name]['sma1']-self.inds[d._name]['sma2'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_SMA_WIDTH')											
														
				self.inds[d._name]['slope_adx'] = 	btind.Slope(self.inds[d._name]['adx'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_ADX')	
														
				self.inds[d._name]['slope_of_slope_adx'] = 	btind.Slope(self.inds[d._name]['slope_adx'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_of_Slope_ADX')	
														
				self.inds[d._name]['slope_rsi'] = 	btind.Slope(self.inds[d._name]['rsi'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_RSI')
														
				self.inds[d._name]['slope_of_slope_rsi'] = 	btind.Slope(self.inds[d._name]['slope_rsi'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_of_Slope_RSI')									
														
				self.inds[d._name]['slope_ema1'] = 	btind.Slope(self.inds[d._name]['ema1'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_EMA1')
				self.inds[d._name]['slope_ema2'] = 	btind.Slope(self.inds[d._name]['ema2'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_EMA2')
				self.inds[d._name]['slope_ema3'] = 	btind.Slope(self.inds[d._name]['ema3'],
														period=indp.get('slope_period'),
														plot=False,
														plotname = 'Slope_EMA3')
				
				#Plot ADX and Slope on same subplot as stochastic							
				self.inds[d._name]['adx'].plotinfo.plotmaster = self.inds[d._name]['rsi']
Пример #8
0
 def __init__(self):
     super().__init__()
     self.rsi = btind.RSI(self.datas[0], period = self.p.rsi_period)
Пример #9
0
 def __init__(self):
     super().__init__()
     self.rsi = btind.RSI(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