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.
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.
@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.
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 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.
ie Time is 10:15:01PM and fetching candle of 10:14PM