I am trying to record 10 candles for 20 scripts in a dictionary of lists of open,high,low and close. But while doing so, I want to increment a counter only once every 5 mins, to append the lists. But what happens is the counter get incremented by 20 (sometimes more than 20) because the function to do so gets called at every tick. Can anyone think of a solution for this issue?
`if company_data['timestamp'].minute%ohlc[company_data['instrument_token']][5] == 0 and company_data['timestamp'].second==59 and ohlc[company_data['instrument_token']][4] == False: cnt = cnt+1`
This is with reference to the code you suggested which converts ticks to ohlc candles. where the 4th one will be equal to false when a new candle starts but still it gets incremented a lot of times.
Add data only when the timestamp gets matched to needed candle timeframe
I tried this:
`if company_data['timestamp'].minute%ohlc[company_data['instrument_token']][5] == 0 and company_data['timestamp'].second==59 and ohlc[company_data['instrument_token']][4] == False:
cnt = cnt+1`
This is with reference to the code you suggested which converts ticks to ohlc candles.
where the 4th one will be equal to false when a new candle starts but still it gets incremented a lot of times.