sir while getting historical data exchange “INDEX” not working
getting error Exception in Getting OHLC data as ‘INDEX’
Sorry it was a silly mistake from my side.
Thank you sir, Thank you very much.
VBR Prasad
Hi@ tradehull_Imran…
Sir, your answer to my question has made me extremely happy. Teachers like you are rare in the education system. Without charging any fees, you provided a clear and knowledgeable response, proving your expertise. Thank you so much! I have another question… “can I write an algorithm that executes both call and put option trades simultaneously, based on different conditions?”
Hi, @Tradehull_Imran , Sir
While running my Algo with time.sleep(0.1), each stock take approx. 4 to 5 secs for scanning, I am scanning Nifty50 Stocks in one min. time frame, Please check the screenshot
how to reduce it to 2 secs, sir ?
because to scan all Nifty50 Stocks for one time , it take Approx 4 to 5 mins , then I will get no trades…
Please check my algo and do necessary changes.
Thank you, 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 = ['INFY', 'M&M', 'HINDALCO', 'DLF', 'TATASTEEL', 'NTPC', 'MARUTI', 'TATAMOTORS', 'ONGC', 'BPCL', 'WIPRO', 'SHRIRAMFIN', 'ADANIPORTS', 'JSWSTEEL', 'COALINDIA', 'ULTRACEMCO', 'BAJAJ-AUTO', 'LT', 'POWERGRID', 'ADANIENT', 'SBIN', 'HCLTECH', 'TCS', 'EICHERMOT', 'BAJAJFINSV', 'TECHM', 'LTIM', 'HINDUNILVR', 'BHARTIARTL', 'AXISBANK', 'GRASIM', 'DRREDDY', 'ICICIBANK', 'HDFCBANK', 'BAJFINANCE', 'SBILIFE', 'RELIANCE', 'KOTAKBANK', 'ITC', 'TITAN', 'SUNPHARMA', 'INDUSINDBK', 'APOLLOHOSP', 'BRITANNIA', 'NESTLEIND', 'HDFCLIFE', 'DIVISLAB', 'CIPLA', 'ASIANPAINT', 'TATACONSUM']
traded_wathclist = []
#-----------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------
while True:
live_pnl = tsl.get_live_pnl()
current_time = datetime.datetime.now().time()
if current_time < datetime.time(00, 15):
print("Wait for market to start", current_time)
time.sleep(1)
continue
if (current_time > datetime.time(15, 00)) or (live_pnl < max_loss):
order_details = tsl.cancel_all_orders()
print("Market is over, 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}")
# Conditions on 1-minute timeframe-----------------------------------------------------------------
chart_1 = tsl.get_historical_data(tradingsymbol=stock_name, exchange='NSE', timeframe="1")
pervious_candle = chart_1.iloc[-2]
ltp = tsl.get_ltp_data(stock_name)[stock_name]
no_repeat_order = stock_name not in traded_wathclist
# 1) RSI ------------------------ apply indicators--------------------------------------
chart_1['rsi'] = talib.RSI(chart_1['close'], timeperiod=14)
cc_1 = chart_1.iloc[-2]
cc_2 = chart_1.iloc[-3]
ut_1 = cc_1['rsi'] > 60
dt_1 = cc_1['rsi'] < 40
# 2) Linear Regression Slope -------------------------- apply indicators-----------------------------------
chart_1['LINEARREG_SLOPE'] = talib.LINEARREG_SLOPE(chart_1['close'], timeperiod=9)
cc_1 = chart_1.iloc[-2]
cc_2 = chart_1.iloc[-3]
ut_2 = cc_1['LINEARREG_SLOPE'] >= 0
dt_2 = cc_1['LINEARREG_SLOPE'] <= 0
# 3) ADX -------------------------- apply indicators-----------------------------------
chart_1['adx'] = talib.ADX(chart_1['high'], chart_1['low'], chart_1['close'], timeperiod=14)
cc_1 = chart_1.iloc[-2] #pandas completed candle of 1 min timeframe
cc_2 = chart_1.iloc[-3]
adx = cc_1['adx'] >= 20
# BUY conditions ------------------------------------------------------------------------------
if ut_1 and ut_2 and adx and no_repeat_order:
print(stock_name, "is in uptrend, Buy this script")
#print(f"BUY {stock_name}\t{current_time}\t{ut_1}\t{ut_2}\t{adx}\t{ut_3}\t{ut_4}")
qty = 1
ltp = tsl.get_ltp_data(stock_name)[stock_name]
entry_price = ltp
entry_orderid = tsl.order_placement(stock_name, 'NSE', qty, 0, 0, 'MARKET', 'BUY', 'MIS')
traded_wathclist.append({'symbol': stock_name, 'entry_price': entry_price, 'direction': 'BUY'})
# SELL conditions -----------------------------------------------------------------------------
if dt_1 and dt_2 and adx and no_repeat_order:
print(stock_name, "is in downtrend, Sell this script")
#print(f"SELL {stock_name}\t{current_time}\t{dt_1}\t{dt_2}\t{adx}\t{dt_3}\t{dt_4}")
qty = 1
ltp = tsl.get_ltp_data(stock_name)[stock_name]
entry_price = ltp
entry_orderid = tsl.order_placement(stock_name, 'NSE', qty, 0, 0, 'MARKET', 'SELL', 'MIS')
traded_wathclist.append({'symbol': stock_name, 'entry_price': entry_price, 'direction': 'SELL'})
For Dhan_Tradehull_V2 new file the scan taking long time, shift previous file
Hi @Tradehull_Imran,
Today I am not getting any rate limit errors, haven’t changed or added anything in the code or used the latest dhan codebase version 2.3 still using the old codebase and it still works. I am not able to understand how yesterday the same code was giving rate limit error and today morning it’s working fine and I am testing the same code from 27th Nov. in the live market and haven’t faced any issues, except for yesterday.
Please help me understand why this happened so that this issue can be avoided in future.
Ops…
@Tradehull_Imran , Please update it accordingly, sir.
Please correct me, if I am wrong …
Running same strategy, same condition and same time frame, in code base 2.3 , I also removed sleep function
but if I change it to LTP for entries then it take 5 secs for scanning each stock
but when I use Pervious candle close for entries then it take 2 secs for scanning each stock…
Please provide a solution to scan Nifty 50 stocks in 1 min i.e, less than 60 secs in LTP or Previous candle close
New Dhan_Tradehull_V2.py not able to process the all_instrument 2024-12-11.csv , and it is failing again and again at SWANENERGY. @Tradehull_Imran Sir please look into this issue…
D:\Python_Project\Working Directory\NSE>py Multi_EQ_Buy_latest.py
Codebase Version 2.2 : Rate Limits
-----Logged into Dhan-----
This BOT Is Picking New File From Dhan
Got the instrument file
ERROR:root:Error while processing SWANENERGY: -2
ERROR:root:Error while processing SWANENERGY: -2
ERROR:root:Error while processing SWANENERGY: -2
ERROR:root:Error while processing SWANENERGY: -2
Hi @Tradehull_Imran,
Suppose if I want to find how much intraday margin dhan is providing for the stocks, like for e.g. on AWFIS only 1X margin is provided while on some 5x is provided.
which file is working? I tried the previous version too, that is also not working…
is it an issue with file or Dhan_Tradehull not able to understand…
@Tradehull_Imran Please look into the issue , nothing working
D:\Python_Project\Working Directory\NSE>py Multi_EQ_Buy_latest.py
-----Logged into Dhan-----
This BOT Is Picking New File From Dhan
Got the instrument file
ERROR:root:Error while processing PREMIERENE: -2
Same here, some time it throws rate limit error, after 12.00 AM it was reset
Please provide a solution to scan Nifty 50 stocks in 1 min i.e, less than 60 secs in LTP or Previous candle close
My Algo details are their in this post
Folks,
A surprise for everyone!
@Tradehull_Imran sir is back and recording the newest series
A lot of new videos, new learning’s & new concepts
What would you like us to cover more let us know👇
@Tradehull_Imran Sir, After 3.00 PM no data fetching until 12.00 AM
@Tradehull_Imran and @RahulDeshpande
Wow, Great, Please Upload those New videos as soon as possible, We are awaiting for it…
- How to manage multiple open position and tp/sl orders with trailing stop loss
- I will update my Excel sheet at EOD, Like below
this should act as Trade Info in my Algo For e.g. if OFSS LTP is above Buy Level , then it should scan for entries with other conditions like RSI cross over
Am working like this only, and am using dictionaries to handle multiple orders target/sl
Super excited
@Tradehull_Imran Sir today I have tested that