Best way to get Candle data

rogerrajeev32
I am forming candles using stream data which in turn is used to calculate indicators. ATR is a very important indicator for my strategy. Bcs of technical issues the stream candles have a variation to historical data when fetched EOD. On paper trading for one month, I have inferred that incorrect ATR is way bigger drawback than a delay of 5-15s for candle formation with regards to my strategy.

For this reason, I have decided to fetch the candles using historical data API. Can you let me know the best way to fetch candles ? I see a small variation in the candle returned from the API at 1th, 5th, 10th, 50th second. I know its not possible to have it 100% synced bcs of technical difficulties. I would just like to know the best way to get most accurate data.

Additional details.

For testing I used Crude oil FUT 6pm+
Logic- Fetch the candle at 0th,1th,5th, 10th,50th second.
Also have fallback mechanism to fetch T+1s if candle is not formed.
There was some occasions were the 10th/50th variant had an updated candle.
My testing was based on Crude oil, but I plan to do it on Nifty/Bank Nifty which have way more ticks every minute and possiblity of deviation may go up.

So would like to know best possible way
  • rakeshr
    ATR is generally calculated over a period range. I'm not sure, what period range you are looking for but for the live candle fetch historical data fetch is not recommended. Maybe you can try out the combination of historical data for the previous days candle and form candles at your end for live candles. This thread explains more.
  • SRIJAN
    SRIJAN edited January 2022
    What kind of variation do you see?? Historical data is always synced . What period and timeframe are you fetching??
  • rogerrajeev32
    @rakeshr ATR on one minute candle. so previous day candles aren't of much use one midday session. I just want to know like after 15s, historic candle will be formed. or when will it be formed

    @SRIJAN the variation was the close of the candle while querying historical API. On one minute time frame when querying candle of previous minute(T-1), the close was XYZ at first second(HH:T:01). When the same candle was queried at the10th second(HH:T:10), it was ABC. and on querying the next day, I was able to confirm 10th second was the final value. So I would like to know, how to find which is the correct value.
  • SRIJAN
    SRIJAN edited January 2022
    Well,I never saw variations like this so can't really tell what to do. What's the 'to' parameter you are passing?? Is it the current time?beacuse if you pass the 'to' as the current time,then the ltp at that sec comes as the close value of the last candle in the response. That could be the error.
  • SRIJAN
    And,I just checked on CrudeOil,the historical data is same and correct no matter which second I fetch last minute candle.
  • rogerrajeev32
    @SRIJAN This was when fetching one minute candles when market is open

    ie Time is 10:15:01PM and fetching candle of 10:14PM
  • SRIJAN
    What's the 'from' and 'to' parameters you are passing?? There must be some error in them.
  • rogerrajeev32
    I pass the same from and to, so that I get data of that minute alone. I'll add logs after mondays session
  • krishnarpatel2024
    • Choose a reputable data provider known for accuracy.
    • Use consistent timeframes for fetching candles.
    • Account for latency by fetching data with a buffer time.
    • Verify data consistency by averaging results or using the most common value.
    • Monitor for updates to historical data.
    • Consider volume and liquidity, especially for high-volume instruments.
    • Backtest your strategy using historical data before live trading.
Sign In or Register to comment.