Learn Algo Trading with Python | Codes | Youtube Series

Hi @Vasili_Prasad ,

The code seems to be right, it is working in our end. Do re check.

Refer the below link for the code:

Hi, @Tradehull_Imran Sir,

where can I get options historical data for back testing ..? Any idea… I had seen on some quant site, but forgot to bookmark, so lost its name…

Regards

HI @Tradehull_Imran,

Can we get EOD data of OI for futures…? if Yes How to…?

Regards

D:\stocks\06_1st live algo\1st live Algo>py “How to use updated codebase.py”
Codebase Version 3
-----Logged into Dhan-----
reading existing file all_instrument 2025-04-19.csv
Got the instrument file
[0] > d:\stocks\06_1st live algo\1st live algo\how to use updated codebase.py(17)()
→ chart = tsl.get_historical_data(tradingsymbol = “NIFTY”, exchange=“INDEX”, timeframe=“5”)
(Pdb++) ce_name, pe_name, strike = tsl.ATM_Strike_Selection(Underlying=‘NIFTY’, Expiry=0)
Exception at getting Expiry list as {‘status’: ‘failure’, ‘remarks’: ‘Expecting value: line 1 column 1 (char 0)’, ‘data’: ‘’}
Unable to find the correct Expiry for NIFTY
*** TypeError: cannot unpack non-iterable NoneType object
(Pdb++)

now i am getting this error.
please guide us. Thank you,

I have been observing this phenomenon whenever there are continuous holidays. I think Dhan is shutting down all the servers and going on vacation … :rofl: :rofl: wait for monday … everything will work fine …

1 Like

hi,
Dhan wants you all to enjoy the weekends or holidays with your family… They say, dont be workaholic, give some time to ur family and enjoy with them… :wink:

Hi @anandc ,

Refer the below videos to get historical data and particular day data:

1 Like

Hi @anandc ,

Here’s how you can get oi data for futures:

name = 'NIFTY APR FUT'
quote_data = tsl.get_quote_data(name) 
oi_data = quote_data[name]['oi']

1 Like

Hi @Shashiprakash_Maurya ,

Your code seems to be right, do try during market days.

200 day EMA value using talib library not matching with 200 day EMA on tv.dhan.co. I have written below code
chart[“EMA200”] = EMAIndicator(chart[“close”], 200).ema_indicator() → “using ta.trend”
chart[“EMA200_3”] = talib.EMA(chart[‘close’], timeperiod=200) → “using talib”

none of these are matching. Please help

Hi @Tradehull_Imran ,

In continuation to previous thread,
I found again the issue, where Dhan greeks data is not working as expected.
Whereas Zerodha is showing valid data.
It won’t be a good approach to use greeks then in algo trading.
:rotating_light: Request you to please ask the technical team to check this discrepancies.


Hello @Dhan @Tradehull_Imran
Its great that you are continuously helping us on Algo Trading journey in various format.

Could you please give some idea what exactly are you going to cover in this 8 hours Marathon. Due to office hours it will be difficult for most of us.

Also, will there be recording provided for this which we can watch over weekend?

Thanks!

It will mostly be a live series of all the videos that we have uploaded till now, since a lot of users don’t get the time to watch the whole videos at once. Parallelly, Imran will be there throughout, helping and solving doubts in the comments section as well as in the community!

1 Like

Biggest LIVE session yet! Learn everything—from building scanners to deploying algos —everything explained step by step.

:date: 23rd April (Wednesday)

:alarm_clock: Starts 11:00 AM onwards

:round_pushpin: YouTube Live: https://www.youtube.com/watch?v=74GywsZHn20

Real tools. Real examples. Real-time learning.

@Akshay_Bawane @Gautam_Singh_Pawar @ardhendudgp @Ramyageethika @Subhajitpanja @BhanuV @parmeshwar_deharkar @kalpatrader

2 Likes

Hi @santosh_kumar1 ,

There will be slight difference between the values from terminal to code calculation:

Hull Moving Average code

def wma(series, period):
    weights = np.arange(1, period + 1)
    return series.rolling(period).apply(lambda prices: np.dot(prices, weights) / weights.sum(), raw=True)

def hull_moving_average_from_ohlc(open_: pd.Series, high: pd.Series, low: pd.Series, close: pd.Series, length: int = 9) -> pd.Series:
    typical_price = (open_ + high + low + close) / 4

    half_length = int(length / 2)
    sqrt_length = int(np.sqrt(length))

    wma_half = wma(typical_price, half_length)
    wma_full = wma(typical_price, length)
    diff = 2 * wma_half - wma_full

    hma = wma(diff, sqrt_length)
    return hma

df  = tsl.get_historical_data(tradingsymbol = 'NIFTY 24 APR 23000 CALL',exchange = 'NFO' ,timeframe="1")
df['HMA'] = hull_moving_average_from_ohlc(df['open'], df['high'], df['low'], df['close'], length=9)
1 Like

Very Good Afternnon sir,
In the Option Chain, following are the ‘DATA HEADS’ :
Theta, Delta, OI, OI Chg %, Volume, IV, LTP Chg, LTP, CE,
Strike Price, PE LTP, LTP Chg, IV, Volume, OI Chg %, OI, Delta, Theta

Can we get these data points at required timeframes sir?
If yes, is there any code available at Dhan API Documentation sir?
VBR Prasad

Dear Sir,
Last night I was revising ‘Downoad_Historical_Data’ and ‘Option_Chain Replay’ files.

I sincerely feel, this Session needs some more elaboration sir. Code in ‘Downoad_Historical_Data’ is not explained in details sir.
Thank You very much.

VBR Prasad

Hi @Vasili_Prasad

see below video for detailed explain for download historical data

Respected Sir,
Still I am getting error with Session-9 ‘Download_Historical_Data.py’ file, even after downloading the ZIP file provided from your end sir.
I have enclosed the code and error.
`from Dhan_Tradehull import Tradehull
import datetime
import pdb
import os

client_code = “1101092420”
token_id = “eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJkaGFuIiwicGFydG5lcklkIjoiIiwiZXhwIjoxNzQ1NzI3NjcyLCJ0b2tlbkNvbnN1bWVyVHlwZSI6IlNFTEYiLCJ3ZWJob29rVXJsIjoiIiwiZGhhbkNsaWVudElkIjoiMTEwMTA5MjQyMCJ9.cb75tCmxgH2hXanXpyh4gvNDu-RvyOlcDQHNFPEaKrgq1sOVVEylWjUxBe7RmroTcf5o37xL2MOO-oRTQYF0jA”
tsl = Tradehull(client_code,token_id)

index_name = ‘NIFTY’

no_strikes_to_replay = 20

expiry_date = “24 APR”

start_time =‘2025-04-17 09:15:00+05:30’

today_date = datetime.datetime.now().date()

index_data = tsl.get_historical_data(tradingsymbol=index_name, exchange=‘INDEX’, timeframe=“1”)

ATM_time_data = index_data[index_data[‘timestamp’]==start_time]

if not ATM_time_data.empty:
ATM_close = ATM_time_data.iloc[-1][‘close’]

step = tsl.index_step_dict[index_name]

ATM_Strike = round(ATM_close/step)*step

all_strikes = [ATM_Strike+(stepi) for i in range(1,no_strikes_to_replay+1)] + [ATM_Strike-(stepi) for i in range(1,no_strikes_to_replay+1)] + [ATM_Strike]

call_and_put_Strikes = [f"{index_name} {expiry_date} {strike} CALL" for strike in all_strikes] + [f"{index_name} {expiry_date} {strike} PUT" for strike in all_strikes]

file_path = f’data/{index_name}/{today_date}/’

directory = os.path.dirname(file_path)

if not os.path.exists(directory):
os.makedirs(directory)

for strike in call_and_put_Strikes:
option_df = tsl.get_historical_data(tradingsymbol=strike, exchange=‘NFO’, timeframe=“1”)
option_df.to_csv(f’data/{index_name}/{today_date}/{strike}.csv’,index=False)
`
And the ERROR is:

C:\Users\LENOVO PC\Desktop\RP\Dhan Algo\DHAN Advanced Algo Trading Series\Session 9\SePY “1. Download_Historical_data.py”
Codebase Version 3
-----Logged into Dhan-----
reading existing file all_instrument 2025-04-23.csv
Got the instrument file
Traceback (most recent call last):
File “1. Download_Historical_data.py”, line 33, in
ATM_Strike = round(ATM_close/step)*step
NameError: name ‘ATM_close’ is not defined

Please Resolve it sir.
VBR Prasad
type or paste code here