Disliked{quote} I am confused by the statement about the "live stream of ticks". I tested on M1, actually it does not repaint, ok. But I do not understand everything else. Please give me an example: - when do I search "explicitly"? - what will be recalculated?Ignored
Consider the snippet of code below. You see the iteration starts at limit-1 and decrements to '0'. This loop gets executed with every tick. On an H1 chart this could easily occur hundreds of times. If gadblUpper[] is a dynamic buffer associated with a visible object then during the course of that hour -- i.e. during the time the current H1 bar is being formed -- the gadblUpper[0] element will continuously change. As you know, index '0' is the current bar -- the one that is currently being formed. It won't become stationary until it matures as index '1' and the next bar begins.
for( int i = limit-1; i >= 0; i-- )
{
...
gadblMid[i] = dblTma;
gadblUpper[i] = dblTma + ( dblAtrMultiplier * dblRange );
gadblLower[i] = dblTma - ( dblAtrMultiplier * dblRange );
gadblRange[i] = Convert_2_Pips(strSymbol, MathAbs(gadblUpper[i] - gadblLower[i]));
...
}
If you were to place a function like CheckNewBar() at the beginning of start() or OnCalculate() then you can filter out and ignore all ticks except the first tick at the beginning of H1. MT4 guarantees you will receive a tick at the exact beginning of a time frame -- be it M1, ... MN1. However, there is no guarantee you will get a Close tick at the end of the time frame. You can only know what the close tick was after the fact. That is, when you receive a new Open tick, then you can look back in time to see when the previous tick occurred -- that would be your Close tick. It might have been a few seconds before the Open tick, or it could have been minutes or hours before -- you just don't know. It depends on the symbol and the broker's data feed.
There is another way to avoid the appearance of recalculation -- don't count down to '0'. Instead count down to '1':
for( int i = limit-1; i >= 1; i-- )
Just to be clear -- there is nothing wrong with recalculating -- in fact, it often is desirable. If you avoid recalculating index '0' then that means during the 60 minutes the H1 bar takes to form you are ignoring all ticks -- including wicks (i.e. Highs and Lows) -- which might be undesirable.
As for when you would search explicitly? At the beginning of start() or OnCalculate() -- for example:
int start ()
{
....
if (false == CheckNewBar())
{
return (0);
}
....
}
Again -- in an indicator this may not be desirable since recalculating is okay. One is much more likely to ignore ticks when programming an EA.
Am I going in the right direction -- or simply making things more confusing? I'm really good at making things more confusing -- that's what my wife and kids tell me all the time. I also tend to repeat myself and exaggerate -- in case you haven't noticed...