Learn Algo Trading with Python | Codes | Youtube Series

I am also facing issue in Mult timeframe algo
single positional indexer is out-of-bounds

@Tradehull_Imran

Actually sir there is instability in running algos with v2. sometime it’s running sometimes it not … I have checked my api key subscription validity is 4days more but still not running. If possible pls make video on crude oil so we can work and study live on algos in evening.

Hi Everyone,

Below is the file update code for session8. 8. Session8- 2nd Live Algo.zip - Google Drive

The following issues are solved,

  1. Solved : Orders not getting Placed
    Reason : This is because kill switch may be accidently made ON during testing)
    Solution : As of now comment out kill switch, we can enable it when the testing is complete.

  2. Solved : File was not able to run continuously
    Reason : This is because of Historical api rate limits were getting exceeded,
    Solution : Now we have used time.sleep(1) to stay under the rate limit.

Important : Also do update me if this solution works fine

2 Likes

Hi @thakurmhn
This issue was mostly due to Kill switch getting enabled.

see Point 1 : Learn Algo Trading with Python | Codes | Youtube Series - #748 by Tradehull_Imran

Hi @Zee2Zahid
You can make any type of order placement using below mapping.

tsl.order_placement(stock_name,'NSE', 1, 0, 0, 'MARKET', 'BUY', 'MIS')
tsl.order_placement(tradingsymbol, exchange,quantity, price, trigger_price, order_type, transaction_type, trade_type)

Important : also see Parameters table in : Orders - DhanHQ Ver 2.0 / API Document

1 Like

Hi @Scooby_Doo
see this link : Learn Algo Trading with Python | Codes | Youtube Series - #706 by Tradehull_Imran

Hi @Kishore007
This issue was mostly due to Kill switch getting enabled.

see : Learn Algo Trading with Python | Codes | Youtube Series - #748 by Tradehull_Imran

Hi @Msk92
This issue has been solved, use the latest file now Learn Algo Trading with Python | Codes | Youtube Series - #748 by Tradehull_Imran

Hi @Naga_Rajesh_K

  1. Apply solution from this link : Learn Algo Trading with Python | Codes | Youtube Series - #706 by Tradehull_Imran

After applying Point 1 solution

  1. Apply solution from this link : Learn Algo Trading with Python | Codes | Youtube Series - #748 by Tradehull_Imran

Also for Supertrend see this link : Learn Algo Trading with Python | Codes | Youtube Series - #758 by Tradehull_Imran

Hi @rahulcse56

see below 2 links

@rejithkoroth @ddeogharkar @Aijaz_Ahmad @Priyesh_Sharma @sourabh_paswan @Gamma_Trader @Kuldeep_Khaladkar

For the issue in continuously running algo…

see the updated code : Learn Algo Trading with Python | Codes | Youtube Series - #748 by Tradehull_Imran

2 Likes

Hi @Priyesh_Sharma

for SL and Target question
see : Learn Algo Trading with Python | Codes | Youtube Series - #750 by Tradehull_Imran

Hi @Kishore007
See below code


# Conditions that are on 5 minute timeframe
chart_5        = tsl.get_intraday_data(stock_name, 'NSE', 5)       # 5 minute chart
chart_5         = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="5") # this call has been updated to get_historical_data call, 


indi = ta.supertrend(chart_5['high'], chart_5['low'], chart_5['close'], 7, 3)
chart_5 = pd.concat([chart_5, indi], axis=1, join='inner')


cc_5 		   = chart_5.iloc[-1]

ub_breakout    = cc_5['close'] > cc_5['SUPERTd_7_3.0']
lb_breakout    = cc_5['close'] < cc_5['SUPERTd_7_3.0']




--------------- Logical reference --------------------------


import pandas_ta as ta
indi = ta.supertrend(df['high'], df['low'], df['close'], 7, 3)
df = pd.concat([df, indi], axis=1, join='inner')
print(df)


'Column1 = this will give full supertrend line values'	trend
'Column2 = this will show if st is red or green'		direction
'Column3 = show values only for green nan for red'		long
'Column4 = show values only for red nan for green'		short

Hi @Harsh_Singh1

See high level code references

chart_5        = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="5")
chart_5['adx'] = talib.ADX(chart_5['high'], chart_5['low'], chart_5['close'], timeperiod=14)
chart_5['fastk'], chart_5['fastd'] = talib.STOCHRSI(chart_5['close'], timeperiod=14, fastk_period=5, fastd_period=3, fastd_matype=0)



For vwapuse below reference
	import pandas_ta as pta
	data.set_index(pd.DatetimeIndex(data['date']), inplace=True)
	data['vwap'] = pta.vwap(data['high'] , data['low'], data['close'] , data['volume'])



2 Likes

Hi @Lalith_Kumar

See : Learn Algo Trading with Python | Codes | Youtube Series - #748 by Tradehull_Imran

Hi @mrizzwanghazi
use updated code : Learn Algo Trading with Python | Codes | Youtube Series - #748 by Tradehull_Imran

Hi Sir, @Tradehull_Imran
I’m pleased to inform you that the script is running perfectly. Thank you for your support and assistance. It is now continuously running, and orders are being placed successfully.

1 Like

Today I will try both and update you Dhan api v2

And session 8

Problem getting consistent intraday or historical data in live market hours.

My algo is producing good Buy/Sell signals for index, however fetching intraday or historical data from api is not consistent. In between it stop providing data and DF fails with errors, even after setting sleep(1).

currently I am just monitoring with logging the signals but if I place order through api this will be huge risk
I am not sure if this is becuase of hiting api rate limit or any other problem, I am monitoring my script for last 3 days and see the same issue.
If it is hitting api rate limit then what is the solution? becuase if orders are getting placed in my absence then it will be huge risk, and purpose to learn and run algo is that we should be able to trade in our absence
Today I created new api token thinking that it will help but I can see the same issue … or else algo trading will never help

Error:

2024-11-14 14:07:23,211 - strategy_test-2.py - INFO - Current file name: strategy_test-2.py
2024-11-14 14:07:23,211 - strategy_test-2.py - INFO - This is an info message
2024-11-14 14:07:23,211 - root - INFO - Dhan.py started system
2024-11-14 14:07:23,211 - root - INFO - STARTED THE PROGRAM
-----Logged into Dhan-----
This BOT Is Picking New File From Dhan
Got the instrument file
2024-11-14 14:07:25,386 - root - ERROR - Error at getting start date as If using all scalar values, you must pass an index
Traceback (most recent call last):
File “/home/mohan/Dhan-Alog-Trading/examples/Dhan_Tradehull_V2.py”, line 218, in get_start_date
df = pd.DataFrame(ohlc[‘data’])
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohan/miniconda3/envs/dhan-test/lib/python3.12/site-packages/pandas/core/frame.py”, line 778, in init
mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohan/miniconda3/envs/dhan-test/lib/python3.12/site-packages/pandas/core/internals/construction.py”, line 503, in dict_to_mgr
return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohan/miniconda3/envs/dhan-test/lib/python3.12/site-packages/pandas/core/internals/construction.py”, line 114, in arrays_to_mgr
index = _extract_index(arrays)
^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohan/miniconda3/envs/dhan-test/lib/python3.12/site-packages/pandas/core/internals/construction.py”, line 667, in _extract_index
raise ValueError(“If using all scalar values, you must pass an index”)
ValueError: If using all scalar values, you must pass an index
If using all scalar values, you must pass an index
2024-11-14 14:07:25,772 - root - ERROR - Exception in Getting OHLC data as If using all scalar values, you must pass an index
Traceback (most recent call last):
File “/home/mohan/Dhan-Alog-Trading/examples/Dhan_Tradehull_V2.py”, line 259, in get_historical_data
df = pd.DataFrame(ohlc[‘data’])

there is no socket file only there thats y i said why don’t you provide some basic startegy which would working templates atleast like MACD cross or MA cross only working models at any condition this seems like need to take up the course i don’t see any one would got perfectly here out of 10 its 1 not more than got it i guess any ways i will quit is better option rather than begging