Hi @Sahil_Malhotra ,
Can you share your whole code to review the same?
Hi @Sahil_Malhotra ,
Can you share your whole code to review the same?
Hi @Tradehull_Imran sir,
trying to fetch option chain data for âCRUDEOILâ
ATM_Strike, option_chain = tsl.get_option_chain(Underlying= âCRUDEOILâ, exchange = âMCXâ, expiry= 0, num_strikes= 20)
getting this error :
Getting Error at Option Chain as No option chain data available for the CRUDEOIL
Hi, has there been any update on bracket order placement pls ? This is a much needed feature to ensure trades are well risk managed !
Hii @Tradehull_Imran sir,
Sir, can we get order book data in algo trading? Specifically, how many orders are placed at different levels for limit orders and market orders? If so, could you please provide more details?
By the way, sir, this has been an incredibly interesting journeyâfrom staring at the laptop screen for 4â5 hours, dealing with losses, to transitioning into algo trading, which is more accurate, fast, disciplined, and efficient. Your guidance has truly made a difference, and weâre grateful for everything youâve taught us.
With algo trading, it feels like weâve moved from emotional decision-making to a structured, rule-based approach that eliminates impulsive trades and optimizes execution speed. The reliability of data-driven strategies has made the process smoother, reducing stress and increasing consistency.
Thank you for sharing your knowledge and helping us improve our trading approach!
Hi, Siddhesh, from where to download corresponding file
Hi, Very Good Afternoon, Can you please confirm your code of Trailing_stop_loss, is functional.
I am a Non-Coder, trying to learn , Can you please help me out with some Functional Codes, especially Options trading, And Intraday trading of Equity segment, with your terms please.
Also please let me know about your success in implementing the Trailing stop loss code (Dt.07/02/2025)
VBR Prasad, 9949324446
i an using trading vie pro version i am not able to fire order on condition meet. Alert message i am receving on condition meet.
Hi - @Tradehull_Imran
how to measure the efficiency of the code. Even my 300 line codes take roung 10 secs to complete one loop. With the kinda of market movement - there is high chance that I will miss the entry window (my code has self-developed indicator - with a small price range for entry). Also, SL trailing will also be concern.
More on SL trailing. in you SL trailign videos, ATR based trailing seems to be good but even if I keep the conservative 1.5*ATR (itâs coming around roughly 25 to 30 points on 170-200 rupees options (100 OTM) like today and when the price movement is fast, ATR increases & the SL slowly trails. We might be missing out big on this. We rarely see very big move to get the benefit of this. Success ratio is very less. Also, I want to do ATR trailing based backtesting - can you help me with any books, codes, resources. Or - can you suggest any other method of SL trailing â or diret me to right direction. (btw - I do option buying)
thank you imran sir
Hi Prasad,
Yes, my code is functional, but itâs too complex to explain.
Trailing stop loss alone is 1800 line code.
I have implemented different kinds of stop losses like dynamic trailing, fixed trailing, fixed trailing with profit, and safety_net, High oi strikes, paper trading, buy dip feature and API lag fallbacks.
if you are interested in above mentioned feature or similar kinds of features, I can guide you. and also share my code.
if you are looking for a normal trailing stop loss, better stick with Dhan Super Trader function, which would be the easiest and has no maintenance code, which is also available in API, itâs 2-3 lines of code added to the original order placement function.
With that, you can input trailing jump, take profit, and take loss altogether.
sir i have subcribed to dhanapi and i am able to fetch data but their are certain discrepancies as close value obv value these are not matching.
tsl.modify_order() is giving constatnt error of an unexpected keyword argument âorder_idâ. Here is my simple code just to check order placement. Can anyone help here. Are you also getting this? @Tradehull_Imran @RahulDeshpande
import pdb
import time
import datetime
import traceback
import pandas as pd
from pprint import pprint
from Dhan_Tradehull_V2 import Tradehull
client_code = âCCodeâ
token_id = âTiken hereâ
tsl = Tradehull(client_code, token_id)
if True:
orderid = tsl.order_placement(
tradingsymbol=âNIFTY 22 MAY 25700 CALLâ,
exchange=âNFOâ,
quantity=75,
price=0,
trigger_price=0,
order_type=âMARKETâ,
transaction_type=âBUYâ,
trade_type=âMISâ
)
order_details = tsl.get_order_detail(orderid=orderid)
print("Success: OrderId- ", orderid)
sl_orderid = tsl.order_placement(
tradingsymbol=âNIFTY 22 MAY 25700 CALLâ,
exchange=âNFOâ,
quantity=75,
price=3.5,
trigger_price=4.0,
order_type=âSTOPLIMITâ,
transaction_type=âSELLâ,
trade_type=âMISâ
)
sl_order_details = tsl.get_order_detail(orderid=sl_orderid)
print("Success: SL OrderId- ", sl_orderid)
tsl.modify_order(
order_id=sl_orderid,
order_type="STOPLIMIT",
quantity=75,
price=3.7,
trigger_price=4.2
)
Thanks for your Prompt Reply Sir. AS a learner, I am interested to have your code with Different Nomenclatures. My Mail ID is: vbrajprasad@gmail.com, Mob:9949324446
Thank you very much.
VBR Prasad
Okay, Dm would be easy.
I have Dm you!
Thank you very much
is there any issue in API websocket connection
my error code
Validating Access Token...
Watchlist changed. Reconnecting the feed...
Disconnected from WebSocket feed.
WebSocket connection error: server rejected WebSocket connection: HTTP 429
Reconnecting Again...
Hi @Tradehull_Imran @RahulDeshpande @Dhan sir,
trying to fetch option chain data or ATM strike selection for âCRUDEOILâ, âNATURALGASMâ(Commodity) just doesnt work
ATM_Strike, option_chain = tsl.get_option_chain(Underlying= âCRUDEOILâ, exchange = âMCXâ, expiry= 0, num_strikes= 20)
ATM_CE_name, ATM_PE_name, ATM_Strike = tsl.ATM_Strike_Selection(Underlying=âGOLDâ, Expiry=0)
also, is there a way to find out unit of a lot for commodity?
like CRUDEOIL = 100 unit, CRUDEOILM = 10 unit
iâm also seeing similar issue. the same code was working couple of days back. could some1 provide a solution for this.
Hello @Tradehull_Imran Sir
I have a code that scans stocks whose current price > prev day high, the code is as below, in order to achieve the results can i replace get_historical_data() with get_ltp_data() ??
import pdb
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
import talib
import time
import datetime
client_code = â19â
token_id = âiR1wâ
tsl = Tradehull(client_code, token_id)
available_balance = tsl.get_balance()
leveraged_margin = available_balance5
max_trades = 2
per_trade_margin = (leveraged_margin/max_trades)
max_loss = (available_balance1)/100*-1
watchlist = [âITCâ]
traded_wathclist =
while True:
live_pnl = tsl.get_live_pnl()
current_time = datetime.datetime.now().time()
if current_time < datetime.time(9, 15):
print("wait for market to start", current_time)
continue
if (current_time > datetime.time(14, 30)) or (live_pnl < max_loss):
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(1)
print(stock_name)
chart_1 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="1")
chart_5min = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="5") # this call has been updated to get_historical_data call,
chart_15 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="15") # this call has been updated to get_historical_data call,
chart_daily = tsl.get_historical_data(tradingsymbol = stock_name,exchange ='NSE', timeframe="DAY")
if (chart_1 is None) or (chart_5min is None) :
continue
if (chart_1.empty) or (chart_5min.empty):
continue
if (chart_15.empty) or (chart_15.empty):
continue
if (chart_15 is None) or (chart_15 is None) :
continue
if (chart_daily.empty) or (chart_daily is None):
continue
# Conditions that are on 5 minute timeframe
chart_5min['ema20'] = talib.EMA(chart_5min['close'], timeperiod=20)
chart_5min['ema50'] = talib.EMA(chart_5min['close'], timeperiod=50)
chart_5min['ema100'] = talib.EMA(chart_5min['close'], timeperiod=100)
chart_5min['ema200'] = talib.EMA(chart_5min['close'], timeperiod=200)
# Get previous and current day's data
prev_day = chart_daily.iloc[-2]
curr_day = chart_daily.iloc[-1]
cc_5 = chart_5min.iloc[-1] #pandas completed candle of 5 min timeframe
ema_condition = (cc_5['ema20'] > cc_5['ema50']) and (cc_5['ema20'] > cc_5['ema100']) and (cc_5['ema20'] > cc_5['ema200'])
high_breakout = curr_day['high'] > prev_day['high']
no_repeat_order = stock_name not in traded_wathclist
max_order_limit = len(traded_wathclist) <= max_trades
if high_breakout and ema_condition and no_repeat_order and max_order_limit:
print(stock_name, "is in uptrend, Buy this script")
Hi @Tradehull_Imran Sir
atm_strike, option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="INDEX", expiry=0, num_strikes=16)
# Find strikes where call price < 40 and put price > 40
call_price = option_chain[option_chain['CE LTP'] < 40]
call_index = call_price['CE LTP'].idxmax()
call_strike = call_price.loc[call_index]['Strike Price']
As call_strike is not a valid symbol name, kindly guide to place order for required call_strike below Rs 40. Pl give syntax for order placement for call_strike