@Imran Sir,
When i am running 2 programe in my laptop then i am getting below error
Please let me know how to resolve it so that i can run or test more then 2 programs at a time.
IRFC Rejected: pullback fail
Exception in Getting OHLC data as {'status': 'failure', 'remarks': {'error_code': 'DH-904', 'error_type': 'Rate_Limit', 'error_message': 'Too many requests on server from single user breaching rate limits. Try throttling API calls.'}, 'data': ''}
Also can you guide me how to resolve below queries, I want in buy if my share price low ang high breakout 2 level pivot point in any range from S4 to R4.
Ex if low< R1 and High> R3 then i want to buy call or if low<S1 and break high >R1 then buy etc
def classic_pivots(prev):
h,l,c = prev["high"],prev["low"],prev["close"]
p = (h+l+c)/3
r = h-l
return {
"P":round(p,2),
"R1":round(p+0.5*r,2),
"S1":round(p-0.5*r,2),
"R2":round(p+1.0*r,2),
"S2":round(p-1.0*r,2),
"R3":round(p+2.0*r,2),
"S3":round(p-2.0*r,2),
"R4":round(p+3.0*r,2),
"S4":round(p-3.0*r,2)
}
chart = tsl.get_historical_data(underlying=stock, "NFO", "5")
piv = classic_pivots(chart.iloc[-2])
pivot_levels = [piv["S4"],piv["S3"],piv["S2"],piv["S1"], piv["P"], piv["R1"],piv["R2"],piv["R3"],piv["R4"] ]
pivot_levels = sorted(pivot_levels)
current_price = chart["close"].iloc[-1]
cross_count = sum(current_price >= lvl for lvl in pivot_levels)
three_level_breakout = cross_count >= 3
Please share me proper code of it .
Regards
Hi @Krushna_Rout ,
Currently Dhan has API rate limitations, tagging @Dhan for the same.
@Tradehull_Imran sir,
If i will increase my sleep(60) instead of sleep(15) ,it will resolve rate limit error.
then what is the process to rur more than 2 program at the same time?
Also kindly share me 2 level pivot breakout code.
Regards
Krishna
Hi @Krushna_Rout ,
Using 2 different Dhan accounts , you can run 2 algo’s at same time without much rate limit issues .
Refer the below pseudocode for 2 level pivot breakout -
pivot_highs = []
pivot_lows = []
for i in range(len(df)):
if current_candle_is_pivot_high(i):
pivot_highs.append(df["high"][i])
if current_candle_is_pivot_low(i):
pivot_lows.append(df["low"][i])
if len(pivot_highs) >= 2:
previous_pivot_high = pivot_highs[-2]
latest_pivot_high = pivot_highs[-1]
if df["close"][i] > latest_pivot_high and df["close"][i] > previous_pivot_high:
buy_signal = True
else:
buy_signal = False
if len(pivot_lows) >= 2:
previous_pivot_low = pivot_lows[-2]
latest_pivot_low = pivot_lows[-1]
if df["close"][i] < latest_pivot_low and df["close"][i] < previous_pivot_low:
sell_signal = True
else:
sell_signal = False
@Tradehull_Imran
I am unable to understand it and may be logic is differnt.
My purpose was if today stock low and high price 5min candle cross yesterday classical pivot 2 level then alert for call similarly if its cross down 2 level pivot point then put will be trigger.
suppose S1 98, pivot 100 R1 102 then if
ex: if price R1 then 2 level breakout within range of (S4 to R4) of yesterday pivot in upside then buy call initiate.
silmarly if high > S1 and low break S3 that is 2 level downside then put intiate.
kindly give me code ,if possible as per my above syntax
Regards
Hi @Krushna_Rout ,
Refer this pseudocode for the logic mentioned -
ordered_levels = [
("S4", pivot_levels["S4"]),
("S3", pivot_levels["S3"]),
("S2", pivot_levels["S2"]),
("S1", pivot_levels["S1"]),
("P", pivot_levels["P"]),
("R1", pivot_levels["R1"]),
("R2", pivot_levels["R2"]),
("R3", pivot_levels["R3"]),
("R4", pivot_levels["R4"]),
]
for i in range(1, len(df)):
previous_close = df.loc[i - 1, "close"]
current_high = df.loc[i, "high"]
current_low = df.loc[i, "low"]
call_signal = False
put_signal = False
for j in range(len(ordered_levels) - 2):
start_level_name, start_level_price = ordered_levels[j]
target_level_name, target_level_price = ordered_levels[j + 2]
if previous_close <= start_level_price and current_high >= target_level_price:
call_signal = True
print("True for CALL side")
break
if call_signal == False:
for j in range(2, len(ordered_levels)):
start_level_name, start_level_price = ordered_levels[j]
target_level_name, target_level_price = ordered_levels[j - 2]
if previous_close >= start_level_price and current_low <= target_level_price:
put_signal = True
print("True for PUT side")
break
if call_signal == False and put_signal == False:
print("No breakout")