Sir,
tsl = Tradehull(client_code,token_id) # tradehull_support_library
available_balance = tsl.get_balance()
leveraged_margin = available_balance2
max_trades = 3
per_trade_margin = (leveraged_margin/max_trades)
max_loss = (available_balance1)/100*-1
waitchlist = [“RBLBANK”, “BIOCON”, “INDIGO”, “TATACHEM”, “UBL”, “HINDCOPPER”, “HINDPETRO”, “BATAINDIA”, “GAIL”, “BHARATFORG”, “GRANULES”, “ICICIPRULI”, “SONACOMS”, “TATAMOTORS”, “MGL”, “POONAWALLA”, “IGL”, “PAYTM”, “TVSMOTOR”, “JUBLFOOD”, “AARTIIND”, “ADANIENT”, “OIL”, “HFCL”, “KPITTECH”, “LTF”, “NAVINFLUOR”, “ANGELONE”, “CHOLAFIN”, “GUJGASLTD”, “CROMPTON”, “BSOFT”, “IDFCFIRSTB”, “AUBANK”, “EICHERMOT”, “BANDHANBNK”, “OBEROIRLTY”, “UNITDSPR”, “ATUL”, “NESTLEIND”, “BPCL”, “SYNGENE”, “ITC”, “PVRINOX”, “NYKAA”, “DRREDDY”, “TRENT”, “PIDILITIND”, “MANAPPURAM”, “NTPC”, “BRITANNIA”, “COALINDIA”, “AUROPHARMA”, “TCS”, “SBICARD”, “HAVELLS”, “CYIENT”, “MOTHERSON”, “APOLLOTYRE”, “EXIDEIND”, “CAMS”, “ESCORTS”, “BAJAJ-AUTO”, “PAGEIND”, “LUPIN”, “GODREJCP”, “INDHOTEL”, “CUMMINSIND”, “ICICIGI”, “KOTAKBANK”, “JSL”, “INDIANB”, “AXISBANK”, “M&M”, “TATACONSUM”, “ASIANPAINT”, “ASHOKLEY”, “JINDALSTEL”, “PNB”, “FEDERALBNK”, “OFSS”, “ZOMATO”, “IRCTC”, “ICICIBANK”, “IOC”, “RELIANCE”, “IRFC”, “SUNPHARMA”, “VBL”, “JIOFIN”, “DEEPAKNTR”, “BERGEPAINT”, “BAJAJFINSV”, “CANFINHOME”, “SJVN”, “IDEA”, “ABFRL”, “DABUR”, “PETRONET”, “PEL”, “CUB”, “LICHSGFIN”, “GNFC”, “NHPC”, “CIPLA”, “COLPAL”, “HDFCBANK”, “LTIM”, “HDFCLIFE”, “SHRIRAMFIN”, “ATGL”, “CONCOR”, “TATAPOWER”, “BANKINDIA”, “IPCALAB”, “TATACOMM”, “NAUKRI”, “TECHM”, “ABBOTINDIA”, “DMART”, “LAURUSLABS”, “LT”, “ABCAPITAL”, “SUPREMEIND”, “BOSCHLTD”, “HINDUNILVR”, “BHARTIARTL”, “MFSL”, “NCC”, “MRF”, “PIIND”, “CANBK”, “INDIAMART”, “MAXHEALTH”, “GMRAIRPORT”, “IEX”, “CDSL”, “DLF”, “HEROMOTOCO”, “INDUSTOWER”, “HAL”, “M&MFIN”, “KEI”, “MCX”, “ADANIGREEN”, “KALYANKJIL”, “COFORGE”, “LTTS”, “CESC”, “UNIONBANK”, “TATASTEEL”, “BANKBARODA”, “HCLTECH”, “POLYCAB”, “BEL”, “TORNTPHARM”, “TATAELXSI”, “SRF”, “YESBANK”]
traded_watchlist = # Stocks that have already been traded
Main live trading loop
while True:
live_pnl = tsl.get_live_pnl()
# current_time =datetime.datetime.now() # time and date
current_time_t = datetime.datetime.now().time() #time only
print(current_time_t)
if current_time_t < datetime.time(9, 21, 30):
print (“Wait market to open”, current_time_t)
continue
if current_time_t > datetime.time(15, 15, 30) or(live_pnl <max_loss):
i_want_to_trade_no_more = tsl.kill_switch('ON')
order_details = tsl.cancel_all_orders()
print ("Market is over or MAX LOSS, Bye for Now", current_time_t)
break
print("Algo is working", current_time_t)
# Loop over each stock in the watchlist
for nifty_FnO_stocks in waitchlist:
# print(nifty_FnO_stocks)
# Fetch intraday data for each stock condition for 10min
chart_10 = tsl.get_intraday_data(nifty_FnO_stocks, 'NSE', 10) # Intraday data for 10min
# Calculate the RSI indicator (Relative Strength Index) using talib
chart_10['rsi'] = talib.RSI(chart_10['close'], timeperiod=14) # pandas
# Extract relevant candles for breakout analysis
cc_10 = chart_10.iloc[-1] # Breakout candle (most recent)
# Conditions for uptrend and downtrend based on RSI
uptrend = cc_10['rsi'] > 60
downtrend = cc_10['rsi'] < 40
# Fetch intraday data for each stock condition for 15min
chart_15 = tsl.get_intraday_data(nifty_FnO_stocks, 'NSE', 15) # Intraday data for 10min
# Calculate the BB indicator (BB band) using talib
# chart_15['rsi'] = talib.RSI(chart_15['close'], timeperiod=14) # pandas
chart_15['upperband'], chart_15['middleband'], chart_15['lowerband'] = talib.BBANDS(chart_15['close'], timeperiod=15, nbdevup=2, nbdevdn=2, matype=0)
# Extract relevant candles for breakout analysis
cc_15 = chart_15.iloc[-1] # Breakout candle (most recent)
ub_breakout = cc_15['close'] > cc_15['upperband']
# Prevent repeating orders
no_repeat_order = nifty_FnO_stocks not in traded_watchlist
# Ensure maximum order limit is respected
max_order_limit = len(traded_watchlist) <= max_trades
# Order Execution Section---------------------------------------------
# Condition to place a buy order
if uptrend and ub_breakout and no_repeat_order and max_order_limit:
print(f"{nifty_FnO_stocks} upper bb breakout, Buy the Stock")
sl_price = round((cc_10['close']*0.30),1)
qty = int(per_trade_margin / cc_10['close']) # Calculate quantity based on margin and price
buy_entry_orderid = tsl.order_placement(
nifty_FnO_stocks, 'NSE', 1, 0, 0, 'MARKET', 'BUY', 'MIS'
)
sl_orderid = tsl.order_placement(nifty_FnO_stocks, 'NSE',1,0,sl_price,'STOPMARKET', 'SELL', 'MIS')
traded_watchlist.append(nifty_FnO_stocks) # Add to traded list
# # Condition to place a sell order
# if downtrend and inside_candle_formed and down_side_breakout and no_repeat_order and max_order_limit:
# print(f"{nifty_FnO_stocks} is in downtrend, Sell the Stock")
# qty = int(per_trade_margin / bc['close']) # Calculate quantity based on margin and price
# sell_entry_orderid = tsl.order_placement(
# nifty_FnO_stocks, 'NSE', 1, 0, 0, 'MARKET', 'SELL', 'MIS'
# )
# traded_watchlist.append(nifty_FnO_stocks) # Add to traded list
# Sleep for a few seconds before fetching the next data point (to avoid API throttling)
time.sleep(5) # Check every 5 second (adjust as needed)
Please find the above code, I’m running it in live market