def Update(): global pricedata_stadistics global pricedata_stadistics_sup print(str(dt.datetime.now()) + " " + timeframe + " Bar Closed - Running Update Function...") pricedata_stadistics['index'] = pricedata['bidclose'].index pricedata_stadistics['bidclose'] = pricedata['bidclose'].values pricedata_stadistics_sup['index'] = pricedata_sup['bidclose'].index pricedata_stadistics_sup['bidclose'] = pricedata_sup['bidclose'].values # Calculate Indicators iFastSMA = sma(pricedata['bidopen'], fast_sma_periods) iSlowSMA = sma(pricedata['bidclose'], slow_sma_periods) iSlowSMA2 = sma(pricedata_sup['bidopen'], slow_sma_periods2) pricedata_stadistics['emaFast'] = iFastSMA pricedata_stadistics['emaSlow'] = iSlowSMA pricedata_stadistics_sup['emaSlow2'] = iSlowSMA2 # Print Price/Indicators print("Close Price: " + str(pricedata_stadistics['bidclose'][len(pricedata) - 1])) #print("Fast SMA: " + str(iFastSMA[len(iFastSMA) - 1])) #print("Slow SMA Open SUP: " + str(iSlowSMA[len(iSlowSMA) - 1])) #print("Slow SMA Open SUP2: " + str(iSlowSMA2[len(iSlowSMA2) - 1])) # *********************************************************** # * Regresion al precio de cierre las velas ================ # *********************************************************** pricedata_stadistics['x'] = np.arange(len(pricedata_stadistics)) # ************* Calcular la poscion Relativa Y for index, row in pricedata_stadistics.iterrows(): pricedata_stadistics.loc[index, 'y'] = int( '{:.5f}'.format((pricedata_stadistics.loc[index, 'bidclose'])).replace('.', '')) max_value = max(np.array(pricedata_stadistics['y'].values)) min_value = min(np.array(pricedata_stadistics['y'].values)) for index, row in pricedata_stadistics.iterrows(): value = pricedata_stadistics.loc[index, 'y'] - min_value NewPricePosition = ((value * 100) / max_value) * 100 pricedata_stadistics.loc[index, 'y'] = NewPricePosition # *********** Calcular la poscion Relativa X max_value = max(np.array(pricedata_stadistics['x'].values)) min_value = min(np.array(pricedata_stadistics['x'].values)) for index, row in pricedata_stadistics.iterrows(): value = pricedata_stadistics.loc[index, 'x'] - min_value NewPricePosition = ((value * 100) / max_value) pricedata_stadistics.loc[index, 'x'] = NewPricePosition regresionLineal_xx = np.array(pricedata_stadistics['x'].values) regresionLineal_yy = np.array(pricedata_stadistics['y'].values) regresionLineal_bb = regresionlineal2.estimate_b0_b1(regresionLineal_xx, regresionLineal_yy) y_pred_sup = regresionLineal_bb[0] + regresionLineal_bb[1] * regresionLineal_xx pricedata_stadistics['y_pred'] = y_pred_sup # Recreacion del Eje X para Presentacion de la Regresion. # for index, row in pricedata_stadistics.iterrows(): # pricedata_stadistics.loc[index, 'x_pred'] = pricedata_stadistics.loc[0, 'y_pred'] # Calculo de Angulo vx = np.array(pricedata_stadistics['x']) vy = np.array(pricedata_stadistics['y_pred']) x1 = vx[0] y1 = vy[0] x2 = vx[-1] y2 = vy[-1] x = x2 - x1 y = y2 - y1 angle = math.atan2(y, x) * (180.0 / math.pi) angle = round(angle, 2) # angle2 = np.rad2deg(np.arctan2(vy[-1] - vy[0], vx[-1] - vx[0])) print("\nAngulo: " + str(angle)) lv_Tendency = "Lateral" if pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] < \ pricedata_stadistics.iloc[1]['y_pred'] and \ pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] < \ pricedata_stadistics.iloc[1]['y_pred']: lv_Tendency = "Bajista" elif pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] > \ pricedata_stadistics.iloc[1]['y_pred'] and \ pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] > \ pricedata_stadistics.iloc[1]['y_pred']: lv_Tendency = "Alcista" print("\nTendencia Regresion Lineal: " + lv_Tendency) # # TRADING LOGIC # # print("Slow SMA Open SUP: " + str(iSlowSMA[len(iSlowSMA) - 1])) # print("Slow SMA Open SUP2: " + str(iSlowSMA2[len(iSlowSMA2) - 1])) message_text = "" #if crossesOver(iFastSMA, iSlowSMA) and angle >= 1: if crossesOver(iFastSMA, iSlowSMA):# and lv_Tendency == "Alcista": message_text = message_text + "\n BUY SIGNAL!" if countOpenTrades("S") > 0: message_text = message_text + "\n Closing Sell Trade(s)..." exit("S") if countOpenTrades("B") == 0: message_text = message_text + "\n Opening Buy Trade..." enter("B") #if crossesUnder(iFastSMA, iSlowSMA) and angle <= -1: if crossesUnder(iFastSMA, iSlowSMA):# and lv_Tendency == "Bajista": message_text = message_text + "\n SELL SIGNAL!" if countOpenTrades("B") > 0: message_text = message_text + "\n Closing Buy Trade(s)..." exit("B") if countOpenTrades("S") == 0: message_text = message_text + "\n Opening Sell Trade..." enter("S") print(message_text) print(str(dt.datetime.now()) + " " + timeframe + " Update Function Completed.\n") print("\n")
def Update(self): self.logMessages = self.logMessages + "\n" + ( str(dt.datetime.now()) + " " + self.timeframe + " Vela Formada - Analizando - Running Update Function...") self.pricedata_stadistics['index'] = self.pricedata['bidclose'].index self.pricedata_stadistics['bidclose'] = self.pricedata[ 'bidclose'].values self.pricedata_stadistics['bidhigh'] = self.pricedata['bidhigh'].values self.pricedata_stadistics['askclose'] = self.pricedata[ 'askclose'].values self.pricedata_stadistics['askhigh'] = self.pricedata['askhigh'].values self.pricedata_stadistics['asklow'] = self.pricedata['asklow'].values self.pricedata_stadistics['askclose'] = self.pricedata[ 'askclose'].values self.pricedata_stadistics['bidlow'] = self.pricedata['bidlow'].values self.pricedata_stadistics['tickqty'] = self.pricedata['tickqty'].values # Calculate Indicators iFastSMA = sma(self.pricedata['bidclose'], self.fast_sma_periods) iSlowSMA = sma(self.pricedata['bidclose'], self.slow_sma_periods) self.pricedata_stadistics['emaFast'] = iFastSMA self.pricedata_stadistics['emaSlow'] = iSlowSMA # Adds a "n_high" column with max value of previous 14 periods self.pricedata_stadistics['n_high'] = self.pricedata_stadistics[ 'bidhigh'].rolling(self.stoK).max() # Adds an "n_low" column with min value of previous 14 periods self.pricedata_stadistics['n_low'] = self.pricedata_stadistics[ 'bidlow'].rolling(self.stoK).min() # Uses the min/max values to calculate the %k (as a percentage) self.pricedata_stadistics['per_k'] = \ ( (self.pricedata_stadistics['bidclose'] - self.pricedata_stadistics['n_low']) / \ (self.pricedata_stadistics['n_high'] - self.pricedata_stadistics['n_low']) ) * 100 # Uses the %k to calculates a SMA over the past 3 values of %k self.pricedata_stadistics['per_d'] = self.pricedata_stadistics[ 'per_k'].rolling(self.stoD).mean() # data_per_k = per_k(pricedata['bidclose'], stoK) # data_per_d = per_d(pricedata['bidclose'], stoD) data_per_k = self.pricedata_stadistics['per_k'] data_per_d = self.pricedata_stadistics['per_d'] # pricedata_stadistics['per_k'] = data_per_k # pricedata_stadistics['per_d'] = data_per_d # self.pricedata_stadistics.loc[index, 'lower_sto'] = 20 # self.pricedata_stadistics.loc[index, 'upper_sto'] = 80 self.logMessages = self.logMessages + "\n" + ( "STO K " + str(data_per_k[len(data_per_k) - 1])) self.logMessages = self.logMessages + "\n" + ( "STO D " + str(data_per_d[len(data_per_d) - 1])) # Calcular Indicador iRSI = rsi(self.pricedata_stadistics['bidclose'], 15) self.logMessages = self.logMessages + "\n" + ("RSI: " + str(iRSI[len(iRSI) - 1])) for index, row in self.pricedata_stadistics.iterrows(): self.pricedata_stadistics.loc[index, 'lower_sto'] = 20 self.pricedata_stadistics.loc[index, 'upper_sto'] = 80 self.pricedata_stadistics.loc[index, 'macdline0'] = 0.00 self.pricedata_stadistics.loc[index, 'macdsub'] = self.macdsub self.pricedata_stadistics.loc[index, 'macdupper'] = self.macduper # *********************************************************** # * Regresion al precio de cierre las velas ================ # *********************************************************** self.pricedata_stadistics['x'] = np.arange( len(self.pricedata_stadistics)) # ************* Calcular la poscion Relativa Y for index, row in self.pricedata_stadistics.iterrows(): self.pricedata_stadistics.loc[index, 'y'] = int('{:.5f}'.format( (self.pricedata_stadistics.loc[index, 'bidclose'])).replace('.', '')) max_value = max(np.array(self.pricedata_stadistics['y'].values)) min_value = min(np.array(self.pricedata_stadistics['y'].values)) for index, row in self.pricedata_stadistics.iterrows(): value = self.pricedata_stadistics.loc[index, 'y'] - min_value NewPricePosition = ((value * 100) / max_value) * 100 self.pricedata_stadistics.loc[index, 'y'] = NewPricePosition # *********** Calcular la poscion Relativa X max_value = max(np.array(self.pricedata_stadistics['x'].values)) min_value = min(np.array(self.pricedata_stadistics['x'].values)) for index, row in self.pricedata_stadistics.iterrows(): value = self.pricedata_stadistics.loc[index, 'x'] - min_value NewPricePosition = ((value * 100) / max_value) self.pricedata_stadistics.loc[index, 'x'] = NewPricePosition regresionLineal_xx = np.array(self.pricedata_stadistics['x'].values) regresionLineal_yy = np.array(self.pricedata_stadistics['y'].values) regresionLineal_bb = regresionlineal2.estimate_b0_b1( regresionLineal_xx, regresionLineal_yy) y_pred_sup = regresionLineal_bb[ 0] + regresionLineal_bb[1] * regresionLineal_xx self.pricedata_stadistics['y_pred'] = y_pred_sup if self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['y_pred'] < \ self.pricedata_stadistics.iloc[1]['y_pred'] and \ self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['y_pred'] < \ self.pricedata_stadistics.iloc[1]['y_pred']: lv_Tendency = "Bajista" elif self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['y_pred'] > \ self.pricedata_stadistics.iloc[1]['y_pred'] and \ self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['y_pred'] > \ self.pricedata_stadistics.iloc[1]['y_pred']: lv_Tendency = "Alcista" # MACD ######################################################################## exp1 = self.pricedata_stadistics['bidclose'].ewm(span=self.macdFast, adjust=False).mean() exp2 = self.pricedata_stadistics['bidclose'].ewm(span=self.macdSlow, adjust=False).mean() macd = exp1 - exp2 self.pricedata_stadistics[ 'macd'] = self.pricedata_stadistics.index.map(macd) self.pricedata_stadistics['signal'] = pd.DataFrame( self.pricedata_stadistics['macd'].ewm(span=self.macdSmooth, adjust=False).mean()) self.pricedata_stadistics['hist'] = pd.DataFrame( self.pricedata_stadistics['macd'] - self.pricedata_stadistics['signal']) # Imprimir Precio/Indicador # self.logMessages = self.logMessages + "\n" + ("Precio Cierre: " + str(pricedata['bidclose'][len(pricedata) - 1])) # self.logMessages = self.logMessages + "\n" + ("Tendencia Regresion Lineal: " + lv_Tendency) lv_signal = self.pricedata_stadistics.iloc[ len(self.pricedata_stadistics) - 1]['signal'] self.logMessages = self.logMessages + "\n" + ( "MACD Signal: " + str(lv_signal) + " SubValuacion: " + str(self.macdsub) + " SobreValuacion: " + str(self.macduper)) self.logMessages = self.logMessages + "\n" + ("RSI " + str(iRSI[len(iRSI) - 1])) # data_per_d['lower_sto'] # if self.crossesOver(data_per_k, data_per_d) and lv_signal <= self.macdsub and \ # self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['signal'] > \ # self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['macd']: # if self.crossesOver(data_per_k, data_per_d) and lv_signal <= self.macdsub and \ # self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['signal'] > \ # self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['macd']: # if self.crossesOver(data_per_k, data_per_d) and data_per_d[len(data_per_d) - 1] <= 20 and \ # self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['bidclose'] > iFastSMA[ # len(iFastSMA) - 1]: if self.crossesOver(self.pricedata_stadistics['y'], self.pricedata_stadistics['y_pred'] ) and lv_Tendency == "Alcista": self.logMessages = self.logMessages + "\n" + " SEÑAL DE COMPRA ! \n" self.logMessages = self.logMessages + "\n" + (''' __,_, [_|_/ // _// __ (_|) |@@| \ \__ \--/ __ \o__|----| | __ \ }{ /\ )_ / _\_ /\__/\ \__O (__ (--/\--) \__/ _)( )(_ `---''---` ''') self.logMessages = self.logMessages + "\n" + " SEÑAL DE COMPRA !" if self.countOpenTrades("S") > 0: self.logMessages = self.logMessages + "\n" + " Cerrando Ventas Abiertas..." self.exit("S") self.logMessages = self.logMessages + "\n" + " Abrir Operacion de Compra..." if self.countOpenTrades("B") == 0: self.enter("B") # playsound("file_example_MP3_700KB.mp3") self.operacioncompra = True # Verifica el Cruce del SMA para Abajo. if self.crossesUnder(self.pricedata_stadistics['y'], self.pricedata_stadistics['y_pred'] ) and lv_Tendency == "Bajista": # if crossesUnder(pricedata_stadistics['signal'], 0.0004): # if self.crossesUnder(data_per_k, data_per_d) and lv_signal >= self.macduper and \ # self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['signal'] < \ # self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['macd']: # if self.crossesUnder(data_per_k, data_per_d) and data_per_d[len(data_per_d) - 1] >= 80 and \ # self.pricedata_stadistics.iloc[len(self.pricedata_stadistics) - 1]['bidclose'] < iFastSMA[ # len(iFastSMA) - 1]: self.logMessages = self.logMessages + "\n" + " SEÑAL DE VENTA ! \n" self.logMessages = self.logMessages + "\n" + (''' __ _ |@@| / \ \--/ __ ) O|----| | __ / / \ }{ /\ )_ / _\_ )/ /\__/\ \__O (__ |/ (--/\--) \__/ / _)( )(_ `---''---` ''') self.logMessages = self.logMessages + "\n" + " SEÑAL DE VENTA ! " if self.countOpenTrades("B") > 0: self.logMessages = self.logMessages + "\n" + " Cerrando Operacion de Compras..." self.exit("B") self.logMessages = self.logMessages + "\n" + " Abrir Operacion de Venta..." if self.countOpenTrades("S") == 0: self.enter("S") # playsound("file_example_MP3_700KB.mp3") self.operacionventa = True self.logMessages = self.logMessages + "\n" + ( str(dt.datetime.now()) + " " + self.timeframe + "Verificacion " "Realizada.\n")
def Update(): global message_text message_text = message_text + ( '\n' + str(dt.datetime.now()) + " " + timeframe + " Bar Closed - Running Update Function..." + symbol) # ********************************************************************* # ** Estadistica General - Regresion Lineal Simple 1 # ********************************************************************* pricedata_stadistics.iloc[0:0] pricedata_stadistics['bidclose'] = pricedata['bidclose'].values pricedata_stadistics['bidopen'] = pricedata['bidopen'].values pricedata_stadistics['x'] = np.arange(len(pricedata_stadistics)) # ************* Calcular la poscion Relativa Y for index, row in pricedata_stadistics.iterrows(): pricedata_stadistics.loc[index, 'y'] = int( '{:.5f}'.format((pricedata_stadistics.loc[index, 'bidclose'])).replace('.', '')) max_value = max(np.array(pricedata_stadistics['y'].values)) min_value = min(np.array(pricedata_stadistics['y'].values)) for index, row in pricedata_stadistics.iterrows(): value = pricedata_stadistics.loc[index, 'y'] - min_value NewPricePosition = ((value * 100) / max_value) * 100 pricedata_stadistics.loc[index, 'y'] = NewPricePosition # *********** Calcular la poscion Relativa X max_value = max(np.array(pricedata_stadistics['x'].values)) min_value = min(np.array(pricedata_stadistics['x'].values)) for index, row in pricedata_stadistics.iterrows(): value = pricedata_stadistics.loc[index, 'x'] - min_value NewPricePosition = ((value * 100) / max_value) pricedata_stadistics.loc[index, 'x'] = NewPricePosition # *********************************************************** # * EMA'S================ # *********************************************************** iFastSMA = sma(pricedata_stadistics['y'], fast_sma_periods) iSlowSMA = sma(pricedata_stadistics['y'], slow_sma_periods) iTooSlowSMA = sma(pricedata_stadistics['y'], too_slow_sma_periods) pricedata_stadistics['emaFast'] = iFastSMA pricedata_stadistics['emaSlow'] = iSlowSMA pricedata_stadistics['emaTooSlow'] = iTooSlowSMA # *********************************************************** # * Regresion al precio de cierre las velas ================ # *********************************************************** regresionLineal_xx = np.array(pricedata_stadistics['x'].values) regresionLineal_yy = np.array(pricedata_stadistics['y'].values) regresionLineal_bb = regresionlineal2.estimate_b0_b1(regresionLineal_xx, regresionLineal_yy) y_pred_sup = regresionLineal_bb[0] + regresionLineal_bb[1] * regresionLineal_xx pricedata_stadistics['y_pred'] = y_pred_sup # Recreacion del Eje X para Presentacion de la Regresion. for index, row in pricedata_stadistics.iterrows(): pricedata_stadistics.loc[index, 'x_pred'] = pricedata_stadistics.loc[0, 'y_pred'] # Calculo de Angulo vx = np.array(pricedata_stadistics['x']) vy = np.array(pricedata_stadistics['y_pred']) x1 = vx[0] y1 = vy[0] x2 = vx[-1] y2 = vy[-1] x = x2 - x1 y = y2 - y1 angle = math.atan2(y, x) * (180.0 / math.pi) angle = round(angle, 2) # angle2 = np.rad2deg(np.arctan2(vy[-1] - vy[0], vx[-1] - vx[0])) message_text = message_text + "\nAngulo: " + str(angle) # # pricedata_stadistics['y_bidhigh'] = pricedata['bidhigh'].values # pricedata_stadistics['y_bidlow'] = pricedata['bidlow'].values # # ************* Calcular la poscion Relativa Y # for index, row in pricedata_stadistics.iterrows(): # pricedata_stadistics.loc[index, 'y_bidhigh'] = int( # '{:.5f}'.format((pricedata_stadistics.loc[index, 'y_bidhigh'])).replace('.', '')) # pricedata_stadistics.loc[index, 'y_bidlow'] = int( # '{:.5f}'.format((pricedata_stadistics.loc[index, 'y_bidlow'])).replace('.', '')) # # max_value = max(np.array(pricedata_stadistics['y_bidhigh'].values)) # min_value = min(np.array(pricedata_stadistics['y_bidhigh'].values)) # for index, row in pricedata_stadistics.iterrows(): # value = pricedata_stadistics.loc[index, 'y_bidhigh'] - min_value # NewPricePosition = ((value * 100) / max_value) * 100 # pricedata_stadistics.loc[index, 'y_bidhigh'] = NewPricePosition # # max_value = max(np.array(pricedata_stadistics['y_bidlow'].values)) # min_value = min(np.array(pricedata_stadistics['y_bidlow'].values)) # for index, row in pricedata_stadistics.iterrows(): # value = pricedata_stadistics.loc[index, 'y_bidlow'] - min_value # NewPricePosition = ((value * 100) / max_value) * 100 # pricedata_stadistics.loc[index, 'y_bidlow'] = NewPricePosition # # # Regresion al precio mas alto velas ====================== # regresionLineal_xx = np.array(pricedata_stadistics['x'].values) # regresionLineal_yy = np.array(pricedata_stadistics['y_bidhigh'].values) # regresionLineal_bb = regresionlineal2.estimate_b0_b1(regresionLineal_xx, regresionLineal_yy) # # y_pred_sup = regresionLineal_bb[0] + regresionLineal_bb[1] * regresionLineal_xx # pricedata_stadistics['y_pred_bidhigh'] = y_pred_sup # # # Regresion al precio de cierre las velas ====================== # regresionLineal_xx = np.array(pricedata_stadistics['x'].values) # regresionLineal_yy = np.array(pricedata_stadistics['y_bidlow'].values) # regresionLineal_bb = regresionlineal2.estimate_b0_b1(regresionLineal_xx, regresionLineal_yy) # y_pred_sup = regresionLineal_bb[0] + regresionLineal_bb[1] * regresionLineal_xx # pricedata_stadistics['y_pred_bidlow'] = y_pred_sup # # ********************************************************************* # # ** Estadistica General - Regresion Lineal # # ********************************************************************* # pricedata_stadistics_sup.iloc[0:0] # pricedata_stadistics_sup['bidclose'] = pricedata_sup['bidclose'].values # pricedata_stadistics_sup['bidhigh'] = pricedata_sup['bidhigh'].values # pricedata_stadistics_sup['bidlow'] = pricedata_sup['bidlow'].values # pricedata_stadistics_sup['rowid'] = np.arange(len(pricedata_stadistics_sup)) # # # *************BIDHIGH # # ************* Calcular la poscion Relativa Y # for index, row in pricedata_stadistics_sup.iterrows(): # pricedata_stadistics_sup.loc[index, 'Y_bidhigh'] = int( # '{:.5f}'.format((pricedata_stadistics_sup.loc[index, 'bidhigh'])).replace('.', '')) # # max_value = max(np.array(pricedata_stadistics_sup['Y_bidhigh'].values)) # min_value = min(np.array(pricedata_stadistics_sup['Y_bidhigh'].values)) # for index, row in pricedata_stadistics_sup.iterrows(): # value = pricedata_stadistics_sup.loc[index, 'Y_bidhigh'] - min_value # NewPricePosition = (value * 100) / max_value # pricedata_stadistics_sup.loc[index, 'Y_bidhigh'] = NewPricePosition # # # *********** Calcular la poscion Relativa X # max_value = max(np.array(pricedata_stadistics_sup['rowid'].values)) # for index, row in pricedata_stadistics_sup.iterrows(): # value = pricedata_stadistics_sup.loc[index, 'rowid'] # NewPricePosition = (value * 100) / max_value # pricedata_stadistics_sup.loc[index, 'X_bidhigh'] = NewPricePosition # # # Regresion al precio mas Alto de las velas ====================== # regresionLineal_xx_sup = np.array(pricedata_stadistics_sup['X_bidhigh'].values) # regresionLineal_yy_sup = np.array(pricedata_stadistics_sup['Y_bidhigh'].values) # regresionLineal_bb_sup = regresionlineal2.estimate_b0_b1(regresionLineal_xx_sup, regresionLineal_yy_sup) # y_pred_sup = regresionLineal_bb_sup[0] + regresionLineal_bb_sup[1] * regresionLineal_xx_sup # # pricedata_stadistics_sup['y_pred_bidhigh'] = y_pred_sup # pricedata_stadistics_sup['x_pred_bidhigh'] = regresionLineal_xx_sup # # # # # # *************BIDLOW # # ************* Calcular la poscion Relativa Y # for index, row in pricedata_stadistics_sup.iterrows(): # pricedata_stadistics_sup.loc[index, 'Y_bidlow'] = int( # '{:.5f}'.format((pricedata_stadistics_sup.loc[index, 'bidlow'])).replace('.', '')) # # max_value = max(np.array(pricedata_stadistics_sup['Y_bidlow'].values)) # min_value = min(np.array(pricedata_stadistics_sup['Y_bidlow'].values)) # for index, row in pricedata_stadistics_sup.iterrows(): # value = pricedata_stadistics_sup.loc[index, 'Y_bidlow'] - min_value # NewPricePosition = (value * 100) / max_value # pricedata_stadistics_sup.loc[index, 'Y_bidlow'] = NewPricePosition # # # *********** Calcular la poscion Relativa X # max_value = max(np.array(pricedata_stadistics_sup['rowid'].values)) # for index, row in pricedata_stadistics_sup.iterrows(): # value = pricedata_stadistics_sup.loc[index, 'rowid'] # NewPricePosition = (value * 100) / max_value # pricedata_stadistics_sup.loc[index, 'X_bidlow'] = NewPricePosition # # # # # # Regresion al precio mas Alto de las velas ====================== # regresionLineal_xx_sup = np.array(pricedata_stadistics_sup['X_bidlow'].values) # regresionLineal_yy_sup = np.array(pricedata_stadistics_sup['Y_bidhigh'].values) # regresionLineal_bb_sup = regresionlineal2.estimate_b0_b1(regresionLineal_xx_sup, regresionLineal_yy_sup) # y_pred_sup = regresionLineal_bb_sup[0] + regresionLineal_bb_sup[1] * regresionLineal_xx_sup # # pricedata_stadistics_sup['y_pred_bidlow'] = y_pred_sup # pricedata_stadistics_sup['x_pred_bidlow'] = regresionLineal_xx_sup # # # # # # # create circle # c = plt.Circle((x1, y1), radius=10, color='red', alpha=.3) # plt.gca().add_artist(c) # # #plt.text(x1, y1, str(round(angle, 2)) + ' °') # # Regresion al mas bajo de las velas ====================== # regresionLineal_xx_sup = np.array(pricedata_stadistics_sup['rowid'].tail(numberofregresion_sup).values) # regresionLineal_yy_sup = np.array(pricedata_stadistics_sup['bidlow'].tail(numberofregresion_sup).values) # regresionLineal_bb_sup = regresionlineal2.estimate_b0_b1(regresionLineal_xx_sup, regresionLineal_yy_sup) # y_pred_sup = regresionLineal_bb_sup[0] + regresionLineal_bb_sup[1] * regresionLineal_xx_sup # # numberRegx = len(pricedata_stadistics_sup) - numberofregresion_sup # posreg = 0 # for index, row in pricedata_stadistics_sup.iterrows(): # if numberRegx <= pricedata_stadistics_sup.loc[index, 'rowid']: # pricedata_stadistics_sup.loc[index, 'y_pred_bidlow'] = y_pred_sup[posreg] # posreg = posreg + 1 # # # ********************************************************************* # # *** Proyecion de Precios * Se puede Mejorar con Ciclo # # ********************************************************************* # lv_index_1 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['date'] # lv_rowid_1 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['rowid'] # lv_y_pred_askhigh_1 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['y_pred_bidhigh'] # lv_y_pred_asklow_1 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['y_pred_bidlow'] # # lv_index_2 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 2]['date'] # lv_rowid_2 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 2]['rowid'] # lv_y_pred_askhigh_2 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 2]['y_pred_bidhigh'] # lv_y_pred_asklow_2 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 2]['y_pred_bidlow'] # # lv_index_base = lv_index_1 - lv_index_2 # lv_rowid_base = lv_rowid_1 - lv_rowid_2 # lv_y_pred_askhigh_base = lv_y_pred_askhigh_1 - lv_y_pred_askhigh_2 # lv_y_pred_asklow_base = lv_y_pred_asklow_1 - lv_y_pred_asklow_2 # # pricedata_stadistics_proyeccion.iloc[0:0] # for proyect_times in range(2): # pricedata_stadistics_proyeccion.loc[lv_index_1] = pd.Series( # {'rowid': lv_rowid_1, # 'y_pred_bidhigh': lv_y_pred_askhigh_1, # 'y_pred_bidlow': lv_y_pred_asklow_1 # }) # lv_index_1 = lv_index_1 + lv_index_base # lv_rowid_1 = lv_rowid_1 + lv_rowid_base # lv_y_pred_askhigh_1 = lv_y_pred_askhigh_1 + lv_y_pred_askhigh_base # lv_y_pred_asklow_1 = lv_y_pred_asklow_1 + lv_y_pred_asklow_base # # pricedata_stadistics_proyeccion_tenden.iloc[0:0] # for proyect_times in range(3): # pricedata_stadistics_proyeccion_tenden.loc[lv_index_1] = pd.Series( # {'rowid': lv_rowid_1, # 'y_pred_bidhigh': lv_y_pred_askhigh_1, # 'y_pred_bidlow': lv_y_pred_asklow_1 # }) # lv_index_1 = lv_index_1 + lv_index_base # lv_rowid_1 = lv_rowid_1 + lv_rowid_base # lv_y_pred_askhigh_1 = lv_y_pred_askhigh_1 + lv_y_pred_askhigh_base # lv_y_pred_asklow_1 = lv_y_pred_asklow_1 + lv_y_pred_asklow_base # # Calculamos La tendencia con los valores de de la proyection las velas mas altas y mas bajas. lv_Tendency = "Lateral" if pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] < \ pricedata_stadistics.iloc[1]['y_pred'] and \ pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] < \ pricedata_stadistics.iloc[1]['y_pred']: lv_Tendency = "Bajista" elif pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] > \ pricedata_stadistics.iloc[1]['y_pred'] and \ pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] > \ pricedata_stadistics.iloc[1]['y_pred']: lv_Tendency = "Alcista" message_text = message_text + "\nTendencia Regresion Lineal: " + lv_Tendency lv_posicion_venta = False lv_posicion_compra = False if lv_Tendency == "Bajista" and (pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['emaTooSlow'] > pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y']): lv_posicion_venta = True lv_posicion_compra = False elif lv_Tendency == "Alcista" and (pricedata_stadistics.iloc[len(pricedata_stadistics) - 1][ 'emaTooSlow'] < pricedata_stadistics.iloc[len(pricedata_stadistics) - 1][ 'y']): lv_posicion_venta = False lv_posicion_compra = True message_text = message_text + "\nPosicion de Venta: " + str(lv_posicion_venta) + " Posicion de Compra: " + str( lv_posicion_compra) # # Print Price/Indicators # print("Close Price: " + str(pricedata['bidclose'][len(pricedata) - 1])) # # print("Fast SMA: " + str(iFastSMA[len(iFastSMA) - 1])) # # print("Slow SMA: " + str(iSlowSMA[len(iSlowSMA) - 1])) # # # TRADING LOGIC # if crossesOver(iFastSMA, iSlowSMA) and lv_posicion_compra and angle >= angulo_plus: message_text = message_text + "\n BUY SIGNAL!" if countOpenTrades("S") > 0: message_text = message_text + "\n Closing Sell Trade(s)..." exit("S") if countOpenTrades("B") == 0: message_text = message_text + "\n Opening Buy Trade..." enter("B") if crossesUnder(iFastSMA, iSlowSMA) and lv_posicion_venta and angle <= angulo_minus: message_text = message_text + "\n SELL SIGNAL!" if countOpenTrades("B") > 0: message_text = message_text + "\n Closing Buy Trade(s)..." exit("B") if countOpenTrades("S") == 0: message_text = message_text + "\n Opening Sell Trade..." enter("S") message_text = message_text + "\n" + str( dt.datetime.now()) + " " + timeframe + " Update Function Completed.========= \n" print(message_text) message_text = ''
def Update(): print( str(dt.datetime.now()) + " " + timeframe + " Bar Closed - Running Update Function...") # ********************************************************************* # ** Estadistica General - Regresion Lineal Simple 1 # ********************************************************************* pricedata_stadistics['bidclose'] = pricedata['bidclose'].values pricedata_stadistics['bidopen'] = pricedata['bidopen'].values pricedata_stadistics['date'] = pricedata['bidclose'].index # pricedata_stadistics['emaFast'] = pricedata_stadistics['bidclose'].rolling(window=fast_sma_periods).mean() # pricedata_stadistics['emaSlow'] = pricedata_stadistics['bidclose'].rolling(window=slow_sma_periods).mean() # Calculate Indicators iFastSMA = sma(pricedata['bidclose'], fast_sma_periods) iSlowSMA = sma(pricedata['bidclose'], slow_sma_periods) pricedata_stadistics['emaFast'] = iFastSMA pricedata_stadistics['emaSlow'] = iSlowSMA pricedata_stadistics.index = pricedata['bidclose'].index pricedata_stadistics['rowid'] = np.arange(len(pricedata_stadistics)) # ********************************************************************* # ** Estadistica General - Regresion Lineal # ********************************************************************* pricedata_stadistics_sup['bidclose'] = pricedata_sup['bidclose'].values pricedata_stadistics_sup['date'] = pricedata_sup['bidclose'].index pricedata_stadistics_sup['bidhigh'] = pricedata_sup['bidhigh'].values pricedata_stadistics_sup['bidlow'] = pricedata_sup['bidlow'].values pricedata_stadistics_sup.index = pricedata_sup['bidclose'].index pricedata_stadistics_sup['rowid'] = np.arange( len(pricedata_stadistics_sup)) # Regresion al mas Alto de las velas ====================== regresionLineal_xx_sup = np.array( pricedata_stadistics_sup['rowid'].tail(numberofregresion_sup).values) regresionLineal_yy_sup = np.array( pricedata_stadistics_sup['bidhigh'].tail(numberofregresion_sup).values) regresionLineal_bb_sup = regresionlineal2.estimate_b0_b1( regresionLineal_xx_sup, regresionLineal_yy_sup) y_pred_sup = regresionLineal_bb_sup[ 0] + regresionLineal_bb_sup[1] * regresionLineal_xx_sup numberRegx = len(pricedata_stadistics_sup) - numberofregresion_sup posreg = 0 for index, row in pricedata_stadistics_sup.iterrows(): if numberRegx <= pricedata_stadistics_sup.loc[index, 'rowid']: pricedata_stadistics_sup.loc[index, 'y_pred_bidhigh'] = y_pred_sup[posreg] posreg = posreg + 1 # Regresion al mas bajo de las velas ====================== regresionLineal_xx_sup = np.array( pricedata_stadistics_sup['rowid'].tail(numberofregresion_sup).values) regresionLineal_yy_sup = np.array( pricedata_stadistics_sup['bidlow'].tail(numberofregresion_sup).values) regresionLineal_bb_sup = regresionlineal2.estimate_b0_b1( regresionLineal_xx_sup, regresionLineal_yy_sup) y_pred_sup = regresionLineal_bb_sup[ 0] + regresionLineal_bb_sup[1] * regresionLineal_xx_sup numberRegx = len(pricedata_stadistics_sup) - numberofregresion_sup posreg = 0 for index, row in pricedata_stadistics_sup.iterrows(): if numberRegx <= pricedata_stadistics_sup.loc[index, 'rowid']: pricedata_stadistics_sup.loc[index, 'y_pred_bidlow'] = y_pred_sup[posreg] posreg = posreg + 1 # ********************************************************************* # *** Proyecion de Precios * Se puede Mejorar con Ciclo # ********************************************************************* lv_index_1 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['date'] lv_rowid_1 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['rowid'] lv_y_pred_askhigh_1 = pricedata_stadistics_sup.iloc[ len(pricedata_stadistics_sup) - 1]['y_pred_bidhigh'] lv_y_pred_asklow_1 = pricedata_stadistics_sup.iloc[ len(pricedata_stadistics_sup) - 1]['y_pred_bidlow'] lv_index_2 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 2]['date'] lv_rowid_2 = pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 2]['rowid'] lv_y_pred_askhigh_2 = pricedata_stadistics_sup.iloc[ len(pricedata_stadistics_sup) - 2]['y_pred_bidhigh'] lv_y_pred_asklow_2 = pricedata_stadistics_sup.iloc[ len(pricedata_stadistics_sup) - 2]['y_pred_bidlow'] lv_index_base = lv_index_1 - lv_index_2 lv_rowid_base = lv_rowid_1 - lv_rowid_2 lv_y_pred_askhigh_base = lv_y_pred_askhigh_1 - lv_y_pred_askhigh_2 lv_y_pred_asklow_base = lv_y_pred_asklow_1 - lv_y_pred_asklow_2 pricedata_stadistics_proyeccion.loc[lv_index_1] = pd.Series({ 'rowid': lv_rowid_1, 'y_pred_bidhigh': lv_y_pred_askhigh_1, 'y_pred_bidlow': lv_y_pred_asklow_1 }) pricedata_stadistics_proyeccion.loc[lv_index_1 + lv_index_base] = pd.Series({ 'rowid': lv_rowid_1 + lv_rowid_base, 'y_pred_bidhigh': lv_y_pred_askhigh_1 + lv_y_pred_askhigh_base, 'y_pred_bidlow': lv_y_pred_asklow_1 + lv_y_pred_asklow_base }) # Calculamos La tendencia con los valores de de la proyection las velas mas altas y mas bajas. lv_Tendency = "Lateral" if pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['y_pred_bidhigh'] < \ pricedata_stadistics_sup.iloc[1]['y_pred_bidhigh'] and \ pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['y_pred_bidlow'] < \ pricedata_stadistics_sup.iloc[1]['y_pred_bidlow']: lv_Tendency = "Bajista" elif pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['y_pred_bidhigh'] > \ pricedata_stadistics_sup.iloc[1]['y_pred_bidhigh'] and \ pricedata_stadistics_sup.iloc[len(pricedata_stadistics_sup) - 1]['y_pred_bidlow'] > \ pricedata_stadistics_sup.iloc[1]['y_pred_bidlow']: lv_Tendency = "Alcista" print("Tendencia Regresion Lineal: " + lv_Tendency) lv_posicion_venta = False lv_posicion_compra = False if lv_Tendency == "Bajista" and pricedata_stadistics_proyeccion.iloc[ len(pricedata_stadistics_proyeccion) - 1]['y_pred_bidhigh'] < pricedata_stadistics.iloc[ len(pricedata_stadistics) - 1]['bidclose']: lv_posicion_venta = True lv_posicion_compra = False elif lv_Tendency == "Alcista" and pricedata_stadistics_proyeccion.iloc[ len(pricedata_stadistics_proyeccion) - 1]['y_pred_bidlow'] > pricedata_stadistics.iloc[ len(pricedata_stadistics) - 1]['bidclose']: lv_posicion_venta = False lv_posicion_compra = True print("Posicion de Venta: " + str(lv_posicion_venta) + " Posicion de Compra: " + str(lv_posicion_compra)) # Print Price/Indicators print("Close Price: " + str(pricedata['bidclose'][len(pricedata) - 1])) #print("Fast SMA: " + str(iFastSMA[len(iFastSMA) - 1])) #print("Slow SMA: " + str(iSlowSMA[len(iSlowSMA) - 1])) # TRADING LOGIC if crossesOver(iFastSMA, iSlowSMA) and lv_posicion_compra: print(" BUY SIGNAL!") if countOpenTrades("S") > 0: print(" Closing Sell Trade(s)...") exit("S") if countOpenTrades("B") == 0: print(" Opening Buy Trade...") enter("B") if crossesUnder(iFastSMA, iSlowSMA) and lv_posicion_venta: print(" SELL SIGNAL!") if countOpenTrades("B") > 0: print(" Closing Buy Trade(s)...") exit("B") if countOpenTrades("S") == 0: print(" Opening Sell Trade...") enter("S") print( str(dt.datetime.now()) + " " + timeframe + " Update Function Completed.\n") print("\n")
def Update(): global pricedata_stadistics, operacionventa, operacioncompra print(str(dt.datetime.now()) + " " + timeframe + " Vela Formada - Analizando - Running Update Function...") pricedata_stadistics['index'] = pricedata['bidclose'].index pricedata_stadistics['bidclose'] = pricedata['bidclose'].values pricedata_stadistics['bidhigh'] = pricedata['bidhigh'].values pricedata_stadistics['askclose'] = pricedata['askclose'].values pricedata_stadistics['askhigh'] = pricedata['askhigh'].values pricedata_stadistics['asklow'] = pricedata['asklow'].values pricedata_stadistics['askclose'] = pricedata['askclose'].values pricedata_stadistics['bidlow'] = pricedata['bidlow'].values pricedata_stadistics['tickqty'] = pricedata['tickqty'].values # Calculate Indicators iFastSMA = sma(pricedata['bidclose'], fast_sma_periods) iSlowSMA = sma(pricedata['bidclose'], slow_sma_periods) pricedata_stadistics['emaFast'] = iFastSMA pricedata_stadistics['emaSlow'] = iSlowSMA # Adds a "n_high" column with max value of previous 14 periods pricedata_stadistics['n_high'] = pricedata_stadistics['bidhigh'].rolling(stoK).max() # Adds an "n_low" column with min value of previous 14 periods pricedata_stadistics['n_low'] = pricedata_stadistics['bidlow'].rolling(stoK).min() # Uses the min/max values to calculate the %k (as a percentage) pricedata_stadistics['per_k'] = (pricedata_stadistics['bidclose'] - pricedata_stadistics['n_low']) * 100 / ( pricedata_stadistics['n_high'] - pricedata_stadistics['n_low']) # Uses the %k to calculates a SMA over the past 3 values of %k pricedata_stadistics['per_d'] = pricedata_stadistics['per_k'].rolling(stoD).mean() # data_per_k = per_k(pricedata['bidclose'], stoK) # data_per_d = per_d(pricedata['bidclose'], stoD) data_per_k = pricedata_stadistics['per_k'] data_per_d = pricedata_stadistics['per_d'] # pricedata_stadistics['per_k'] = data_per_k # pricedata_stadistics['per_d'] = data_per_d # Calcular Indicador iRSI = rsi(pricedata_stadistics['bidclose'], 15) print("RSI: " + str(iRSI[len(iRSI) - 1])) for index, row in pricedata_stadistics.iterrows(): pricedata_stadistics.loc[index, 'lower_sto'] = 20 pricedata_stadistics.loc[index, 'upper_sto'] = 80 pricedata_stadistics.loc[index, 'macdline0'] = 0.00 # *********************************************************** # * Regresion al precio de cierre las velas ================ # *********************************************************** pricedata_stadistics['x'] = np.arange(len(pricedata_stadistics)) # ************* Calcular la poscion Relativa Y for index, row in pricedata_stadistics.iterrows(): pricedata_stadistics.loc[index, 'y'] = int( '{:.5f}'.format((pricedata_stadistics.loc[index, 'bidclose'])).replace('.', '')) max_value = max(np.array(pricedata_stadistics['y'].values)) min_value = min(np.array(pricedata_stadistics['y'].values)) for index, row in pricedata_stadistics.iterrows(): value = pricedata_stadistics.loc[index, 'y'] - min_value NewPricePosition = ((value * 100) / max_value) * 100 pricedata_stadistics.loc[index, 'y'] = NewPricePosition # *********** Calcular la poscion Relativa X max_value = max(np.array(pricedata_stadistics['x'].values)) min_value = min(np.array(pricedata_stadistics['x'].values)) for index, row in pricedata_stadistics.iterrows(): value = pricedata_stadistics.loc[index, 'x'] - min_value NewPricePosition = ((value * 100) / max_value) pricedata_stadistics.loc[index, 'x'] = NewPricePosition regresionLineal_xx = np.array(pricedata_stadistics['x'].values) regresionLineal_yy = np.array(pricedata_stadistics['y'].values) regresionLineal_bb = regresionlineal2.estimate_b0_b1(regresionLineal_xx, regresionLineal_yy) y_pred_sup = regresionLineal_bb[0] + regresionLineal_bb[1] * regresionLineal_xx pricedata_stadistics['y_pred'] = y_pred_sup if pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] < \ pricedata_stadistics.iloc[1]['y_pred'] and \ pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] < \ pricedata_stadistics.iloc[1]['y_pred']: lv_Tendency = "Bajista" elif pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] > \ pricedata_stadistics.iloc[1]['y_pred'] and \ pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['y_pred'] > \ pricedata_stadistics.iloc[1]['y_pred']: lv_Tendency = "Alcista" # MACD ######################################################################## exp1 = pricedata_stadistics['bidclose'].ewm(span=macdFast, adjust=False).mean() exp2 = pricedata_stadistics['bidclose'].ewm(span=macdSlow, adjust=False).mean() macd = exp1 - exp2 pricedata_stadistics['macd'] = pricedata_stadistics.index.map(macd) pricedata_stadistics['signal'] = pd.DataFrame( pricedata_stadistics['macd'].ewm(span=macdSmooth, adjust=False).mean()) pricedata_stadistics['hist'] = pd.DataFrame(pricedata_stadistics['macd'] - pricedata_stadistics['signal']) # Imprimir Precio/Indicador # print("Precio Cierre: " + str(pricedata['bidclose'][len(pricedata) - 1])) # print("Tendencia Regresion Lineal: " + lv_Tendency) lv_signal = pricedata_stadistics.iloc[len(pricedata_stadistics) - 1]['signal'] print("MACD Signal: " + str(lv_signal) + " SubValuacion: " + str(macdsub) + " SobreValuacion: " + str(macduper)) print("STO D" + str(data_per_d[len(data_per_d) - 1])) if iRSI[len(iRSI) - 1] <= 40 and crossesOver(data_per_d, pricedata_stadistics['lower_sto']) and lv_signal <= macdsub: print(" SEÑAL DE COMPRA ! \n") print(''' __,_, [_|_/ // _// __ (_|) |@@| \ \__ \--/ __ \o__|----| | __ \ }{ /\ )_ / _\_ /\__/\ \__O (__ (--/\--) \__/ _)( )(_ `---''---` ''') print(" SEÑAL DE COMPRA ! \n") if countOpenTrades("S") > 0: print(" Cerrando Ventas Abiertas...\n") exit("S") print(" Abrir Operacion de Compra...\n") if countOpenTrades("B") == 0: enter("B") operacioncompra = True # Verifica el Cruce del SMA para Abajo. # if crossesUnder(data_per_d, 0.80): # if crossesUnder(pricedata_stadistics['signal'], 0.0004): if iRSI[len(iRSI) - 1] >= 60 and crossesUnder(data_per_d, pricedata_stadistics['upper_sto']) and lv_signal >= macduper: print(" SEÑAL DE VENTA ! \n") print(''' __ _ |@@| / \ \--/ __ ) O|----| | __ / / \ }{ /\ )_ / _\_ )/ /\__/\ \__O (__ |/ (--/\--) \__/ / _)( )(_ `---''---` ''') print(" SEÑAL DE VENTA ! \n") if countOpenTrades("B") > 0: print(" Cerrando Operacion de Compras...\n") exit("B") print(" Abrir Operacion de Venta...\n") if countOpenTrades("S") == 0: enter("S") operacionventa = True # Cerrar Ventas ######################################### if operacionventa and crossesOver(data_per_d, pricedata_stadistics['lower_sto']): if countOpenTrades("S") > 0: print(" Cerrando Ventas Abiertas...\n") operacionventa = False exit("S") # Cerrar Compras ######################################### if operacioncompra and crossesUnder(data_per_d, pricedata_stadistics['upper_sto']): if countOpenTrades("B") > 0: print(" Cerrando Compras Abiertas...\n") operacioncompra = False exit("B") print(str(dt.datetime.now()) + " " + timeframe + " Verificacion Realizada.\n")