Hello to all i have this code with live data and i try it to add the MACD to buy when the macd > 0 and dont buy when the macd < 0
without includ the macd bot working perfectly, but when i go to add the macd of course bot running but dosnt execute trades. Can someone help me?
THIS IS THE CODE WITHOUT INCLUDE MACD (working)
df = pd.DataFrame()
in_position = False
buyorders,sellorders = [],[]
def on_open(ws):
ws.send(our_msg)
def on_message(ws,message):
global df, in_position, buyorders, orderqty, buyprice#, sellorders
out = json.loads(message)
out = pd.DataFrame({'price':float(out['c'])}, index=[pd.to_datetime(out['E'],unit='ms')])
df = pd.concat([df,out],axis=0)
print(df)
df = df.tail(15)
last_price = df.tail(1).price.values[0]
sma_15 = df.price.rolling(15).mean().tail(1).values[0]
if not in_position and last_price > sma_15:
order = client.create_order(symbol='BTCUSDT',
side='BUY',
type='MARKET',
quoteOrderQty=40)
orderqty = float(order['executedQty'])
buyprice = float(order['fills'][0]['price'])
in_position = True
print(order)
if in_position and (last_price > buyprice * 1.0005 or last_price < buyprice * 0.999):
order = client.create_order(symbol='BTCUSDT',
side='SELL',
type='MARKET',
quantity=orderqty)
in_position = False
print(order)
AND THIS IS MY CODE WITH INCLUDE MACD (dont working):
df = pd.DataFrame()
in_position = False
buyorders,sellorders = [],[]
def on_open(ws):
ws.send(our_msg)
def on_message(ws,message):
global df, in_position, buyorders, orderqty, buyprice#, sellorders
out = json.loads(message)
out = pd.DataFrame({'price':float(out['c'])}, index=[pd.to_datetime(out['E'],unit='ms')])
df = pd.concat([df,out],axis=0)
print(df)
df = df.tail(15)
last_price = df.tail(1).price.values[0]
sma_15 = df.price.rolling(15).mean().tail(1).values[0]
if not in_position and ta.trend.macd_diff(df.Close) > 0 \
and ta.trend.macd_diff(df.Close) < 0 and last_price < sma_15:
order = client.create_order(symbol='BTCUSDT',
side='BUY',
type='MARKET',
quoteOrderQty=40)
orderqty = float(order['executedQty'])
buyprice = float(order['fills'][0]['price'])
in_position = True
print(order)
if in_position and (last_price > buyprice * 1.0005 or last_price < buyprice * 0.999):
order = client.create_order(symbol='BTCUSDT',
side='SELL',
type='MARKET',
quantity=orderqty)
in_position = False
print(order)