Learn Algo Trading with Python | Codes | Youtube Series

requesting @Dhan @Tradehull_Imran to update the playlist of Algo Trading series as existing playlist contains outdated stuffs causing most of the errors for who is a beginer.

Thank you

2 Likes


This error

1 Like


still getting error @Tradehull_Imran after using V2

@Tradehull_Imran Sir, An error occurs when we try to retrieve options Greeks data.

all_values = tsl.get_option_greek(51300, ‘29-01-2025’, ‘BANKNIFTY’, 10, ‘all_val’, ‘CE’)

I think you should try storing it in a variable

aa = 11
print("aa",aa)

and can then apply operations on it

aa = 11
print("aa",aa*11)
1 Like

Is this Course Series available in English?, In Dhan youtube channel , the videos only in Hindi available

@Tradehull_Imran Sir,

Gettiing error

after using dhancode base ratelimit, getting GMRINRA stock name by default and below error.

D:\my_applications\my_algo\Strategies>py “2 candle theory Algo.py”
Codebase Version 2.2 : Rate Limits
-----Logged into Dhan-----
reading existing file all_instrument 2024-12-29.csv
Got the instrument file
Error processing GMRINFRA: No expiry date found for GMRINFRA
Traceback (most recent call last):
File “2 candle theory Algo.py”, line 37, in
if (index_chart == None):
File “D:\my_applications\python\lib\site-packages\pandas\core\generic.py”, line 1466, in nonzero
raise ValueError(
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

D:\my_applications\my_algo\Strategies>

Hello sir
Sir paper trading ke liye kya algo ban sakta hai , please algo test karene k liye bahut zaroori Hai. Please sir help

1 Like

@Tradehull_Imran
How can I install libraries on macOS? Are there any libraries and the required .whl files available for MacOS?

Imran Sir,
आप Python 3.8 Version में क्‍यों बता रहे है जबकि Python 13.3.0 version आ गया है साथ ही आप पहले सारे program को sublime में बता रहे थे फिर बाद में VS Code में बता रहे हो। जब आप बता रहे है तो सभी में एक रूपता रखिये ताकि कुछ तो समझ आये।

1 Like

with new codebase, you dont specify expiry date,
now it works like currect expiry = 0, next expiry = 1
dont write actual date in expiry (‘29-01-2025’,)

2 Likes

:+1:

Hi @SUDHANSU_SEKHAR_MAHA

Do check if you have subscribed to Data api and its not expired.

Hi @Kanha_Meher

use below code

   all_values = tsl.get_option_greek(strike=24400, expiry=0, asset='NIFTY', interest_rate=10, flag='all_val', scrip_type='CE')

Get Option Greek

  • tsl.get_option_greek(strike: int, expiry: int, asset: str, interest_rate: float, flag: str, scrip_type: str)
  • Arguments:
    • strike (int): The strike price of the option.
    • expiry (int): The expiry to select.
      • 0 - Current week/month (depending on expiry type).
      • 1 - Next week/month (depending on expiry type).
    • and so on for subsequent weeks/months.
    • asset (str): The underlying asset for the option (e.g., ‘NIFTY’).
    • interest_rate (float): The interest rate to be used in calculations (e.g., 10).
    • flag (str): The Greek value to fetch.
    • ‘price’ - Option price.
    • ‘delta’ - Delta value.
    • ‘delta2’ - Second-order delta.
    • ‘theta’ - Theta value.
    • ‘rho’ - Rho value.
    • ‘vega’ - Vega value.
    • ‘gamma’ - Gamma value.
    • ‘all_val’ - All Greeks values in a dictionary.
    • scrip_type (str): The option type (‘CE’ for Call options, ‘PE’ for Put options).
  • Returns:
    • Depending on the flag, it returns the requested Greek value or all Greek values in a dictionary.
1 Like

Hi @logi

Yes as of now sessions are mainly in Hindi with bit of English mixed.

Hi @Arun_Rawat

Do use this updated version : Dhan_Tradehull_V2.py - Google Drive

Hi @avinashkumar07412

Yes, we have created paper trading code , this will be covered in upcoming Advance Algo trading series in depth.

2 Likes

Hi, @Tradehull_Imran , Sir…

For scanning each stock it take almost 5 secs, sir. Please check the screenshot.

Faced Same problem earlier , but you have guided me to resolve the issue by using LTP .

Please check it , sir…

import pdb
import time
import datetime
import traceback
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
from pprint import pprint
import talib
import pandas_ta as pta
import pandas_ta as ta
import warnings
warnings.filterwarnings("ignore")
#-----------------------------------------------------------------------------------
client_code = "11"
token_id    = "11"
tsl = Tradehull(client_code,token_id)
#----------------------------------------------------------------------------------
available_balance = tsl.get_balance()
max_loss = available_balance * -0.03				#  max loss of 3%
#-----------------------------------------------------------------------------------------
#watchlist = ['AARTIIND', 'ABB', 'ADANIENT', 'ADANIPORTS', 'APOLLOHOSP', 'ASIANPAINT', 'AUROPHARMA', 'AXISBANK', 'BAJAJ-AUTO', 'BAJAJFINSV', 'BAJFINANCE', 'BEL', 'BHARTIARTL', 'BPCL', 'BRITANNIA', 'CHOLAFIN', 'CIPLA', 'COALINDIA', 'CUMMINSIND', 'DLF', 'DRREDDY', 'EICHERMOT', 'GRASIM', 'HCLTECH', 'HDFCBANK', 'HDFCLIFE', 'HEROMOTOCO', 'HINDALCO', 'HINDUNILVR', 'ICICIBANK', 'INDUSINDBK', 'INFY', 'ITC', 'JSWSTEEL', 'KOTAKBANK', 'LT', 'M&M', 'MARUTI', 'NESTLEIND', 'NTPC', 'ONGC', 'POWERGRID', 'RELIANCE', 'SBILIFE', 'SBIN', 'SHRIRAMFIN', 'SUNPHARMA', 'TATACONSUM', 'TATAMOTORS', 'TATASTEEL', 'TCS', 'TECHM', 'TITAN', 'TRENT', 'ULTRACEMCO', 'WIPRO']
watchlist = ['AARTIIND', 'ABB', 'ASIANPAINT', 'AUROPHARMA', 'AXISBANK', 'BAJAJ-AUTO', 'BAJAJFINSV', 'BAJFINANCE', 'BHARTIARTL', 'CHOLAFIN', 'CIPLA', 'COALINDIA', 'DLF', 'DRREDDY', 'EICHERMOT', 'HCLTECH', 'HDFCBANK', 'HDFCLIFE', 'HEROMOTOCO', 'HINDALCO', 'HINDUNILVR', 'ICICIBANK', 'INDUSINDBK', 'INFY', 'JSWSTEEL', 'KOTAKBANK', 'LT', 'M&M', 'MARUTI', 'NESTLEIND', 'NTPC', 'ONGC', 'POWERGRID', 'RELIANCE', 'SBILIFE', 'SBIN', 'SHRIRAMFIN', 'SUNPHARMA', 'TATACONSUM', 'TATAMOTORS', 'TATASTEEL', 'TCS', 'TECHM', 'TITAN', 'TRENT', 'ULTRACEMCO', 'WIPRO']
traded_wathclist = []
#-----------------------------------------------------------------------------------------------------
while True:
	live_pnl = tsl.get_live_pnl()
	current_time = datetime.datetime.now().time()

	if current_time < datetime.time(0, 15):
		print("Wait for market to start", current_time)
		time.sleep(1)
		continue

	if (current_time > datetime.time(23, 10)):
		order_details = tsl.cancel_all_orders()
		print("Market is over, Bye Bye see you tomorrow", current_time)
		break

	for stock_name in watchlist:
		time.sleep(0.1)
		current_time = datetime.datetime.now().time()
		print(f"Scanning {stock_name}, Time: {current_time}")

		# ORB Conditions -------------------------------------------
		chart_5 = tsl.get_historical_data(tradingsymbol=stock_name, exchange='NSE', timeframe="5")
		chart_d = tsl.get_historical_data(tradingsymbol=stock_name, exchange='NSE', timeframe="DAY")
		pv_5    = chart_5.iloc[-2]			# pervious_candle_5
		pv_d    = chart_d.iloc[-1]			# pervious_candle_d
		no_repeat_order  = stock_name not in traded_wathclist
		
		# 1) Price Action    ------------------------------------------------------------
		pv_5_close = pv_5['close']  # Close price of previous 5-min candle
		pv_d_high  = pv_d['high']    # High price of previous day candle
		pv_d_low   = pv_d['low']    # Low price of previous day candle

		# Calculate percentage increase from previous day's high to previous 5-min candle close
		percentage_increase = ((pv_5_close - pv_d_high) / pv_d_high) * 100
		percentage_decrease = ((pv_5_close - pv_d_low) / pv_d_low) * 100

		ut_1 = 0.3 <= percentage_increase <= 0.98				# Check if the increase is between range
		dt_1 = -0.98 <= percentage_decrease <= -0.3 			# Check if the decrease is between range

		# 2) Linear Regression Slope -------------------------- apply indicators-----------------------------------
		chart_5['LINEARREG_SLOPE']     = talib.LINEARREG_SLOPE(chart_5['close'], timeperiod=9)
		cc_1            = chart_5.iloc[-2]  
		ut_2			= cc_1['LINEARREG_SLOPE'] >= 0
		dt_2			= cc_1['LINEARREG_SLOPE'] <= 0

		# BUY conditions ------------------------------------------------------------------------------
		if ut_1 and ut_2 and no_repeat_order:
			print(stock_name, "is in uptrend, Buy this script")
			qty 		= 1
			pv_5    	= chart_5.iloc[-2]
			entry_price = pv_5
			entry_orderid = tsl.order_placement(stock_name, 'NSE', qty, 0, 0, 'MARKET', 'BUY', 'MIS')
			traded_wathclist.append(stock_name)

		# SELL conditions -----------------------------------------------------------------------------
		if dt_1 and dt_2 and no_repeat_order:
			print(stock_name, "is in downtrend, Sell this script")
			qty = 1
			pv_5    	= chart_5.iloc[-2]
			entry_price = pv_5
			entry_orderid = tsl.order_placement(stock_name, 'NSE', qty, 0, 0, 'MARKET', 'SELL', 'MIS')
			traded_wathclist.append(stock_name)

Hi @Kanha_Meher

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

Hi @Anil_Dhruw

Python 3.8 has been widely used and extensively tested, so most libraries are stable and compatible with it. Some libraries may lag in supporting newer Python versions, like TA-lib , particularly for major releases like Python 13.3.0.

Sublime Test or VS Code are just code editors, I am trying to integrate AI usage with Algo-trading which will make writing Algo easier, (So I need to test other Environments, as on sublime text its not possible).

2 Likes