Learn Algo Trading with Python | Codes | Youtube Series

Hi @Msk92
Do check session 3

2 Likes

Thanks @Subhajitpanja
Thanks for pointing it out, will incorporate the changes in dhan_coedebase_v2 as well.

1 Like

Hi @arbind04

Since no data is received
no close frame received or sent

Do try to run the same code in Monday market.

Hi @s_nandi
Sure, it can be added in upcoming videos list.

Hi @jain79
It will be required for algo trading.

thank you sir

Thank you @Tradehull_Imran sir

Yes Sir Required tick by tick option chain data

1 Like

Thanks again Sir and please consider the commodity part also
then we can test properly

@Tradehull_Imran Sir

How to use MACD in Algo? Please cover this on your next session.

@Tradehull_Imran

but when I use that I am getting this error

‘NSE_IDX’
Traceback (most recent call last):
File “/Users/deep/PV/Trade/back-test/Dhan codebase/Dhan_Tradehull.py”, line 216, in get_historical_data
exchangeSegment = script_exchange[exchange]
KeyError: ‘NSE_IDX’
BANK NIFTY
None
BANK NIFTY
None

code :slight_smile:

previous_hist_data = tsl.get_historical_data(‘ACC’,‘NSE’,12)

print(“ACC:”)

print(previous_hist_data)

previous_hist_data = tsl.get_historical_data(‘BANKNIFTY’,‘NSE_IDX’,12)

print(“BANK NIFTY”)

print(previous_hist_data)

intraday_hist_data =tsl.get_intraday_data(‘BANKNIFTY’,‘NSE’,60)

print(“BANK NIFTY”)

print(intraday_hist_data)

#pdb.set_trace()

Hi @deepV

This particular question is to be tested on Monday.

@kram49658 @Subhajitpanja
Added +

1 Like

when i want install libararies.bat then this error come.
plz solve

when i run dhan_codebase usage
then this error come
solve problem sir

Hi, Do I have to subscribe to Data API for this tutorial?

I’m having a problem installing the libraries

yes

@Tradehull_Imran

Hi Imran, Good morning!!

I hope you had a great weekend. I am trying to fetch otm call and put options < 5 rupees to buy and otm call and put options < 50 rupees to sell but the code is not executing properly. Please check and help me.

I have a small request to update the code to include if otm call or put option < 50 rupees to sell is below vwap then buy respective call or put which is < 5 rupees first then execute sell order which is < 50 rupees. I also want to place stop loss for sell order above vwap + 15 rupees. if stop loss hit, exit both respective buy and sell orders.

I have also observed when I run the below code, it is opening up “Websocket” Excel file and writing each strike price there to fetch pricing details. Is it the correct way it suppose to work?

import pdb
import time
import datetime
import traceback
import talib
from Dhan_Tradehull import Tradehull
import pandas as pd
import time

client_code = “xxxxx”
token_id = “xxxxx”
tsl = Tradehull(client_code, token_id)

#Flags to track if a condition has already been met

found_ce_buy = False
found_pe_buy = False

found_ce_sell = False
found_pe_sell = False

print(“\nChecking buy conditions:”)
for distance_from_atm_buy in range(1, 30):
# Get the strike details and LTP for both CE and PE
otm_ce_name_buy, otm_pe_name_buy, ce_otm_strike_buy, pe_otm_strike_buy = tsl.OTM_Strike_Selection(‘NIFTY’, ‘31-10-2024’, distance_from_atm_buy)
ce_ltp_buy = tsl.get_ltp(otm_ce_name_buy)
pe_ltp_buy = tsl.get_ltp(otm_pe_name_buy)

# Check condition for call option
if not found_ce_buy and ce_ltp_buy < 5:  # buy condition 1
    print(distance_from_atm_buy, otm_ce_name_buy, ce_ltp_buy)
    print("Found the strike which has less than Rs 5 Ltp (CE - Buy):", otm_ce_name_buy, ce_ltp_buy)
    found_ce_buy = True

# Check condition for put option
if not found_pe_buy and pe_ltp_buy < 5:  # buy condition 2
    print(distance_from_atm_buy, otm_pe_name_buy, pe_ltp_buy)
    print("Found the strike which has less than Rs 5 Ltp (PE - Buy):", otm_pe_name_buy, pe_ltp_buy)
    found_pe_buy = True

# Stop the loop if both buy conditions are satisfied
if found_ce_buy and found_pe_buy:
    break

print(“Checking sell conditions:”)
for distance_from_atm_sell in range(1, 11):
# Get the strike details and LTP for both CE and PE
otm_ce_name_sell, otm_pe_name_sell, ce_otm_strike_sell, pe_otm_strike_sell = tsl.OTM_Strike_Selection(‘NIFTY’, ‘31-10-2024’, distance_from_atm_sell)
ce_ltp_sell = tsl.get_ltp(otm_ce_name_sell)
pe_ltp_sell = tsl.get_ltp(otm_pe_name_sell)

# Check condition for call option
if not found_ce_sell and ce_ltp_sell < 50:  # sell condition 1
    print(distance_from_atm_sell, otm_ce_name_sell, ce_ltp_sell)
    print("Found the strike which has less than Rs 50 Ltp (CE):", otm_ce_name_sell, ce_ltp_sell)
    found_ce_sell = True

# Check condition for put option
if not found_pe_sell and pe_ltp_sell < 50:  # sell condition 2
    print(distance_from_atm_sell, otm_pe_name_sell, pe_ltp_sell)
    print("Found the strike which has less than Rs 50 Ltp (PE):", otm_pe_name_sell, pe_ltp_sell)
    found_pe_sell = True

# Stop the loop if both sell conditions are satisfied
if found_ce_sell and found_pe_sell:
    break

Now it is working but no idea what wa s happen on Friday, and one small error is there is no any candle is formed in the chosen time frame how i can continue with the run.

Below the error :