Learn Algo Trading with Python | Codes | Youtube Series

Hi @Aijaz_Ahmad

This is tick data , it wont have 5 mins candle volume data
use this code for 5 mins volume data

data = tsl.get_historical_data(tradingsymbol = 'ACC' ,exchange = 'NSE' ,timeframe="5")

also the rate limit issue has been fixed
use this file : Learn Algo Trading with Python | Codes | Youtube Series - #1330 by Tradehull_Imran

Hi @avinashkumar07412

I have checked the code and it seems correct.
also we need to add code so that it foes not send repeated orders also

I have added pseudocode for same

# Define the running, breakout, inside, and base candles
rc = index_chart.iloc[-1]  # Running candle
bc = index_chart.iloc[-2]  # Breakout candle
ic = index_chart.iloc[-3]  # Inside candle
ba_c = index_chart.iloc[-4]  # Base candle

print(index_chart)

# ------------------------- LEVELS ----------------------------------------------------
index_chart1 = {
    "level1": 24729,
    "level2": 24646,
    "level3": 24567,
    "level4": 24492,
    "level5": 24437,
    "level6": 24381,
    "level7": 24304
}

# Initialize breakout levels list
breakout_levels = []
traded = "no"


# ---------------------------------- BUY -------------------------------------------
for level_name, level_value in index_chart1.items():

    if ba_c['close'] > level_value:
        breakout_levels.append(f"Above {level_name} ({level_value})")

    if (any("Above" in level for level in breakout_levels) and (index_chart['rsi'] > 55).any() and ba_c['close'] > ic['close']) and (traded == "no"):
        print("buy")
        traded = "yes"


# ---------------------------------- SELL -------------------------------------------
    if ba_c['close'] < level_value:
        breakout_levels.append(f"Below {level_name} ({level_value})")

    if (any("Below" in level for level in breakout_levels) and (index_chart['rsi'] < 50).any() and ba_c['close'] < ic['close']):
        print("sell")


1 Like

I have general question to @Dhan @Hardik and @Tradehull_Imran sir

For :chart_with_downwards_trend: :chart_with_upwards_trend: candle stick chart we have replay features to test our own technical logic.

Similarly entire day I need option chain data for a perticular entity (suppose Bank nifty, ACC data)

At the end of the day I will see the excel in every minute how option data changed

Just want to know is it possible with any local database or not

Thanks @Tradehull_Imran. The rate limit issues are not coming up now and my code is working fine

Thank you @Tradehull_Imran sir🙏

Just one last clarification for this question. We can get that Order ID dynamically right ?
Instead of passing to the parameter static value.

Hi @parveen_chugh

use this code for option chain


tradingsymbol = "NIFTY"
exchange = "NSE"
instrument_exchange = {'NSE':"NSE",'BSE':"BSE",'NFO':'NSE','BFO':'BSE','MCX':'MCX','CUR':'NSE'}
exchange_segment = tsl.Dhan.INDEX
instrument_df = tsl.instrument_df.copy()
security_id 	= instrument_df[((instrument_df['SEM_TRADING_SYMBOL']==tradingsymbol)|(instrument_df['SEM_CUSTOM_SYMBOL']==tradingsymbol))&(instrument_df['SEM_EXM_EXCH_ID']==instrument_exchange[exchange])].iloc[-1]['SEM_SMST_SECURITY_ID']

option_chain_data = tsl.Dhan.option_chain(under_security_id =int(security_id), under_exchange_segment = exchange_segment, expiry = '2024-12-05' )
option_chain_data = pd.DataFrame(option_chain_data['data']['data'])

also we will be releasing option_chain complete support in Dhan_Tradehull_V3

yes we will get orderid as return value when we place an order

entry_orderid = tsl.order_placement('ACC','NSE', 1, 0, 0, 'MARKET', 'BUY', 'MIS')
order_status  = tsl.get_order_status(orderid=entry_orderid)


if order_status == 'TRADED':
    print("Order is suscessfully executed")


if order_status == 'PENDING':
    print("Order is PENDING")
1 Like

Hi, @Tradehull_Imran , Sir, around 1.30 pm I received this Error Message regarding Rate Limit, sir…

Thank you :pray: @Tradehull_Imran sir

Hi @Tradehull_Imran ,

This is what I want, it’s giving live OHLCV from 1second upto 30minutes.

https://api.icicidirect.com/breezeapi/documents/index.html#candle-data-live-streamliveohlcv

Also this is another Breeze API websocket method through which we can get OHLCV, below is the output for 5minute time frame.

Ticks: {'interval': '5minute', 'exchange_code': 'NSE', 'stock_code': 'TCS', 'low': '4455.15', 'high': '4469.95', 'open': '4455.15', 'close': '4468.95', 'volume': '92561', 'datetime': '2024-12-05 14:15:00'}
Ticks: {'interval': '5minute', 'exchange_code': 'NSE', 'stock_code': 'HEG', 'low': '588.6', 'high': '591.9', 'open': '588.6', 'close': '590.75', 'volume': '146606', 'datetime': '2024-12-05 14:15:00'}

The main thing is with OHLC it’s providing volume, which I want in realtime without hitting rate limit.

Thanks sir…

@Tradehull_Imran sir

Hi @Kishore007

send drive link of folder you are using
also from when the algo was running.

Rate limit is hit and if you are pulling data for too many stocks it gives this error and I observed some other issues as well.

Hi @Aijaz_Ahmad

This is good, we can raise a feature request for the same
adding @Hardik for same.

Hi @Tradehull_Imran,

Thanks, but since it’s not readily available now and might take some time, is it possible for you to help me by using Breeze API for pulling data in realtime and using dhan for the rest.

Hi @Subhajitpanja

Yes this is quite possible and a good idea , Its like replay of option chain
do add this idea on

Have just completed episode 6 which is first algo. When I tried to execute the script. I got

MRF
intraday_minute_data() missing 2 required positional arguments: 'from_date' and 'to_date'
Traceback (most recent call last):
  File "/Users/raj/Desktop/workstation/personal/trading-view/algo/dhanDocs/3. Session3 - Codebase/Dhan codebase/Dhan_Tradehull.py", line 253, 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'
Traceback (most recent call last):
  File "/Users/raj/Desktop/workstation/personal/trading-view/algo/dhanDocs/3. Session3 - Codebase/Dhan codebase/firstAlgo.py", line 29, in <module>
    chart['rsi'] = talib.RSI(chart['close'], timeperiod=14) #pandas
TypeError: 'NoneType' object is not subscriptable

I just looked into function intraday_minute_data which is expecting 2 params.
Can you check for me, please?

same problem @Tradehull_Imran

Sir, Can you please share the file,

Thank you
VBR Prasad