
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
It looks like you are using something else (maybe iHigh()/iLow() or High[]/Low[]) instead of arrays that are passed by reference to the OnCalculate() function.
https://www.mql5.com/en/forum/475546
No, am actually using the OnCalculate() rates buffers, that is why it is baffling, as I can't tell, where it is getting its values from.
Interestingly, your last 10 bars appear to have the right calculation/display. If 10 bars is your intended lookback period, then eliminate the preceding superfluous dots with ...
Post edited by moderator
I can't understand the behaviour of the indicator, it plots well no problem at all, until the error occurs. Also, the candle on which its calculation are to start, is included in the code.
if(lastHigh!=high[idx]) { Up[idx] = high[idx]; lastHigh = high[idx]; }
If the condition is false, do you set your buffers to EMPTY_VALUE?
Where do you set high/low directions?
In MT4, buffers and MT4 predefined arrays are all ordered AsSeries. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.
To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
If the condition is false, do you set your buffers to EMPTY_VALUE?
Where do you set high/low directions?
In MT4, buffers and MT4 predefined arrays are all ordered AsSeries. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.
1) No, In the condition that it is false, the buffer (UP) in this case, holds the value of the most recent high. it is set to "EMPTY_VALUE", when the candle is first added.
2) When the new candle is added (at limit>0) to the chart, a dot is placed below and above, with the values as seen from the OnCalculate. There is no direction, just placing a dot above at the high, and below at the low.
Yes, I am aware of the predefined arrays being orded AsSeries. Am using the arrays passed to the OnCalculate.
You can't just ignore the situation when prev_calculated is zero. You should initialize all buffers with empty values and recalculate them for each bar. If the indicator has been running for a while and the terminal suddenly sets prev_calculated to 0, then this is not happening for nothing.
For the code from your example, it will not be difficult to calculate the arrow values again for each bar on the chart. If you have data there that cannot be restored, it is not enough to simply store it in an indicator buffer. Indicator buffers can be "corrupted" when the terminal adds or removes bars, after which you will not be able to find out which bars the values stored in the buffer belonged to.
You can't just ignore the situation when prev_calculated is zero. You should initialize all buffers with empty values and recalculate them for each bar. If the indicator has been running for a while and the terminal suddenly sets prev_calculated to 0, then this is not happening for nothing.
Yes, that is why am setting from which bar to begin its plotting. If I initialize the plot buffers to EMPTY_VALUE, I lose all real time historic values calculated prior.
For the code from your example, it will not be difficult to calculate the arrow values again for each bar on the chart. If you have data there that cannot be restored, it is not enough to simply store it in an indicator buffer. Indicator buffers can be "corrupted" when the terminal adds or removes bars, after which you will not be able to find out which bars the values stored in the buffer belonged to.
It does not recalculate, just working with the real time (currently forming candle) only.
Please, is there a way I can check for this.
Please, is there a way I can check for this.
What exactly do you want to check?
Here's the terminal adding bars to the right end:
And here the terminal adds bars to the left end:
I just did these 2 tests. I managed to do it even though the market is closed. I simply changed the timeframe to M1 (which had not been used for a long time) and pressed the home button. The indicator I used:
Here's the terminal adding bars to the right end:
And here the terminal adds bars to the left end:
Now imagine that you had data in indicator buffers, the size of which the terminal changed.
Those 2 examples were primitive. The terminal can also delete bars from the chart sometimes, judging by what other users write on this forum (I myself have never seen bars deleted from the chart). After buffers are truncated, they may still contain data, but the indexing is corrupted.
Yes, that is why am setting from which bar to begin its plotting. If I initialize the plot buffers to EMPTY_VALUE, I lose all real time historic values calculated prior.
It does not recalculate, just working with the real time (currently forming candle) only.
Please, is there a way I can check for this.
Here's how I avoid nested loops:
MT4 empty value: Other constants - Named Constants - Constants, Enumerations and Structures - MQL4 Reference