@Tradehull_Imran need your help my algo is not placing order getting an error.
sharing with you full code can you please help me on this my algo is not fetch ce data may i know the reason please help me.
traded = “no”
trade_info = {“options_name”:None, “qty”:None, “sl”:None, “CE_PE”:None}
while True:
time.sleep(2)
current_time = datetime.datetime.now()
index_chart = tsl.get_historical_data(tradingsymbol='CRUDEOIL FEB FUT', exchange='MCX', timeframe="5")
# rsi ------------------------ apply indicators
index_chart['rsi'] = talib.RSI(index_chart['close'], timeperiod=14)
# vwap
index_chart.set_index(pd.DatetimeIndex(index_chart['timestamp']), inplace=True)
index_chart['vwap'] = pta.vwap(index_chart['high'] , index_chart['low'], index_chart['close'] , index_chart['volume'])
# Supertrend
indi = ta.supertrend(index_chart['high'], index_chart['low'], index_chart['close'], 10, 2)
index_chart = pd.concat([index_chart, indi], axis=1, join='inner')
# vwma
index_chart['pv'] = index_chart['close'] * index_chart['volume']
index_chart['vwma'] = index_chart['pv'].rolling(20).mean() / index_chart['volume'].rolling(20).mean()
# volume
volume = 50,000
first_candle = index_chart.iloc[-3]
second_candle = index_chart.iloc[-2]
running_candle = index_chart.iloc[-1]
# ---------------------------- BUY ENTRY CONDITIONS ----------------------------
bc1 = first_candle['close'] > first_candle['vwap'] # First Candle close is above VWAP
bc2 = first_candle['close'] > first_candle['SUPERT_10_2.0'] # First Candle close is above Supertrend
bc3 = first_candle['close'] > first_candle['vwma'] # First Candle close is above VWMA
bc4 = first_candle['rsi'] < 80 # First candle RSI < 80
#bc5 = second_candle['volume'] > 50000 # Second candle Volume should be greater than 50,000 for Nifty and above 125,000 for Bank Nifty
print("BUY ", current_time, bc1, bc2, bc3, bc4,)
if bc1 and bc2 and bc3 and bc4:
print("BUY Signal Formed")
ce_name, pe_name, strike = tsl.ATM_Strike_Selection(Underlying ='CRUDEOIL',Expiry ='19-02-2025')
lot_size = tsl.get_lot_size(CE_name)*1
entry_orderid = tsl.order_placement(CE_name,'MCX', lot_size, 0, 0, 'MARKET', 'BUY', 'MIS')
traded = "yes"
trade_info['options_name'] = CE_name
trade_info['qty'] = lot_size
trade_info['sl'] = first_candle['low']
trade_info['CE_PE'] = "CE"
# ---------------------------- check for exit SL/TG
#if traded == "yes":
index_ltp = tsl.get_ltp_data(names = ['CRUDEOIL FEB FUT'])['CRUDEOIL FEB FUT']
long_position = trade_info['CE_PE'] == "CE"
short_position = trade_info['CE_PE'] == "PE"
if long_position:
sl_hit = index_ltp < trade_info['sl']
tg_hit = index_ltp < running_candle['SUPERT_10_2.0']
if sl_hit or tg_hit:
print("Order Exited", trade_info)
exit_orderid = tsl.order_placement(trade_info['options_name'],'NFO', trade_info['qty'], 0, 0, 'MARKET', 'SELL', 'MIS')
pdb.set_trace()
- List item