Learn Algo Trading with Python | Codes | Youtube Series

Thanks its working fine now.

EMA 20 is correct but EMA 200 is not calculating correctly for 5 min candle. please check once.

Hi @Udaycontact ,

Bracket order placement will be available in further sessions

  1. Yes it is a good approach.
  2. Order id will remain same, only modification will take place.
1 Like

Hi @Vasili_Prasad
The code in folder 3.1 is same same file that you are using.
Video 3.1 is for the traders who have not upgraded their codebase and still working on webscokets to get ltp.

Hi @abhaynarayan27
for open source Backtesting use below link : Open Source Backtesting – Google Drive

Hi @Rajashekhar_Rangappa

tsl.get_intraday_data was a old method to get historical data… it gives data only for today, which makes problem if we want to create indicators on it.

Dhanhq was upgraded and now we can use get_historical_data which gives data for last 5 working days.

Retrieve historical or intraday data:

Get Historical Data

  • tsl.get_historical_data(tradingsymbol: str, exchange: str, timeframe: str, debug: str = “NO”)
    • Arguments:
      • tradingsymbol (str): The trading symbol for the instrument you want to fetch data for (e.g., ‘NIFTY’, ‘ACC’).
      • exchange (str): The exchange where the instrument is traded (e.g., ‘NSE’, ‘INDEX’).
      • timeframe (str): The timeframe for the data. It can be:
        • ‘1’ for 1-minute candles
        • ‘5’ for 5-minute candles
        • ‘15’ for 15-minute candles
        • ‘25’ for 25-minute candles
        • ‘60’ for 60-minute candles
        • ‘DAY’ for daily candles
      • debug (optional, str): Set to “YES” to enable detailed API response logging. Default is “NO”.
    • Sample Code:

data = tsl.get_historical_data(tradingsymbol='NIFTY', exchange='INDEX', timeframe="DAY") 
data = tsl.get_historical_data(tradingsymbol='ACC', exchange='NSE', timeframe="1")

Hi @Subhajitpanja ,

Elaborate about the query.

Upto high level understanding, the instrument file will be downloaded once in a day when programs starts freshly for that day and is read whenever program is restarted during the day.

Okay Sir. Thank You very much for clarification.

1 Like

Hi @rahulcse56 ,

EMA 200 requires at least 200 candles for accurate calculation. Do check the number of candles present in your dataframe before proceeding to calculate.

Thanks sir :pray:

1 Like

Dear sir

how to backtest my algo code ,please suggest step by step process…

1 Like

@Tradehull_Imran Sir,

Below line is showing in terminal, although there is no existence of that file in my source folder(which already shared as image). I will try to run it again on Market days and let you know the output

reading existing file all_instrument 2025-02-07.csv

Thank you sir

1 Like

Sir pre open ka data kaise aaega… my strategy based on pre open volatility . help me this. if there is no method to get pre open data then i will mannualy give it to my algo.

yes i have checked the last 200 candles are present in the historical data. although EMA200 value of 5 min candle is not coming correctly.

Hello @Tradehull_Imran Sir,

entry_order_id = trade_hull.order_placement(tradingsymbol=call_at_the_money,
                                                            exchange='NFO',
                                                            quantity=lot_size,
                                                            price=0,
                                                            trigger_price=0,
                                                            order_type='MARKET',
                                                            transaction_type='BUY',
                                                            trade_type='MIS')

stop_loss_order_id = trade_hull.order_placement(tradingsymbol=call_at_the_money,
                                                                exchange='NFO',
                                                                quantity=lot_size,
                                                                price=sell_price,
                                                                trigger_price=trigger_stop_loss,
                                                                order_type='STOPLIMIT',
                                                                transaction_type='SELL',
                                                                trade_type='MIS')
average_buy_price = trade_hull.get_executed_price(entry_order_id)

traded_stocks[stock] = {
    'Option': call_at_the_money,
    'Quantity': lot_size,
    'Stop_Loss': trigger_stop_loss,
    'Average_buy_price': average_buy_price,
    'Stop_loss_order_id': stop_loss_order_id
}

Sir I want to loop over a stock list, and on a loop fill information for that stock in a dictionary.

after placing an order, we want the average buy price

average_buy_price = trade_hull.get_executed_price(entry_order_id)

Do I need time sleep between the order placing and calling its average traded price? Or is it fast enough to immediately get it?

if we need the time sleep, what minimum amount could I put, without slowing the code down ?

Hi @Dhananjay_Umalkar ,

You can call average price immediately.

I want to get the day’s first candle based on 5 min.
For ex,

chart = tsl.get_historical_data('NIFTY FEB FUT', 'NFO', "5")

Not sure which values to pick? :thinking:

Hi @Rajashekhar_Rangappa

To get first candle of the day use the below code:

first_candle = chart[chart['timestamp'].dt.date == datetime.datetime.now().date()].iloc[0]

mac operating systems ka link chahiya need

I just verified the values. seems something fishy in response.

From API :point_down:

NIFTY FEB FUT H=23623.0 L=23533.1

From chart,

Can you check for me, please?