Hi @Tradehull_Imran ,
How to calculate Change in OI …?
Hi @Tradehull_Imran ,
How to calculate Change in OI …?
yes it is easy, share your code.
like if u want it should trail to ctc it can do that also if u want it trail continually like for every 5point it can trail sl up.
or can use this code and modify according to your needs
while True:
try:
current_market_price_dict = tsl.get_ltp_data(names=[trading_symbol])
current_market_price = current_market_price_dict[trading_symbol]
if current_market_price >= target_price:
# Target booking
tsl.modify_order(order_id=stoploss_orderid, order_type= "MARKET", quantity=qty, price=0, trigger_price=0)
log_queue.put(f"Target reached. Selling {trading_symbol} at market price. Sell Order ID: {stoploss_orderid}")
logging.info(f"Target reached. Selling {trading_symbol} at market price. Sell Order ID: {stoploss_orderid}")
break
elif current_market_price >= buy_price + sltrail:
# Calculate new stop-loss price
modified_sl = current_market_price - sltrail
sl_limit_price = modified_sl - 1
# Place a new stop-loss order
tsl.modify_order(order_id=stoploss_orderid, order_type= "STOPLIMIT", quantity=qty, price=sl_limit_price, trigger_price=modified_sl)
log_queue.put(f"New Stop Loss Order Placed. Order ID: {stoploss_orderid}, Stop Price: {modified_sl}")
logging.info(f"New Stop Loss Order Placed. Order ID: {stoploss_orderid}, Stop Price: {modified_sl}")
Hi @Vinod_Kumar1 ,
Send your code, will check if any speed optimization is possible in the code.
Hi @Abhishek_Pawde ,
do use this upgraded codebase file to get option chain for stocks:
Hi @Himansshu_Joshi
use below code
if ltp < sl_price:
modified_order = tsl.modify_order(order_id=sl_orderid,order_type="MARKET",quantity=25,price=0,trigger_price=0)
hi @Akshay_Bawane ,
you can fetch change in oi from the option chain directly. refer below code
option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="INDEX", expiry=0, num_strikes=10)
hello @Tradehull_Imran can i add indicator on ltp combined atm preimum live data while streaming i was trying but i failed mutlipe times
please suggest a code for trailing stop loss… or way to do it…
Do send the code and error faced as well
Hi @SF_F
we will be creating Trailing SL in detail in upcoming advance Algorithmic Trading Series.
for the Change in OI data from dhanhq… divide it by lot size.
Also for SENSEX the lot size will be 20 now.
thank you for your response in the meantime please confirm if below code works for trailing SL.
order_price = tsl.get_executed_price(orderid=buy_entry_orderid)
if order_status == "Traded":
print("Buy 1st order Successful, Order Price -", order_price)
if initial_SL == 0 #ensure always zero else initial SL will not trigger
#SL Cal.
sl_price = int(round((order_price-2),1))
sl_orderid = tsl.order_placement(atm_ce_sp,'NSE', 1, sl_price, sl_price, 'STOPMARKET', 'SELL', 'MIS')
sl_order_status = tsl.get_order_status(orderid=sl_orderid)
initial_SL = 1
print("Stoploss order pending-", sl_price)
continue
sl_order_status = tsl.get_order_status(orderid=sl_orderid)
sl_orderid_price = tsl.get_executed_price(orderid=sl_orderid)
if sl_order_status == "Pending":
#tlsl_status
tlsl_1Min = tsl.get_historical_data(tradingsymbol=atm_ce_sp,exchange='NSE',timeframe='1')
tlsl_ltp = int(tlsl_1Min['close'].iloc[-2])
usl_price = int(round(max(order_price,tlsl_ltp)-2,0))
if usl_ltp > sl_price:
cancel_details = tsl.cancel_orders(sl_orderid)
sl_orderid = tsl.order_placement(atm_ce_sp,'NSE', 1, usl_price, usl_price, 'STOPMARKET', 'SELL', 'MIS')
print("modify_TL_order-", tlsl_ltp, sl_orderid)
sl_order_status = tsl.get_order_status(orderid=sl_orderid)
if order_status == "Traded":
print("Modified_Stoploss Hit-", sl_price, sl_orderid)
sl_orderid_price = tsl.get_executed_price(orderid=sl_orderid)
order_detail = tsl.get_orderbook('')
Good afternnon sir, I was trying to Multitime frame file from Session 8, I am getting this error:
CODE:
import pdb
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
import talib
import time
import datetime
client_code = “1101092420”
token_id = “-----------”
tsl = Tradehull(client_code,token_id)
available_balance = tsl.get_balance()
leveraged_margin = available_balance5
max_trades = 1
per_trade_margin = (leveraged_margin/max_trades)
max_loss = (available_balance1)/100*-1
watchlist = [‘MOTHERSON’, ‘OFSS’, ‘MANAPPURAM’, ‘BSOFT’, ‘CHAMBLFERT’, ‘DIXON’, ‘NATIONALUM’, ‘DLF’, ‘IDEA’, ‘ADANIPORTS’, ‘SAIL’, ‘HINDCOPPER’, ‘INDIGO’, ‘RECLTD’, ‘PNB’, ‘HINDALCO’, ‘RBLBANK’, ‘GNFC’, ‘ALKEM’, ‘CONCOR’, ‘PFC’, ‘GODREJPROP’, ‘MARUTI’, ‘ADANIENT’, ‘ONGC’, ‘CANBK’, ‘OBEROIRLTY’, ‘BANDHANBNK’, ‘SBIN’, ‘HINDPETRO’, ‘CANFINHOME’, ‘TATAMOTORS’, ‘LALPATHLAB’, ‘MCX’, ‘TATACHEM’, ‘BHARTIARTL’, ‘INDIAMART’, ‘LUPIN’, ‘INDUSTOWER’, ‘VEDL’, ‘SHRIRAMFIN’, ‘POLYCAB’, ‘WIPRO’, ‘UBL’, ‘SRF’, ‘BHARATFORG’, ‘GRASIM’, ‘IEX’, ‘BATAINDIA’, ‘AARTIIND’, ‘TATASTEEL’, ‘UPL’, ‘HDFCBANK’, ‘LTF’, ‘TVSMOTOR’, ‘GMRINFRA’, ‘IOC’, ‘ABCAPITAL’, ‘ACC’, ‘IDFCFIRSTB’, ‘ABFRL’, ‘ZYDUSLIFE’, ‘GLENMARK’, ‘TATAPOWER’, ‘PEL’, ‘IDFC’, ‘LAURUSLABS’, ‘BANKBARODA’, ‘KOTAKBANK’, ‘CUB’, ‘GAIL’, ‘DABUR’, ‘TECHM’, ‘CHOLAFIN’, ‘BEL’, ‘SYNGENE’, ‘FEDERALBNK’, ‘NAVINFLUOR’, ‘AXISBANK’, ‘LT’, ‘ICICIGI’, ‘EXIDEIND’, ‘TATACOMM’, ‘RELIANCE’, ‘ICICIPRULI’, ‘IPCALAB’, ‘AUBANK’, ‘INDIACEM’, ‘GRANULES’, ‘HDFCAMC’, ‘COFORGE’, ‘LICHSGFIN’, ‘BAJAJFINSV’, ‘INFY’, ‘BRITANNIA’, ‘M&MFIN’, ‘BAJFINANCE’, ‘PIIND’, ‘DEEPAKNTR’, ‘SHREECEM’, ‘INDUSINDBK’, ‘DRREDDY’, ‘TCS’, ‘BPCL’, ‘PETRONET’, ‘NAUKRI’, ‘JSWSTEEL’, ‘MUTHOOTFIN’, ‘CUMMINSIND’, ‘CROMPTON’, ‘M&M’, ‘GODREJCP’, ‘IGL’, ‘BAJAJ-AUTO’, ‘HEROMOTOCO’, ‘AMBUJACEM’, ‘BIOCON’, ‘ULTRACEMCO’, ‘VOLTAS’, ‘BALRAMCHIN’, ‘SUNPHARMA’, ‘ASIANPAINT’, ‘COALINDIA’, ‘SUNTV’, ‘EICHERMOT’, ‘ESCORTS’, ‘HAL’, ‘ASTRAL’, ‘NMDC’, ‘ICICIBANK’, ‘TORNTPHARM’, ‘JUBLFOOD’, ‘METROPOLIS’, ‘RAMCOCEM’, ‘INDHOTEL’, ‘HINDUNILVR’, ‘TRENT’, ‘TITAN’, ‘JKCEMENT’, ‘ASHOKLEY’, ‘SBICARD’, ‘BERGEPAINT’, ‘JINDALSTEL’, ‘MFSL’, ‘BHEL’, ‘NESTLEIND’, ‘HDFCLIFE’, ‘COROMANDEL’, ‘DIVISLAB’, ‘ITC’, ‘TATACONSUM’, ‘APOLLOTYRE’, ‘AUROPHARMA’, ‘HCLTECH’, ‘LTTS’, ‘BALKRISIND’, ‘DALBHARAT’, ‘APOLLOHOSP’, ‘ABBOTINDIA’, ‘ATUL’, ‘UNITDSPR’, ‘PVRINOX’, ‘SIEMENS’, ‘SBILIFE’, ‘IRCTC’, ‘GUJGASLTD’, ‘BOSCHLTD’, ‘NTPC’, ‘POWERGRID’, ‘MARICO’, ‘HAVELLS’, ‘MPHASIS’, ‘COLPAL’, ‘CIPLA’, ‘MGL’, ‘ABB’, ‘PIDILITIND’, ‘MRF’, ‘LTIM’, ‘PAGEIND’, ‘PERSISTENT’]
traded_wathclist =
while True:
live_pnl = tsl.get_live_pnl()
current_time = datetime.datetime.now().time()
if current_time < datetime.time(9, 30):
print("wait for market to start", current_time)
continue
if (current_time > datetime.time(23, 15)) 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, Bye Bye see you tomorrow", current_time)
break
for stock_name in watchlist:
time.sleep(0.2)
print(stock_name)
# Conditions that are on 1 minute timeframe
# chart_1 = tsl.get_intraday_data(stock_name, 'NSE', 1) # 1 minute chart # this call has been updated to get_historical_data call,
chart_1 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="1")
chart_1['rsi'] = talib.RSI(chart_1['close'], timeperiod=14) #pandas
cc_1 = chart_1.iloc[-2] #pandas completed candle of 1 min timeframe
uptrend = cc_1['rsi'] > 60
downtrend = cc_1['rsi'] < 40
# Conditions that are on 5 minute timeframe
# chart_5 = tsl.get_intraday_data(stock_name, 'NSE', 5) # 5 minute chart
chart_5 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="5") # this call has been updated to get_historical_data call,
chart_5['upperband'], chart_5['middleband'], chart_5['lowerband'] = talib.BBANDS(chart_5['close'], timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
cc_5 = chart_5.iloc[-1] # pandas
ub_breakout = cc_5['high'] > cc_5['upperband']
lb_breakout = cc_5['low'] < cc_5['lowerband']
no_repeat_order = stock_name not in traded_wathclist
max_order_limit = len(traded_wathclist) <= max_trades
if uptrend and ub_breakout and no_repeat_order and max_order_limit:
print(stock_name, "is in uptrend, Buy this script")
sl_price = round((cc_1['close']*0.98),1)
qty = int(per_trade_margin/cc_1['close'])
buy_entry_orderid = tsl.order_placement(stock_name,'NSE', 1, 0, 0, 'MARKET', 'BUY', 'MIS')
sl_orderid = tsl.order_placement(stock_name,'NSE', 1, 0, sl_price, 'STOPMARKET', 'SELL', 'MIS')
traded_wathclist.append(stock_name)
if downtrend and lb_breakout and no_repeat_order and max_order_limit:
print(stock_name, "is in downtrend, Sell this script")
sl_price = round((cc_1['close']*1.02),1)
qty = int(per_trade_margin/cc_1['close'])
buy_entry_orderid = tsl.order_placement(stock_name,'NSE', 1, 0, 0, 'MARKET', 'SELL', 'MIS')
sl_orderid = tsl.order_placement(stock_name,'NSE', 1, 0, sl_price, 'STOPMARKET', 'BUY', 'MIS')
traded_wathclist.append(stock_name)
ERROR:
C:\Users\RP\Desktop\DHAN Algorhythemic Trading\8. Session8- 2nd Live Algo\2nd live Algo>py “Multi timeframe Algo.py”
Codebase Version 2.3 : Solved - ATM issues
-----Logged into Dhan-----
reading existing file all_instrument 2025-01-30.csv
Got the instrument file
Exception for instrument name HINDALCO INDUSTRIES as Check the Tradingsymbol
Exception for instrument name NIFTY BANK as Check the Tradingsymbol
got exception in pnl as ‘Hindalco Industries’
MOTHERSON
OFSS
MANAPPURAM
BSOFT
CHAMBLFERT
DIXON
NATIONALUM
DLF
IDEA
ADANIPORTS
SAIL
HINDCOPPER
INDIGO
RECLTD
PNB
HINDALCO
RBLBANK
GNFC
ALKEM
CONCOR
PFC
PFC is in uptrend, Buy this script
GODREJPROP
MARUTI
ADANIENT
ONGC
CANBK
OBEROIRLTY
BANDHANBNK
BANDHANBNK is in downtrend, Sell this script
SBIN
HINDPETRO
CANFINHOME
TATAMOTORS
LALPATHLAB
MCX
TATACHEM
BHARTIARTL
INDIAMART
LUPIN
INDUSTOWER
VEDL
SHRIRAMFIN
POLYCAB
WIPRO
UBL
SRF
BHARATFORG
GRASIM
IEX
BATAINDIA
AARTIIND
TATASTEEL
UPL
HDFCBANK
LTF
TVSMOTOR
GMRINFRA
Exception in Getting OHLC data as Check the Tradingsymbol or Exchange
Traceback (most recent call last):
File “Multi timeframe Algo.py”, line 57, in
chart_1[‘rsi’] = talib.RSI(chart_1[‘close’], timeperiod=14) #pandas
TypeError: ‘NoneType’ object is not subscriptable
Hi @SF_F
Check below code reference
import pdb
import time
import datetime
import traceback
from Dhan_Tradehull import Tradehull
import pandas as pd
from pprint import pprint
import talib
import pandas_ta as ta
import xlwings as xw
import winsound
import sqn_lib
client_code = "1102790337"
token_id = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJkaGFuIiwicGFydG5lcklkIjoiIiwiZXhwIjoxNzM2ODYwMTMxLCJ0b2tlbkNvbnN1bWVyVHlwZSI6IlNFTEYiLCJ3ZWJob29rVXJsIjoiIiwiZGhhbkNsaWVudElkIjoiMTEwMjc5MDMzNyJ9.Leop6waGeVfmBOtczNEcjRWmC8pUGWQf54YPINGDi_PZjk1IvW-DDdaYXsgM_s8McOT44q4MjEQxGXU0lduK0A"
tsl = Tradehull(client_code,token_id)
opening_balance = 1005000 # tsl.get_balance()
base_capital = 1000000
market_money = opening_balance - base_capital
# beacuse I am loosing money, so I have 0 market money, and I can take risk on the current opening balance and not on the base capital
if (market_money < 0):
market_money = 0
base_capital = opening_balance
market_money_risk = (market_money*1)/100
base_capital_risk = (base_capital*0.5)/100
max_risk_for_today = base_capital_risk + market_money_risk
max_order_for_today = 2
risk_per_trade = (max_risk_for_today/max_order_for_today)
atr_multipler = 3
risk_reward = 3
watchlist = ['NIFTY', 'ADANIPORTS', 'ADANIENT', 'SBIN']
single_order = {'name':None, 'date':None , 'entry_time': None, 'entry_price': None, 'buy_sell': None, 'qty': None, 'sl': None, 'exit_time': None, 'exit_price': None, 'pnl': None, 'remark': None, 'traded':None}
orderbook = {}
wb = xw.Book('Live Trade Data.xlsx')
live_Trading = wb.sheets['Live_Trading']
completed_orders_sheet = wb.sheets['completed_orders']
reentry = "yes" #"yes/no"
completed_orders = []
bot_token = "8059847390:AAECSnQK-yOaGJ-clJchb1cx8CDhx2VQq-M"
receiver_chat_id = "1918451082"
live_Trading.range("A2:Z100").value = None
completed_orders_sheet.range("A2:Z100").value = None
for name in watchlist:
orderbook[name] = single_order.copy()
while True:
print("starting while Loop \n\n")
current_time = datetime.datetime.now().time()
if current_time < datetime.time(10, 15):
print(f"Wait for market to start", current_time)
time.sleep(1)
continue
live_pnl = tsl.get_live_pnl()
max_loss_hit = live_pnl < (max_risk_for_today*-1)
market_over = current_time > datetime.time(15, 15)
if max_loss_hit or market_over:
order_details = tsl.cancel_all_orders()
print(f"Market over Closing all trades !! Bye Bye See you Tomorrow", current_time)
pdb.set_trace()
break
all_ltp = tsl.get_ltp_data(names = watchlist)
for name in watchlist:
orderbook_df = pd.DataFrame(orderbook).T
live_Trading.range('A1').value = orderbook_df
completed_orders_df = pd.DataFrame(completed_orders)
completed_orders_sheet.range('A1').value = completed_orders_df
current_time = datetime.datetime.now()
print(f"Scanning {name} {current_time}")
try:
if name == "NIFTY":
exchange = "INDEX"
else:
exchange = "NSE"
chart = tsl.get_historical_data(tradingsymbol = name,exchange = exchange,timeframe="5")
chart['rsi'] = talib.RSI(chart['close'], timeperiod=14)
sqn_lib.sqn(df=chart, period=21)
chart['market_type'] = chart['sqn'].apply(sqn_lib.market_type)
chart['atr'] = talib.ATR(chart['high'], chart['low'], chart['close'], timeperiod=14)
cc = chart.iloc[-2]
no_of_orders_placed = orderbook_df[orderbook_df['qty'] > 0].shape[0] + completed_orders_df[completed_orders_df['qty'] > 0].shape[0]
# buy entry conditions
bc1 = cc['rsi'] > 1
bc2 = orderbook[name]['traded'] is None
bc3 = True # cc['market_type'] != "neutral"
bc4 = no_of_orders_placed < 5
except Exception as e:
print(e)
continue
if bc1 and bc2 and bc3:
print("buy ", name, "\t")
pdb.set_trace()
# margin_avialable = tsl.get_balance()
# margin_required = cc['close']/4.5
# if margin_avialable < margin_required:
# print(f"Less margin, not taking order : margin_avialable is {margin_avialable} and margin_required is {margin_required} for {name}")
# continue
ce_name, pe_name, ce_otm_strike, pe_otm_strike = tsl.OTM_Strike_Selection(Underlying='NIFTY', Expiry=0, OTM_count=2)
lot_size = tsl.get_lot_size(tradingsymbol = ce_name)
options_chart = tsl.get_historical_data(tradingsymbol = ce_name,exchange = 'NFO',timeframe="5")
options_chart['atr'] = talib.ATR(options_chart['high'], options_chart['low'], options_chart['close'], timeperiod=14)
rc_options = options_chart.iloc[-1]
orderbook[name]['name'] = name
orderbook[name]['options_name'] = ce_name
orderbook[name]['date'] = str(current_time.date())
orderbook[name]['entry_time'] = str(current_time.time())[:8]
orderbook[name]['max_holding_time'] = datetime.datetime.now() + datetime.timedelta(hours=2)
orderbook[name]['buy_sell'] = "BUY"
sl_points = rc_options['atr']*atr_multipler
orderbook[name]['qty'] = 25 # int(int((risk_per_trade*0.7)/sl_points)/lot_size)*lot_size
try:
entry_orderid = tsl.order_placement(tradingsymbol=orderbook[name]['options_name'] ,exchange='NFO', quantity=orderbook[name]['qty'], price=0, trigger_price=0, order_type='MARKET', transaction_type='BUY', trade_type='MIS')
orderbook[name]['entry_orderid'] = entry_orderid
orderbook[name]['entry_price'] = tsl.get_executed_price(orderid=orderbook[name]['entry_orderid'])
orderbook[name]['sl'] = round(orderbook[name]['entry_price'] - sl_points, 1) # 99
orderbook[name]['tsl'] = orderbook[name]['sl']
price = orderbook[name]['sl'] - 0.05
sl_orderid = tsl.order_placement(tradingsymbol=orderbook[name]['options_name'] ,exchange='NFO', quantity=orderbook[name]['qty'], price=price, trigger_price=orderbook[name]['sl'], order_type='STOPLIMIT', transaction_type ='SELL', trade_type='MIS')
orderbook[name]['sl_orderid'] = sl_orderid
orderbook[name]['traded'] = "yes"
message = "\n".join(f"'{key}': {repr(value)}" for key, value in orderbook[name].items())
message = f"Entry_done {name} \n\n {message}"
tsl.send_telegram_alert(message=message,receiver_chat_id=receiver_chat_id,bot_token=bot_token)
except Exception as e:
print(e)
pdb.set_trace(header= "error in entry order")
if orderbook[name]['traded'] == "yes":
bought = orderbook[name]['buy_sell'] == "BUY"
if bought:
try:
ltp = all_ltp[name]
sl_hit = tsl.get_order_status(orderid=orderbook[name]['sl_orderid']) == "TRADED"
holding_time_exceeded = datetime.datetime.now() > orderbook[name]['max_holding_time']
current_pnl = round((ltp - orderbook[name]['entry_price'])*orderbook[name]['qty'],1)
except Exception as e:
print(e)
pdb.set_trace(header = "error in sl order cheking")
if sl_hit:
try:
orderbook[name]['exit_time'] = str(current_time.time())[:8]
orderbook[name]['exit_price'] = tsl.get_executed_price(orderid=orderbook[name]['sl_orderid'])
orderbook[name]['pnl'] = round((orderbook[name]['exit_price'] - orderbook[name]['entry_price'])*orderbook[name]['qty'],1)
orderbook[name]['remark'] = "Bought_SL_hit"
message = "\n".join(f"'{key}': {repr(value)}" for key, value in orderbook[name].items())
message = f"SL_HIT {name} \n\n {message}"
tsl.send_telegram_alert(message=message,receiver_chat_id=receiver_chat_id,bot_token=bot_token)
if reentry == "yes":
completed_orders.append(orderbook[name])
orderbook[name] = None
except Exception as e:
print(e)
pdb.set_trace(header = "error in sl_hit")
if holding_time_exceeded and (current_pnl < 0):
try:
tsl.cancel_order(OrderID=orderbook[name]['sl_orderid'])
time.sleep(2)
square_off_buy_order = tsl.order_placement(tradingsymbol=orderbook[name]['name'] ,exchange='NSE', quantity=orderbook[name]['qty'], price=0, trigger_price=0, order_type='MARKET', transaction_type='SELL', trade_type='MIS')
orderbook[name]['exit_time'] = str(current_time.time())[:8]
orderbook[name]['exit_price'] = tsl.get_executed_price(orderid=square_off_buy_order)
orderbook[name]['pnl'] = (orderbook[name]['exit_price'] - orderbook[name]['entry_price'])*orderbook[name]['qty']
orderbook[name]['remark'] = "holding_time_exceeded_and_I_am_still_facing_loss"
message = "\n".join(f"'{key}': {repr(value)}" for key, value in orderbook[name].items())
message = f"holding_time_exceeded_and_I_am_still_facing_loss {name} \n\n {message}"
tsl.send_telegram_alert(message=message,receiver_chat_id=receiver_chat_id,bot_token=bot_token)
if reentry == "yes":
completed_orders.append(orderbook[name])
orderbook[name] = None
winsound.Beep(1500, 10000)
except Exception as e:
print(e)
pdb.set_trace(header = "error in tg_hit") # Testing changes. sadhasd ajsdas dbna sdb abs da sd asd abs d asd
options_name = orderbook[name]['options_name']
options_chart = tsl.get_historical_data(tradingsymbol = options_name,exchange = 'NFO',timeframe="5")
options_chart['atr'] = talib.ATR(options_chart['high'], options_chart['low'], options_chart['close'], timeperiod=14)
rc_options = options_chart.iloc[-1]
sl_points = rc_options['atr']*atr_multipler
options_ltp = tsl.get_ltp_data(names = options_name)[options_name]
tsl_level = options_ltp - sl_points
if tsl_level > orderbook[name]['tsl']:
trigger_price = round(tsl_level, 1)
price = trigger_price - 0.05
tsl.modify_order(order_id=orderbook[name]['sl_orderid'],order_type="STOPLIMIT",quantity=25,price=price,trigger_price=trigger_price)
orderbook[name]['tsl'] = tsl_level
# order_ids = tsl.place_slice_order(tradingsymbol="NIFTY 19 DEC 24400 CALL", exchange="NFO",quantity=10000, transaction_type="BUY",order_type="LIMIT",trade_type="MIS",price=0.05)
Use below code to manage exceptions
for stock_name in watchlist:
print(stock_name)
chart_1 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="1")
if chart_1 is None:
continue
chart_1['rsi'] = talib.RSI(chart_1['close'], timeperiod=14) #pandas
also remove GMRINFRA from watchlist
and use latest codebase file : Dhan_Tradehull_V2.py - Google Drive
Thank you so much for your kind & quick help
M&MFIN LTP SHOWN 2106.98 INSTEND OF CURRENT PRICE, PLEASE HELP. @Tradehull_Imran
Very Good Morning Sir.
Thank You very much for your correction.
I will let you know after trying this sir.
VBR Prasad
Sir I have suggested modification in the code. But Still I am getting the Error:
Modified Code:
for stock_name in watchlist:
time.sleep(0.2)
print(stock_name)
# Conditions that are on 1 minute timeframe
# chart_1 = tsl.get_intraday_data(stock_name, 'NSE', 1) # 1 minute chart # this call has been updated to get_historical_data call,
chart_1 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="1")
if chart_1 is none:
continue
chart_1['rsi'] = talib.RSI(chart_1['close'], timeperiod=14) #pandas
cc_1 = chart_1.iloc[-2] #pandas completed candle of 1 min timeframe
uptrend = cc_1['rsi'] > 60
downtrend = cc_1['rsi'] < 40
ERROR:
Codebase Version 2.3 : Solved - ATM issues
-----Logged into Dhan-----
This BOT Is Picking New File From Dhan
Got the instrument file
MOTHERSON
Traceback (most recent call last):
File “Multi timeframe Algo.py”, line 55, in
if chart_1 is none:
NameError: name ‘none’ is not defined
Please Suggest Sir.