facing problem DataFrame constructor not properly called!
Traceback (most recent call last):
File “C:\Users\Administrator\OneDrive\Desktop\Dhan\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 222, in get_historical_data
df = pd.DataFrame(ohlc[‘data’])
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\frame.py”, line 886, in init
raise ValueError(“DataFrame constructor not properly called!”)
ValueError: DataFrame constructor not properly called!
dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “C:\Users\Administrator\OneDrive\Desktop\Dhan\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 253, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id),exchangeSegment,instrument_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “C:\Users\Administrator\OneDrive\Desktop\Dhan\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 253, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id),exchangeSegment,instrument_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “C:\Users\Administrator\OneDrive\Desktop\Dhan\3. Session3 - Codebase\Dhan codebase\Dhan_codebase usage.py”, line 46, in
intraday_hist_data[‘rsi’] = talib.RSI(intraday_hist_data[‘close’], timeperiod=14)
^^^^^
NameError: name ‘talib’ is not defined
C:\Users\Administrator\OneDrive\Desktop\Dhan\3. Session3 - Codebase\Dhan codebase>
(1) pip install TA-Lib use stockoverflow (pip - Python TA-Lib install problems - Stack Overflow)
(2) notice your date format in code is YYYY-MM-DD hence your input needs to be in same format or you can use %d-%m-%y for 19-02-25 format
(3) also you need to see apke dataframe (df) me date time ka format kya aa rha h either you can use variable explorer if you are using spyder or use print(df.head()) after df = pd.DataFrame(ohlc[‘data’])
(4) code can be like
import pandas as pd
import talib
ohlc = self.Dhan.intraday_minute_data(str(security_id), exchangeSegment, instrument_type, from_date=‘2023-10-01’, to_date=‘2023-10-31’)
print(ohlc[‘data’])
df = pd.DataFrame(ohlc[‘data’])
df[‘rsi’] = talib.RSI(df[‘close’], timeperiod=14)
1 Like
Dear Sir, I have created a logic for QQE Indicator especially Fast and Slow lines want to verify if Iam correct, some more conditions to be added and oredering sequence to be added. at present it is a scanner. May please check.
import pdb
from Dhan_Tradehull import Tradehull
import pandas as pd
import talib
from pprint import pprint
#import sqn_lib
import time
import datetime
import traceback
import talib
import pandas_ta as pta
import pandas_ta as ta
import warnings
warnings.filterwarnings("ignore")
client_code = "1xxxxx4"
token_id = "exxxx"
tsl = Tradehull(client_code,token_id)
traded = "no"
trade_info = {"options_name":None, "qty":None, "sl":None, "CE_PE":None}
while True:
current_time = datetime.datetime.now()
QQE = 4.236
#nifty_chart = tsl.get_historical_data(tradingsymbol ='NIFTY FEB FUT', exchange = 'NFO', timeframe ="5")
nifty_fut = tsl.get_historical_data(tradingsymbol ='NIFTY FEB FUT', exchange = 'NFO', timeframe ="5")
nifty_ltp = tsl.get_ltp_data(names = ['NIFTY FEB FUT'])['NIFTY FEB FUT']
# rsi ------------------------ apply indicators
nifty_fut['rsi'] = talib.RSI(nifty_fut['close'], timeperiod=14)
#------------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------------
# volume
volume = 50000
# QQE Fast RSI calculations ------------------------------------------------------------------
nifty_rsi = talib.RSI(nifty_fut['close'], timeperiod = 14) # RSI
fast_rsi= talib.EMA(nifty_rsi, 5) - 50 # Fast RSI i.e smoothen RSI --------------------------------
first_candle = nifty_fut.iloc[-3]
second_candle = nifty_fut.iloc[-2]
running_candle = nifty_fut.iloc[-1]
delta = abs(fast_rsi - fast_rsi.shift(1))
ema_1=talib.EMA(delta, 27)
ema_2 = talib.EMA(ema_1,27)
slow_rsi = ema_2* QQE # SLOW RSI ------------------------------------------
first_fast_rsi =fast_rsi.iloc[-3]
second_fast_rsi =fast_rsi.iloc[-2]
running_fast_rsi =fast_rsi.iloc[-1]
first_slow_rsi =slow_rsi.iloc[-3]
second_slow_rsi =slow_rsi.iloc[-2]
running_slow_rsi =slow_rsi.iloc[-1]
# ---------------------------- BUY ENTRY CONDITIONS ----------------------------
bc1 = first_fast_rsi < first_slow_rsi
bc2 = second_fast_rsi > second_slow_rsi
bc4 = first_candle['rsi'] < 80 # First candle RSI < 80
bc5 = second_candle['volume'] > 50000 # Second candle Volume should be greater than 50,000 for Nifty and above 125,000 for Bank Nifty
bc6 = traded == "no"
bc7 = nifty_ltp > first_candle['low']
print(f"BUY \t {current_time} \t {bc1} \t {bc2} \t {bc4} \t {bc5} \t {bc7} \t first_candle {str(first_candle['timestamp'].time())}")
# ---------------------------- SELL ENTRY CONDITIONS ----------------------------
sc1 = first_fast_rsi > first_slow_rsi
sc2 = second_fast_rsi < second_slow_rsi
#sc3 = first_candle['close'] < first_candle['vwma']
sc4 = first_candle['rsi'] > 20 # First candle RSI > 20
sc5 = second_candle['volume'] > 50000 # Second candle Volume should be greater than 50,000 for Nifty and above 125,000 for Bank Nifty
sc6 = traded == "no"
sc7 = nifty_ltp < first_candle['high']
print(f"SELL \t {current_time} \t {sc1} \t {sc2} \t {sc4} \t {sc5} \t {sc7} \t first_candle {str(first_candle['timestamp'].time())} \n")
if bc1 and bc2 and bc4 and bc5 and bc6 and bc7:
print("Buy Signal Formed")
pdb.set_trace()
if sc1 and sc2 and sc4 and sc5 and sc6 and sc7:
print("Sell Signal Formed")
pdb.set_trace()
I have another indicator Xtrend which I wanted in python, because Xtrend alongwith QQE is a better combination. Xtrend is bit complicated in logic to understand.
use ai tools to code but a bit first try to backtest first i have used QQE but mostly on crypto but it provides so many wrong signals