Sir, can we get order book data in algo trading? Specifically, how many orders are placed at different levels for limit orders and market orders? If so, could you please provide more details?
By the way, sir, this has been an incredibly interesting journey—from staring at the laptop screen for 4–5 hours, dealing with losses, to transitioning into algo trading, which is more accurate, fast, disciplined, and efficient. Your guidance has truly made a difference, and we’re grateful for everything you’ve taught us.
With algo trading, it feels like we’ve moved from emotional decision-making to a structured, rule-based approach that eliminates impulsive trades and optimizes execution speed. The reliability of data-driven strategies has made the process smoother, reducing stress and increasing consistency.
Thank you for sharing your knowledge and helping us improve our trading approach!
Hi, Very Good Afternoon, Can you please confirm your code of Trailing_stop_loss, is functional.
I am a Non-Coder, trying to learn , Can you please help me out with some Functional Codes, especially Options trading, And Intraday trading of Equity segment, with your terms please.
Also please let me know about your success in implementing the Trailing stop loss code (Dt.07/02/2025)
VBR Prasad, 9949324446
how to measure the efficiency of the code. Even my 300 line codes take roung 10 secs to complete one loop. With the kinda of market movement - there is high chance that I will miss the entry window (my code has self-developed indicator - with a small price range for entry). Also, SL trailing will also be concern.
More on SL trailing. in you SL trailign videos, ATR based trailing seems to be good but even if I keep the conservative 1.5*ATR (it’s coming around roughly 25 to 30 points on 170-200 rupees options (100 OTM) like today and when the price movement is fast, ATR increases & the SL slowly trails. We might be missing out big on this. We rarely see very big move to get the benefit of this. Success ratio is very less. Also, I want to do ATR trailing based backtesting - can you help me with any books, codes, resources. Or - can you suggest any other method of SL trailing → or diret me to right direction. (btw - I do option buying)
Yes, my code is functional, but it’s too complex to explain.
Trailing stop loss alone is 1800 line code.
I have implemented different kinds of stop losses like dynamic trailing, fixed trailing, fixed trailing with profit, and safety_net, High oi strikes, paper trading, buy dip feature and API lag fallbacks.
if you are interested in above mentioned feature or similar kinds of features, I can guide you. and also share my code.
if you are looking for a normal trailing stop loss, better stick with Dhan Super Trader function, which would be the easiest and has no maintenance code, which is also available in API, it’s 2-3 lines of code added to the original order placement function.
With that, you can input trailing jump, take profit, and take loss altogether.
tsl.modify_order() is giving constatnt error of an unexpected keyword argument ‘order_id’. Here is my simple code just to check order placement. Can anyone help here. Are you also getting this? @Tradehull_Imran@RahulDeshpande
import pdb
import time
import datetime
import traceback
import pandas as pd
from pprint import pprint
from Dhan_Tradehull_V2 import Tradehull
Thanks for your Prompt Reply Sir. AS a learner, I am interested to have your code with Different Nomenclatures. My Mail ID is: vbrajprasad@gmail.com, Mob:9949324446
Thank you very much.
I have a code that scans stocks whose current price > prev day high, the code is as below, in order to achieve the results can i replace get_historical_data() with get_ltp_data() ??
import pdb
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
import talib
import time
import datetime
live_pnl = tsl.get_live_pnl()
current_time = datetime.datetime.now().time()
if current_time < datetime.time(9, 15):
print("wait for market to start", current_time)
continue
if (current_time > datetime.time(14, 30)) or (live_pnl < max_loss):
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(1)
print(stock_name)
chart_1 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="1")
chart_5min = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="5") # this call has been updated to get_historical_data call,
chart_15 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="15") # this call has been updated to get_historical_data call,
chart_daily = tsl.get_historical_data(tradingsymbol = stock_name,exchange ='NSE', timeframe="DAY")
if (chart_1 is None) or (chart_5min is None) :
continue
if (chart_1.empty) or (chart_5min.empty):
continue
if (chart_15.empty) or (chart_15.empty):
continue
if (chart_15 is None) or (chart_15 is None) :
continue
if (chart_daily.empty) or (chart_daily is None):
continue
# Conditions that are on 5 minute timeframe
chart_5min['ema20'] = talib.EMA(chart_5min['close'], timeperiod=20)
chart_5min['ema50'] = talib.EMA(chart_5min['close'], timeperiod=50)
chart_5min['ema100'] = talib.EMA(chart_5min['close'], timeperiod=100)
chart_5min['ema200'] = talib.EMA(chart_5min['close'], timeperiod=200)
# Get previous and current day's data
prev_day = chart_daily.iloc[-2]
curr_day = chart_daily.iloc[-1]
cc_5 = chart_5min.iloc[-1] #pandas completed candle of 5 min timeframe
ema_condition = (cc_5['ema20'] > cc_5['ema50']) and (cc_5['ema20'] > cc_5['ema100']) and (cc_5['ema20'] > cc_5['ema200'])
high_breakout = curr_day['high'] > prev_day['high']
no_repeat_order = stock_name not in traded_wathclist
max_order_limit = len(traded_wathclist) <= max_trades
if high_breakout and ema_condition and no_repeat_order and max_order_limit:
print(stock_name, "is in uptrend, Buy this script")