Learn Algo Trading with Python | Codes | Youtube Series

Hello Everyone,

Excited to announce that we’re live with our newest Algo Trading Series—this time, diving deeper into Advanced Algo Trading! :rocket:

With this two-video series, you’ll gain all the knowledge needed to transition from a beginner to an intermediate Algo Trader.

For queries, codes, and more on the Advanced Algo Trading Series, check out this post: :link: https://madefortrade.in/t/learn-advance-algo-trading-series-codes-youtube/42976!

As always, @Tradehull_Imran will be there to guide you every step of the way. Happy learning! :dart:

7 Likes

Thank you, @RahulDeshpande, and your entire team for your support! We also want to acknowledge @Dhan for going above and beyond to help us—your efforts mean a lot

3 Likes

Hello @Tradehull_Imran Sir, How we can get more months OHLC data for stocks to backtest our algo, please make a video on it or suggest any source from where we can get data affordably to test our algos. Regards

Hi @anandc ,

You need to subscribe for multiple data API for different accounts, to get the data.

Hi Sir @Tradehull_Imran
please help me in getting live oi data sir
What i have to send inplace of request code
(for request code 17 , i’m getting quote data but not getting oi data)
Sir, What is the input format to get oi data live
(i’m reading entire Dhanfeed Code from 2,3 days continoulsy , still not able to understand sir)

from dhanhq import marketfeed
sub_instruments = [(marketfeed.NSE, “1333”, 17)]
version = “v2” # Mention Version and set to latest version ‘v2’

try:
data = marketfeed.DhanFeed(client_id, access_token, sub_instruments, version)
while True:
data.run_forever()
response = data.get_data()
print(response)

except Exception as e:
print(e)

data.disconnect()
unsub_instruments = [(marketfeed.NSE, “1333”, 17)]

data.unsubscribe_symbols(unsub_instruments)

Sir Here i want to get live_oi data. Please help sir

Hi @Vinod_Kumar1

we will be checking it in upcoming videos for Open Source Backtesting

Hi @Raju2

use below code

ce_quote = tsl.get_quote(['NIFTY 13 FEB 23600 CALL'])
ce_oi = ce_quote[ce_otm]['oi']

see reference video: https://www.youtube.com/watch?v=P9iPYShakbA

Sir @Tradehull_Imran

what would be the proper way to square off the entry ?

entry_order_id = trade_hull.order_placement(
                        tradingsymbol=call,
                        exchange='NFO',
                        quantity=lot_size,
                        price=0,
                        trigger_price=0,
                        order_type='MARKET',
                        transaction_type='BUY',
                        trade_type='MIS'
                    )

cancel_buy = self.cancel_order(entry_order_id)

does not work!

we want to close the buy position that has already been traded, basically, just sell the quantity we have.

Hi @Priyesh_Sharma

can you describe more on uptick and downtick.

Hi @Dhananjay_Umalkar
to squareoff a order that is in position book. we need to send a reverse order

exit_order_id = trade_hull.order_placement(
                        tradingsymbol=call,
                        exchange='NFO',
                        quantity=lot_size,
                        price=0,
                        trigger_price=0,
                        order_type='MARKET',
                        transaction_type='SELL',
                        trade_type='MIS'
                    )

self.cancel_order(entry_order_id) will cancel order if its pending in orderbook (in which case it has not been executed and its pending and not in positionbook)

Hi @vinay_kumaar

Congrats on your Algo. :rocket:

intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “c:\Users\GLAUME\Desktop\tr\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 257, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id),exchangeSegment,instrument_type)
TypeError: intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’

@Tradehull_Imran please check this error intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “c:\Users\GLAUME\Desktop\tr\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 257, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id),exchangeSegment,instrument_type)
TypeError: intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’

Hi @Dhananjay_Umalkar

Yes, we can cancel the stop-limit order when LTP drops below the last updated trigger price. Additionally, we need to immediately send a market order in the reverse transaction type to square off the position. This ensures that the position is exited effectively, simulating a stop-loss market order.

Also note we can only cancel pending orders…
for orders that have been executed… we need to send reverse transaction type order

3 Likes

Hi @Dev_Goswami

intraday_minute_data call has been removed now… we have now upgraded to get_historical_data

see implementation video : https://www.youtube.com/watch?v=P9iPYShakbA

Hello @Tradehull_Imran

Yes, Uptick when price reverses below RSI <30
Downtick when price reverses after RSI >60

@Tradehull_Imran How can I retrieve historical data for a specific day in a 5-minute time frame? According to your video, it seems that only 2-3 days of 5-minute data can be fetched. My algorithm requires 5-minute interval data for backtesting, but I don’t have enough data. How should I proceed in this case? Also, why is Dhan charging for historical data access?

@Tradehull_Imran

Hi Sir,
I need live option chain data for stocks through web socket.
For example: TCS (only for stocks not for indexes)
i need option data(for both ce and pe) @ ATM, 2OTM & 2ITM strikes data.
"

Code…
instruments = [(marketfeed.NSE, “1333”, 17)]
version = “v2”
try:
data = marketfeed.DhanFeed(client_id, access_token, instruments, version)
while True:
data.run_forever()
response = data.get_data()
print(response)
except Exception as e:
print(e)
data.disconnect()
"

Here i’m getting Quote Data bcz of Request Code 17 But In API clearly metioned that(Whenever you subscribe to Quote Data, you also receive Open Interest (OI) data packets which is important for Derivative Contracts.)

I’m not getting oi data sir. Do i need to change input structure. Or else anything need to change.

please help me in getting live oi data for all my stocks sir. I need live oi from 9 to 3 for all my stock options.

I received this error how to solve please tell me

PS C:\Users\owner\OneDrive\Business\Algo Trading\Dhan\live-trading-project> & C:/Users/owner/AppData/Local/Programs/Python/Python38/python.exe "c:/Users/owner/OneDrive/Business/Algo Trading/Dhan/live-trading-project/src/backtesting_v4_live_tr.py"
Codebase Version 3
2025-02-14 17:33:18,424 - Dhan.py  started system
2025-02-14 17:33:18,424 - STARTED THE PROGRAM
-----Logged into Dhan-----
reading existing file all_instrument 2025-02-14.csv
Got the instrument file
2025-02-14 17:33:26,878 - Error processing GMRINFRA: No expiry date found for GMRINFRA
Traceback (most recent call last):
  File "C:\Users\owner\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py", line 128, in correct_step_df_creation
    raise ValueError(f"No expiry date found for {name}")
ValueError: No expiry date found for GMRINFRA
-----Logged into Dhan-----
reading existing file all_instrument 2025-02-14.csv
Got the instrument file
2025-02-14 17:33:39,445 - [ERROR] Dhan API Login Failed
[ERROR] Dhan API Login Failed
2025-02-14 17:33:39,445 - [ERROR] Strategy stopped due to API authentication failure.
[ERROR] Strategy stopped due to API authentication failure.
PS C:\Users\owner\OneDrive\Business\Algo Trading\Dhan\live-trading-project>

Hi @Tradehull_Imran ,
I was using following line for OI analysis,
It was working fine with this,
from Dhan_Tradehull_V2 import Tradehull

ATM_Spot, OC_Total = tsl.get_option_chain(Underlying="NIFTY", exchange="INDEX", expiry=0, num_strikes=3)

Which code will replace exactly this code by using, Dhan-Tradehull 3.0.5

Note: I’m using num_strikes as well.

TIA :slightly_smiling_face: