Candles are repainting on 'bar replay'

Hi all,

When I use bar replay to replay on a 1 hour step (on an hourly candle chart), the candles will sometimes repaint. I can’t work out why this is happening. What am I doing wrong? Thanks.

I am not sure what you mean with 'repainting" because technically the word ‘repaint’ means just drawing in response to WM_PAINT message. But if you mean that you charts modify past candles it only may mean that your formulas look into the future.

1 Like

I am facing a similar problem. My database is a 1min database with entries starting at 9:16 and database created with "$TIMESHIFT -0.016666667".

On bar replay with 5min step interval, on clicking Next, a bar appears capturing data for 1minute i.e. say, 9:31am. When I click Next again, 9:31am bar completes with data from 9:31-9:35am and a new bar appears with data for 9:36am.
Error_12

How can I overcome this issue? Thanks in advance.

Hi @shaleen, and Welcome to the forum.

Please Search and follow the instructions to get your "Verified Badge".

You need to be verified to post questions.

Also, as a new member, you should read the "How to use this site", for lots of helpful tips.

Solution to Problem:- if we replace $TIMESHIFT -0.016666667 by $TIMESHIFT -0.016 while importing data, the error goes away.

SURPRISING!!! Can somebody point out why this happens?

Lastly, I have verified my license and read the basic stuff on this portal. Thanks.

It just means that your source data file had incorrect timestamps.

Source file data seems to be correct, sample below:-

BANKNIFTY_F1,20180103,09:16,25440.00,25486.95,25426.05,25470.00,64040,1355880
BANKNIFTY_F1,20180103,09:17,25470.40,25473.95,25459.25,25460.95,25160,1355880
BANKNIFTY_F1,20180103,09:18,25460.95,25464.75,25456.35,25459.05,18040,1355880
BANKNIFTY_F1,20180103,09:19,25458.00,25477.15,25458.00,25475.00,30560,1357840
BANKNIFTY_F1,20180103,09:20,25473.40,25483.50,25470.05,25483.10,21040,1357840
BANKNIFTY_F1,20180103,09:21,25484.10,25495.70,25480.60,25482.25,35880,1357840
BANKNIFTY_F1,20180103,09:22,25480.55,25487.30,25472.55,25486.45,17920,1352920
BANKNIFTY_F1,20180103,09:23,25485.90,25486.00,25476.35,25476.65,22400,1352920
BANKNIFTY_F1,20180103,09:24,25475.50,25482.20,25474.10,25480.00,8840,1352920
BANKNIFTY_F1,20180103,09:25,25481.55,25482.95,25470.00,25472.95,7960,1361320
BANKNIFTY_F1,20180103,09:26,25470.00,25475.80,25469.25,25470.65,13440,1361320
BANKNIFTY_F1,20180103,09:27,25470.00,25470.00,25463.30,25468.45,11800,1361320
BANKNIFTY_F1,20180103,09:28,25467.30,25467.95,25454.40,25458.85,15720,1366240
BANKNIFTY_F1,20180103,09:29,25456.50,25461.00,25455.50,25461.00,23440,1366240
BANKNIFTY_F1,20180103,09:30,25462.00,25462.00,25458.35,25462.00,7360,1366240
BANKNIFTY_F1,20180103,09:31,25460.30,25462.85,25455.00,25455.00,7480,1366760
BANKNIFTY_F1,20180103,09:32,25455.00,25461.00,25455.00,25459.65,6680,1366760
BANKNIFTY_F1,20180103,09:33,25459.35,25462.00,25458.55,25462.00,5280,1366760
BANKNIFTY_F1,20180103,09:34,25462.00,25462.00,25456.10,25456.10,4960,1368080
BANKNIFTY_F1,20180103,09:35,25458.20,25458.20,25451.00,25457.35,10920,1368080
BANKNIFTY_F1,20180103,09:36,25457.70,25460.00,25454.00,25457.00,8880,1368080
BANKNIFTY_F1,20180103,09:37,25460.00,25460.00,25456.10,25456.35,2360,1370800
BANKNIFTY_F1,20180103,09:38,25456.95,25459.95,25456.85,25459.90,2440,1370800
BANKNIFTY_F1,20180103,09:39,25458.00,25459.00,25457.00,25458.30,1480,1370800
BANKNIFTY_F1,20180103,09:40,25459.05,25459.05,25448.10,25449.05,9200,1372080

The timestamps are wrong, forward looking. They should start at 9:15, if trading starts at 9:15.

What is to be done if Market closing & opening time changes / differs once or couple of times every year.
Indian National Stock Exchange follow official time form 9.15am to 3.30pm.
However every year there is an auspicious festival day when market trades just for one hour as per auspicious time which can change from 2pm onwards till 8pm.
Also recently there was problem of network so market was stand still from 10.40am till 3.45pm
But later same day from 3.45pm to 5pm special time was given to exit positions.

It does not matter when trading starts. What matters is that your bars have correct timestamp. Five-minute bar that covers 9:00:00..9:04:59 should have timestamp of 9:00, not 9:05.

@Tomasz, following your suggestion in other thread, I did a quick test, using the above "BANKNIFTY_F1" sample, ASCII data, importing it applying a $TIMESHIFT -0.0166667 and the resulting timestamp in the Quote editor are starting at 09:15:00.

I wonder if using such a fractional number (approx. corresponding to 1-M) will give correct results also importing a large dataset, or if there is the risk of misalignments in the long run?

I have multiple years of 1M data where the timestamp is at the bar's close)*.
Up to now I used an external script to offset my timestamps, but if you confirm that $TIMESHIFT will work correctly also for a 1-M (using a rounded value with repeating decimals) I may save some time importing these series directly.

* The data I plan to use does not start each day simultaneously for all the tickers (it includes Outside RTH), so a misalignment may not be easy to spot visually.

Don't worry.
Internally AmiBroker uses double precision floating point for timeshift. It means 64-bits.
The dates in Windows are also stored as double precision floating point (64-bit).

So we don't lose any precision. Approximate resolution of this format is 1 microsecond.

You just need to make sure you specify MORE than few digits because double precision is actually 15 significant digits, so for one minute shift backwards you should use:

-0.0166666666666667 // correct timeshift for 1-minute
1 Like