Learn Algo Trading with Python | Codes | Youtube Series

Hello @Tradehull_Imran,
i have started session 3, and i am getting error as below cmd error code:

also the same is the issue with historical data call.
below is the error showing in cmd :

 File "C:\Users\arpan\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py", line 817, in __init__
    raise ValueError("DataFrame constructor not properly called!")
intraday_minute_data() missing 2 required positional arguments: 'from_date' and 'to_date'
Traceback (most recent call last):
  File "C:\Users\arpan\Dhan Algo\Session 3\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py", line 252, 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'
[0] > c:\users\arpan\dhan algo\session 3\3. session3 - codebase\3. session3 - codebase\dhan codebase\dhan_codebase usage.py(28)<module>()

also sir, there is problem in loading dataframe.
df = pd.DataFrame(ohlc[ā€˜data’]) is not loading. its showing error. please once run it on your pc as well sir and tell me where is the issue.

here is my folder link : Dhan codebase – Google Drive
I request you @Tradehull_Imran please rectify this problem and provide me with the rectified code.

Thank you very much sir.

VBR Prasad

Thank you very much for your clarification sir.

VBR Prasad

Good Afternoon sir,
This is what exactly I was asking (to post a Final Folder containing all Proven Files).

Thank you sir,
VBR Prasad

Hi, @Tradehull_Imran, Sir , Below is my folder link

https://drive.google.com/drive/folders/17j7QL67Yg9vSf72BsoZov6NsXYxqnpbj?usp=sharing

My 2 Algos where running from 9.20 to 1.30 Today, Usually I will run only one Algo from 9.20 and around 12.20 the Rate Limit Error Message , Will come…

But Toady after using 2 Algos , the message came around 1.30… :+1:

1 Like

Thank you, sir… Eager to use SQN indicator.

Will be waiting for the Live Webinar Folder…

hello @Tradehull_Imran,
How to resolve this error ?

(Pdb++) previous_hist_data = tsl.get_historical_data('ACC','NSE',12)
DataFrame constructor not properly called!
Traceback (most recent call last):
  File "C:\Users\arpan\AppData\Local\Programs\Python\Python38\lib\cmd.py", line 214, in onecmd
    func = getattr(self, 'do_' + cmd)
data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\arpan\Dhan algo\Session 3\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py", line 222, in get_historical_data
    df = pd.DataFrame(ohlc['data'])
  File "C:\Users\arpan\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py", line 817, in __init__
    raise ValueError("DataFrame constructor not properly called!")
ValueError: DataFrame constructor not properly called!

Hi @Rajashekhar_Rangappa @Arpan_Shah

we need to upgrade the codebase for this. as the Historical data and Ltp was upgraded

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

Also do let me know if you face any issue after implementing this

@Vasili_Prasad
do check this folder : 1. Api Upgrade.zip - Google Drive

Hi @Kishore007
Then this file seems to be working fine

you can increase the sleep time

see

line 374, inside get_ltp_data function increase the time.sleep(2) to time.sleep(2.5)
line 274, inside get_historical_data function increase the time.sleep(1.5) to time.sleep(2.5)

1 Like

Hi @Kishore007

until the upload, below are the files for SQN

filename : sqn_lib.py

import pandas as pd
import datetime
import pdb
import math


def market_type(num):
	if num > 1.47:
		return "very_bullish"

	if 0.75 < num < 1.46:
		return "bullish"

	if 0 < num < 0.74:
		return "neutral"

	if -0.7 < num < 0:
		return "bearish"

	if num <= -0.7:
		return "very_bearish"


def sqn(df, period):
	df['pnl_sqn'] = ((df['close'] - df['open']) / df['open'])*100
	df['average_pnl'] = df['pnl_sqn'].rolling(period).mean()
	df['average_std'] = df['pnl_sqn'].rolling(period).std()
	name = 'sqn'
	df[name] = (math.sqrt(period)*df['average_pnl'])/df['average_std']
	df = df.drop(columns=['pnl_sqn', 'average_pnl', 'average_std'], inplace=True)
	return df



# Implementation
# sqn_lib.sqn(df=df, period=21)
# df['market_type'] = df['sqn'].apply(sqn_lib.market_type)

usage example


watchlist = ['ADANIPORTS', 'ADANIENT', 'SBIN', 'TATASTEEL', 'BAJAJFINSV', 'RELIANCE', 'TCS', 'JSWSTEEL',  'HCLTECH', 'TECHM']

chart = tsl.get_historical_data(tradingsymbol = name,exchange = 'NSE',timeframe="DAY")


for name in watchlist:

    chart = tsl.get_historical_data(tradingsymbol = name,exchange = 'NSE',timeframe="5")
    sqn_lib.sqn(df=chart, period=21)
    chart['market_type'] = chart['sqn'].apply(sqn_lib.market_type)

    last_candle = chart.iloc[-1]
    market_type = last_candle['market_type']

    print(f"Market Type for {name} is {market_type}")


1 Like

Hi @Arpan_Shah

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

also do upload the complete error screenshot, Thus I am able to see the codebase version being used

Thank you, sir…

Will check and test it, sir…!

Hello @Tradehull_Imran Sir,

  1. I am facing issue with getting historical data for SENSEX Option data. Please help me that.
    Code I am using:
previous_historical_data = tsl.get_historical_data('SENSEX 06 DEC 81100 PUT','FNO','5')
print("Historical Data of SENSEX: ", previous_historical_data)

Error I am getting:

Exception in Getting OHLC data as 'FNO'
Historical Data of SENSEX:  None
  1. Also how can I made trailing stoploss?
    I am using:
new_sl = 45
orderid2 = tsl.order_placement('BANKNIFTY 24 DEC 55500 CALL','NFO',15, new_sl , 0, 'LIMIT', 'BUY', 'MIS')
  1. If I apply new trailing stoploss, then is it required to cancel previous stoploss or how to implement that?

Please help.

Thanks in advance.
Sudip

Strategy Backtesting ke liye bhi 1 session kariye.

1 Like

hello, sir, when I want to get ā€œM&MFINā€ historical data, i get this error,


Is there any other type of symbol i have to use, Thanks

I’m Waiting for back testing video series.

2 Likes

Me too Me too
So far, we have learned Algo Trading, that we can implement and do forward testing, but we can wipe out our capital in that process. So, learning to backtest is key to success. Totally Agree with you @Tradehull_Imran ā€œ:anatomical_heart: Heart of Algo Trading : Backtestingā€

1 Like

hello @Tradehull_Imran

Please let me know, where to get this codebase version 2.2 : rate limit file??