Learn Algo Trading with Python | Codes | Youtube Series

Hi @TAPAS_KUMAR_DUTTA

create a new api… and delete/revoke the previous Trading API

try with the new token_id

1 Like

Hi @Abhishek_Pawde

Use below code

   CE_symbol_name, PE_symbol_name, strike_price = tsl.ATM_Strike_Selection(Underlying='NIFTY', Expiry=0)

Get ATM Strikes

  • tsl.ATM_Strike_Selection(Underlying: str, Expiry: int)
  • Arguments:
    • Underlying (str): The index or instrument name for which you want to find the ATM strike prices (e.g., ‘NIFTY’, ‘BANKNIFTY’).
    • 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.
  • Returns:
    • CE_symbol_name (str): The option symbol for the Call strike.
    • PE_symbol_name (str): The option symbol for the Put strike.
    • strike (int): The ATM strike price.
2 Likes


chart date 14-01-2024

time for execution of trade after closing of 9:25 am candle
time frame : 5min

Indicator : VWAP
mark spot price at 9:25 for ATM strike detection
Now sell straddle as and when it closes below VWAP or if already below still good, initial Sl can be set at 20-25 points or recent high made in straddle price.

Target should be 1:2 or we can do some mindful backtesting for sl trailing options.

For Sl trailing I use ema 21 , my sl initiall is recent high or 25points, after it comes in profit of 10 point i use EMA 21 if its below or at selling price i trail according to it in every 5min closing.

Number of entry : 2 in a day if sl touch 2nd entry criteria will be same

Straddle chart of today


https://www.icharts.in/
for todays trade it gave 50 point touching sl.

We can connect through google meet or zoom , if needed for better understanding.

sir, @Tradehull_Imran can u share your email id

3 Likes

Hye Sir @Tradehull_Imran :

Pnl issue:
when I use Dhan trade hull V2 provided with last video 4th live algo session code:
live_pnl = tsl.get_live_pnl()
Live PnL: -10876500.0

and When I Use Dhan trade hull V2 you have uploaded in google drive:
then live pnl =0

but actual pnl is not displayed

Ok sir thanks, I am running single algo but on multiple scripts watchlist of around 30 stocks.

Hello @Tradehull_Imran Sir,

Mothercandle strategy with volume breakout

Rules
Time Frame - 15 min
Indicators - Volume, and RSI
Screener that scans NIFTY500 or NIFTY200 for Mothercandle structure after 3rd completed candle.
Watchlist to have 3-5 stocks based on screener results
Rule :
Strategy to begin at 10 am
the first candle of the day is the Mothercandle which should be around 1-2 % in size.
the subsequent 2nd and 3rd should be child candle
the candle that gives BO or BD should have 2x volume > Mothercandle and RSI>60 for BO and RSI<40 for BD
SL - Low of Mothecandle about 1-2%
TSL - 0.5%
Risk Reward minimum 1:1

example attached is of AMBUJA CEMENT and MINDA CORP

3 Likes

its working

Yes Its working now. There was some problem with token.

Hi @Zee2Zahid

There is wrong ltp issue in pnl as of now, We will release a update soon.

Hi @Tradehull_Imran Sir,

Could you please help me with a code in your framework for the following logic?

If the first trade hits the target, no further trades for the day, and the kill switch is activated.

If the first trade results in a loss, we get two more chances to trade, making a maximum of three trades in total for the day.

Thank you!

@Tradehull_Imran Sir, mere setup ka backtesting codes please share karna if you do.

1 Like

Hi @CHETAN_99 ,

Dhan will be launching an advanced algorithmic trading series in the upcoming sessions. You can refer to those videos, which will make it easier for you to implement your logic afterward.

6 Likes

@TAPAS_KUMAR_DUTTA It seems you have not subscribed DATA API. You need to subscribe DATA API in order to access historical data which sqn script. Ref error type and error message in your screen. It has already mentioned the same.

1 Like

@Tradehull_Imran Waiting eagerly on this advanced algorithmic series. Do share the you tube playlist link.

Also if you share some update on back testing through python script, would be helpful to align the same. Hope things are progressing. Thanks in advance.

1 Like

@urbadgu Buddy, Thanks for your insight. But It is solved now. Data API was subscribed, but another token needed to be created. But Its working fine now.

1 Like

@Tradehull_Imran
Hi Sir,
I am getting error after the buy or sell signal formed.


Please help me to resolve this

Hi @urbadgu ,

Advanced algorithmic series will be released soon. Tagging @RahulDeshpande for more information.

2 Likes

Hi @rohit2312 ,

Refer below code:

Get OTM Strikes

  • tsl.OTM_Strike_Selection(Underlying: str, Expiry: int, OTM_count: int)
  • Arguments:
    • Underlying (str): The index or instrument name for which you want to find the OTM strike prices (e.g., ‘NIFTY’, ‘BANKNIFTY’).
    • 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.
    • OTM_count (int): The number of steps to move away from the ATM strike to find the OTM strike prices (e.g., 5 means 5 steps away).
  • Returns:
    • CE_symbol_name (str): The option symbol for the OTM Call strike.
    • PE_symbol_name (str): The option symbol for the OTM Put strike.
    • CE_OTM_price (int): The OTM Call strike price.
    • PE_OTM_price (int): The OTM Put strike price.
CE_symbol_name, PE_symbol_name, CE_OTM_price, PE_OTM_price = tsl.OTM_Strike_Selection(Underlying='NIFTY', Expiry=0, OTM_count=5)

do use this upgraded codebase file : Dhan_Tradehull_V2.py - Google Drive

Hello @Tradehull_Imran sir, i take trades manually and i want to take only one trade per day. So, to avoid over trading i am using below mentioned code, it is working fine, but, some times it is showing the error. Please solve this issue. I am using latest codebase version 2.6

import pdb
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
import talib
import time
import datetime

client_code = “”
token_id = “”

tsl = Tradehull(client_code,token_id)

available_balance = tsl.get_balance()

trade_book = tsl.get_trade_book()

length = len(trade_book)

print(“Available balance:”, available_balance)

print(“No. of trades:”, length)

max_trades = 2

while True:

trade_book = tsl.get_trade_book()

length = len(trade_book)
	
if len(trade_book) >= max_trades:
	exit_all = tsl.cancel_all_orders()
	stop_trading = tsl.kill_switch('ON')
	print("Kill switch activated (Max trades limit reached)")

It is showing the following error

Hi @Nagi_Reddy_Vanga ,

Do manage the exception and print the error in detail to look into this:

import traceback
try:
    trade_book = tsl.get_trade_book()
    length = len(trade_book)
    if len(trade_book) >= max_trades:
        exit_all = tsl.cancel_all_orders()
        stop_trading = tsl.kill_switch('ON')
        print("Kill switch activated (Max trades limit reached)")
except Exception as e:
	print(f"Exception occured as {e}")  
    print(traceback.format_exc())
    continue