I am new to use Dhan API. I got the framework code and working well for intraday thru Dhan’s youTube channel. Thank you for the same.
But, when I am trying to test my strategy with old data, say with 2 year OHLC data, I am getting only limited candles data. Please help me to get the historic data.
Also, please provide any back testing framework to use the json mentions in Dhan API page in python code, as below link.
@anuragbhumca07
Dhan provides 2 types of historical data that is intraday and another is daily.
Intraday Historical data is available for last 5 days or so.
Daily historical data is at day level so you will get one OHLC value for each day.
You can find below sample code implemented using dhanhq library. Using this code you can easily fetch daily historical data for whatever date range you want by setting from_date and to_date values in function:
from dhanhq import dhanhq
dhan = dhanhq("client_id","access_token")
# Intraday Minute Data
dhan.intraday_minute_data(security_id,exchange_segment,instrument_type)
# Historical Daily Data
dhan.historical_daily_data(security_id,exchange_segment,instrument_type,expiry_code,from_date,to_date)
Then in that case, how to back test any strategy which is basically based on 5 min. timeframe, and if I want to see the performance over the last 2 years with that strategy?
@Tradehull_Imran is going to cover backtesting topic in ongoing advanced algo trading series.
But logically if you want to backtest your strategy then fetch historical daily data and store it in dataframe.
After that run your logic in loop for each historical date and test when entry exit signals are generated using your algo. Don’t forgot to store entry exit signals in excel or separate dtaframe.
At last calculate your statistics about max profits, max loss, number of trades, average profits per trade etc.
And then fine tune your Algo to limit or reduce loss.
You can also identify for which stocks or segments your algorithm is performing good. How overall market was performing at that time and so on.
but in daily historical data, there is GapUP/GapDown some days which are majoly impacting the results and need to check it every time manually. If you can suggest, where or in some portals, I can get the historic 1 min. data.