Learn Algo Trading with Python | Codes | Youtube Series

@Tradehull_Imran ,

Have been trying had to get along but facing issues.
Could you please help on the below.

  1. How do I get the Index, and Stock Future Data both historical & live market feed (OHLCV, OI, PCR, on a 1 min time frame.
  2. How can I get VIX data
  3. Market Depth - you mentioned in the previouspost that this is no working.

I really want to move forward with this. Can u please help me.

Note:

  • I am not using the Excel thing I am doing it on the screen itself.
  • I keep refereing to your codes but it is always handy to have reference document. however Dhan reference doc is limited to Version 2 and this is were the challange is for me.

Getting error in below line of code in session 6, money management.py script,

Blockquote
no_of_orders_placed = orderbook_df[orderbook_df[‘qty’] > 0].shape[0] + completed_orders_df[completed_orders_df[‘qty’] > 0].shape[0]

after running the commands in above line separately below is the output. why is completed orders portion throwing keyerror for ‘qty’ and how to fix it?

Blockquote
(Pdb++) orderbook_df[orderbook_df[‘qty’] > 0].shape[0]
0
(Pdb++) completed_orders_df[completed_orders_df[‘qty’] > 0].shape[0]
*** KeyError: ‘qty’
Traceback (most recent call last):
File “C:\Users\abcwin\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py”, line 3761, in getitem
indexer = self.columns.get_loc(key)
File “C:\Users\abcwin\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexes\range.py”, line 349, in get_loc
raise KeyError(key)

Please post your questions in forum and everyone here can try to help you.

Have you already completed all training videos?
Make sure you are using correct version of Tradehull support library.

Refer below video to install codebase:

Thanks!

Hi @Tradehull_Imran
Please see this, this error is coming.

Hi @Tradehull_Imran sir,
maine pdb laga ke check kiya data aa raha hai but at the end program nahi chal raha. exception bhi add kr diya tab bhi nahi resolve ho raha

This is the path of Dhan_Tradehull v3,
here for v3,
we are using library pip install Dhan-Tradehull to download it.

C:\Users\Admin\AppData\Local\Programs\Python\Python38\Lib\site-packages\Dhan_Tradehull

Else,
On the top of our script file we use the following line,
from Dhan_Tradehull import Tradehull
Here, you can click on from Dhan_Tradehull (VS Code Editor).
It will redirect to you to the file.

1 Like

Hi for the “expiry” parameter of the atm_strike_selection function, we need to pass the exact date of expiry ? or provide values like 0,1,2 for current expiry and so on ? which i saw in another post.
Which is it?

Hi @Msk92
For current expiry use 0
For next expiry 1 and so on

1 Like

@Tradehull_Imran Further, the tsl.get live pnl is returning some strange 10 digit high value which i am not able to relate back to my Dhan account. Kindly check & confirm.

Blockquote
live_pnl = tsl.get_live_pnl()
(Pdb++) tsl.get_live_pnl()
nnnnnnnnnn.n

@Tradehull_Imran
Did you get time to look into my request?

@anandc
Thank you for suggestion. I implemented it and its very easy to interpret now using color code and formatting.

2 Likes

@Tradehull_Imran Getting :point_down: all of a sudden

/Users/raj/Desktop/workstation/personal/trading/algo/dhan/zerobot_v4.py:136: UserWarning: Converting to PeriodArray/Index representation will drop timezone information.
  chart['vwap'] = pta.vwap(chart['high'], chart['low'], chart['close'], chart['volume'])
/Users/raj/Desktop/workstation/personal/trading/algo/dhan/zerobot_v4.py:136: UserWarning: Converting to PeriodArray/Index representation will drop timezone information.
  chart['vwap'] = pta.vwap(chart['high'], chart['low'], chart['close'], chart['volume'])
/Users/raj/Desktop/workstation/personal/trading/algo/dhan/zerobot_v4.py:136: UserWarning: Converting to PeriodArray/Index representation will drop timezone information.
  chart['vwap'] = pta.vwap(chart['high'], chart['low'], chart['close'], chart['volume'])
/Users/raj/Desktop/workstation/personal/trading/algo/dhan/zerobot_v4.py:136: UserWarning: Converting to PeriodArray/Index representation will drop timezone information.

Update:
It happens if I remove
warnings.filterwarnings("ignore")
from the algo. Have added it back

hi @Siddhesh_Amrute, please could you elaborate what this is and brief steps to implement this? ty.

@saurabha213
I have implemented Short Iron Butterfly Strategy using Algo for Nifty weekly expiry.
It is already explained in @Tradehull_Imran Advance Algo Trading Series available on YouTube.

This is just output of my ongoing trade. Whenever it will hit target or stop loss it will exit my trade.

Thanks!

2 Likes

Hi @SANJEEV_RANJAN ,

  1. Historical data :
data  = tsl.get_historical_data(tradingsymbol = 'INDHOTEL',exchange = 'NSE' ,timeframe="15")

OI data

name = 'NIFTY 03 APR 23200 CALL'
quote_data = tsl.get_quote_data(name) 
oi_data = quote_data[name]['oi']

PCR:

pcr = put_oi_data / call_oi_data

  1. India VIX:
ltp_data = tsl.get_ltp_data(["INDIA VIX"])
india_vix_ltp = ltp_data["INDIA VIX"]
  1. Currently Market Depth data is not accurately available.

Refer the below pypi link for more details:
https://pypi.org/project/Dhan-Tradehull/

1 Like

Hi @saurabha213 ,

Verify that ‘qty’ column is already present in the df before checking it. Cross verify using.

print(completed_orders_df.columns.tolist())

Hi @saurabha213 ,

Do update to our latest codebase version 3.0.6:

  • Open Command Prompt: Press Win, type cmd, and press Enter.
  • Install Dhan-Tradehull: Run pip install Dhan-Tradehull
  • Confirm the installation by running pip show Dhan-Tradehull

Guide to use the updated codebase:
Refer the below pypi link for more details:
https://pypi.org/project/Dhan-Tradehull/
Video reference :

1 Like

Hi @rohit2312 ,

Do share your code to review the same.

Hi @Tradehull_Imran sir, Please see the below code
import pdb
import time
import datetime
import traceback
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
import pprint
import talib
import pandas_ta as pta
import pandas_ta as ta

client_code = “”
token_id = “”
tsl = Tradehull(client_code,token_id)

watchlist = [‘ADANIPORTS’,‘ADANIENT’,‘SBIN’,‘TATASTEEL’,‘BAJAJFINSV’,‘RELIANCE’,‘TCS’,‘JSWSTEEL’,‘HCLTECH’,‘TECHM’,‘NTPC’]

for name in watchlist:

try:
	current_time = datetime.datetime.now()
	chart = tsl.get_historical_data(tradingsymbol = name,exchange = 'NSE',timeframe="5")

	# Calculate EMAs - 3-period EMA and 21-period EMA
	chart['EMA_5'] = ta.ema(chart['close'], length=5)
	chart['EMA_20'] = ta.ema(chart['close'], length=20)
	
	# make inicators rsi
	chart['rsi'] = talib.RSI(chart['close'], timeperiod=14)
	
	# CCI Indicator
	chart['CCI'] = talib.CCI(chart['high'], chart['low'], chart['close'], timeperiod=14)

	# completed_candle
	cc = chart.iloc[-2]

	# buy entry conditions
	bc1 = cc['EMA_5'] > cc['EMA_20']
	bc2 = cc['rsi'] > 60
	bc3 = cc['CCI'] > 100
	
	# pdb.set_trace()

	# sell entry conditions
	sc1 = cc['EMA_5'] < cc['EMA_20']
	sc2 = cc['rsi'] < 40
	sc3 = cc['CCI'] <-100

	if bc1 and bc2 and bc3:
		print("buy", name)

	if sc1 and sc2 and sc3:
		print("sell", name)
except Exception as e:
	print(e)
	pass

i tried to practice pdb.set_trace()
Is this right sir