Learn Advanced Algo Trading Series | Codes | Youtube

@DhanHQ @RahulDeshpande @Tradehull_Imran @Dhan

I truly appreciate the opportunity to learn backtesting. Dhan is the only Indian broker actively guiding its clients towards the future of algorithmic trading, and it’s inspiring to see such dedication.

As traders, we also have a responsibility to put in our best individual efforts to make this initiative successful.

My plan is to go through each session carefully, bringing in real-life scenarios, challenges, and practical problems for discussion. By sharing and engaging with others, we can make our learning experience truly meaningful and worthwhile.

This way, we can ensure our learning has lasting value!

4 Likes

Hi @Dhan , @Tradehull_Imran , @RahulDeshpande

Can you please guide me how can I backtest or replay historic option chain.
I am unable to find historic options related information in instruments file

Thanks!

3 Likes

Hello @Tradehull_Imran @Dhan I am getting error with below code.

option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="NSE", expiry=1, num_strikes=10)

-> option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="NSE", expiry=0, num_strikes=10)
(Pdb++) option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="NSE", expiry=1, num_strikes=10)
Getting Error at Option Chain as 'NIFTY'

orderid = tsl.order_placement(
    tradingsymbol='NIFTY 19 DEC 23300 CALL',
    exchange='NFO',
    quantity=75,
    price=0,                  # Generally BO orders are MARKET or small LIMIT
    trigger_price=0, 
    order_type='MARKET',       # or 'LIMIT' if you want
    transaction_type='BUY',
    trade_type='BO',
    bo_profit_value=30,        # Target points (example 30 points)
    bo_stop_loss_value=15      # Stop Loss points (example 15 points)
)
print(orderid)

Dear @Tradehull_Imran sir,

Please check the code for Bracket Order — is it correct? If not, kindly suggest the correct one.
Also, for modifying a Bracket Order, should we use the same format or use our regular modify order format?

hello sir ,mujhe apne algo ke liye ek sample code chahiye jo live market ka ohlc de nifty ka… jab chahe… like 12 baje tak ka ohlc…aaj ka(live market me)

Hi @Yogesh_Luhar ,

Refer the below code:

option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="INDEX", expiry=0, num_strikes=10)

hi @AJIT_KUDALE ,

You can click on Download anyway and download it.

Hi @Kuldeep_Khaladkar ,

The code seems to be right. You can use regular modify order format.
Refer the below link for more details:
Dhan-Tradehull · PyPI

Hi @Ganesh ,

You can get ohlc data using the below code:

historical_data = tsl.get_historical_data(Underlying='NIFTY', exchange='INDEX', timeframe='1')
  • timeframe (str): The timeframe for the data. It can be:
    • ‘1’ for 1-minute candles
    • ‘5’ for 5-minute candles
    • ‘15’ for 15-minute candles
    • ‘25’ for 25-minute candles
    • ‘60’ for 60-minute candles
    • ‘DAY’ for daily candles

Sir is se to ek din phle ka data aata h na… aaj ka nhn aata hai…

latest_data = tsl.get_historical_data(tradingsymbol=‘NIFTY’, exchange=‘INDEX’, timeframe=“DAY”)
last_candle = latest_data.iloc[-1]
print(last_candle)

output
reading existing file all_instrument 2025-04-21.csv
Got the instrument file
open 23401.85
high 23872.35
low 23298.55
close 23851.65
volume 0.0
timestamp 2025-04-17
Name: 246, dtype: object

aaj 21 april hai…

codebase bi update hua h kya sir g… apne pas Dhan_Tradehull_V2.py hai…aapne jo code share kiya h usme underlying keyword ko error bata rha hai…

@RahulDeshpande said that
Much more are coming :wink::smile:

Now I truly understand what you meant.
Genuinely, hats off to you — absolutely brilliant! @Dhan

Just we are missing you sir @Tradehull_Imran

same question

Hi so we no longer need the “Dhan_TradeHull_V2” file to be added by us manually to the codebase and imported? I dont see it anywhere in these files.
My tsl.cancel_all_orders function as per previous setup is not at all working so checked to upgrade the dhan_tradehull library and it latest but I see now the file “Dhan_TradeHull_V2” is not even there. PLease confirm asap.

(post deleted by author)

Now ‘Dhan_TradeHull_V2’ is updated a new version, and seems the name remains as just ‘Dhan_TradeHull’.

Very Good Morning Sir, Can you please clarify the difference in data between NSE & Dhan, with regards to the OptionChain.
NSE Gives OI & Change in OI both for Call & Put Strikes.
But at Dhan, I have noticed that it gives OI & Change in OI% for Call & Put Strikes.

I am not able to correlate the Change in OI% (Dhan) with Change in OI (NSE), of course this is not % Based.

But even that Percentage Provided on Dhan Platform is not understandable.
Can you please clarify this sir.

VBR Prasad

@Tradehull_Imran sir, thanks for your reply , but when i use this structure i got error sometimes for trigger price, , sl , target . pls check the image attached


could you pls support with snippest as I tried with both Orders - DhanHQ Ver 2.0 / API Document and Dhan-Tradehull · PyPI but i am unable to figure it out.


but same error occurs as shown in app snap

bo = manager.place_bracket_order(
    tradingsymbol=opt_sym,
    exchange="NFO",
    quantity=lot_size,
    price=ltp_opt,
    trigger_price=ltp_opt,  
    order_type="LIMIT",
    transaction_type="BUY",
    trade_type="BO",
    bo_stop_loss_value=sl_pts,  
    bo_profit_value=tp,        
    validity="DAY",
)