Attach your code and tell us which line is giving the error.
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
Attach your code and tell us which line is giving the error.
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
Apologies Keith - I was partway through writing my post and accidentally clicked "done" rather than "insert" when using the code tags and it posted my partially written thread! Hopefully it is complete now and makes sense!
Print("Z", " ", ArraySize(ExtSARBuffer), " ", ArraySize(ExtACTBuffer), " ", i); ExtSARBuffer[i++]=sar; ExtACTBuffer[i]=step;
You increment i in line 242, could that be the problem? I am never sure about i++ in strange places.
You increment i in line 242, could that be the problem? I am never sure about i++ in strange places.
The i++ is in the original code.
The problem is he added his ExtACTBuffer[] filling AFTER, it should always be BEFORE. Not only at line 242 but in all other occurrences.
And you are right in this case, the original is not good using this i++ at 4 different places which are mutually exclusive. Bad coding practice.
Thank you guys - thank you Alain, swapping the "ExtACTBuffer" and the "ExtSARBuffer" lines around has indeed fixed the problem.
Just for my understanding though, does this not effectively change how the code is behaving and makes the "SAR" and the "step" values out of sync in their arrays?
What I mean is, I thought that doing this for example:
ExtACTBuffer[i]=step; ExtSARBuffer[i++]=last_low;
Is the equivalent of saying:
"Assign the value of <step> to the ExtACTBuffer array at position (i)" and then
"Assign the value of <last_low> to the ExtSARBuffer at position (i+1)"
So that "pair" of values of step/last_low is now split between positions i and i+1 depending on which array is being looked at.
I thought that in the way I had them in my code, it was the equivalent of saying:
"Assign the value of <last_low> to the ExtSARBuffer at position (i+1)"
"Assign the value of <step> to the ExtACTBuffer array at position (i) which has the same value as in the line above", meaning that the step/last_low values are at equivalent positions in the two buffers?
SetIndexBuffer(0,ExtACTBuffer, INDICATOR_DATA); SetIndexBuffer(1,ExtSARBuffer, INDICATOR_CALCULATIONS);This is MQL5 code not MQL4
This is MQL5 code not MQL4
Thank you guys - thank you Alain, swapping the "ExtACTBuffer" and the "ExtSARBuffer" lines around has indeed fixed the problem.
Just for my understanding though, does this not effectively change how the code is behaving and makes the "SAR" and the "step" values out of sync in their arrays?
Not it's not. The ++ is applied after i is used as index.It's post-increment, read the documentation please.
Ok - thank you Alain for clarifying on both points - I will read up on this further!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
I am attempting to learn about how to control chart buffers and change which buffers are displayed on the chart versus which ones are not. I decided to use the "Parabolic SAR" as an example, and for my little exercise I decided to try plotting the "step" size rather than the SAR value itself in a separate window. Accordingly, I have modified the standard parabolic SAR that is supplied with MT4/MQL4.
The file is attached - I know it is quite long but I have only modified a handful of rows. They key rows that I have modified or added are:
In the intro section I have added the following lines:
and I declare a new buffer that will store the "step" size.
double ExtACTBuffer[];
In the "on init" section I attempt to modify the code to say that the ACT buffer rather than the SAR buffer should be plotted:
I then copy similar lines of code from the existing parabolicSAR code, such as:
Then, every time a piece of data is written into the "ExtSARBuffer", I copy paste the line and write the "step" into the ACTBuffer:
The code compiles without errors. When I attach it to a chart I indeed get a new indicator window and it appears to plot the activity factor properly, but when it gets to the end of the calculation (65000th bar), there is an out of range error which states:
2020.06.14 15:21:35.172 ActivityFactorDemo EURUSD-sb,M5: array out of range in 'ActivityFactorDemo.mq4' (243,19)
My understanding is that this error is caused by trying to put an "Nth" item in an array that isn't N items long. What I don't understand is that I have only entered values into the ACTBuffer when a value is entered in the SARBuffer, and I have not added any lines of code which increment "i" by one, so this behaviour seems very strange.
I note that there is a discussion about indicator buffers and out of range errors here:
https://www.mql5.com/en/articles/1391#2_1
As I understand it, that article is concerning the situation where the markets are open and the indicator is running, and the bar count changes partway through calculation (?). I wrote and tested my code when the market was closed, so surely it is not possible for this to be the cause of my problems?
I apologise if this is somewhat of a rookie query, but any assistance would be greatly appreciated.
Kind regards,
Paul