but the code for my indicator draws the histogram one bar late.
Any help finding the error would be greatly appreciated !!!!!
Your indenting doesn't help me, I hope it helps you . . . try this . . .
while(i>=0)
{
Diff= Gap[i]; // Value of 0 buffer on i bar
i--; //<------ move this to position a. // Calculating index of the next barif (Diff>GapMin)
{
UpBuffer[i] =1;
}
elseif (Diff<-GapMin)
{
DownBuffer[i]=1;
}
else
{
ZeroBuffer[i]=1;
}
// position a.
}
thanks SDC, point taken about the commenting, I have been using the extra commenting as a tool to remind myself what each line does as I learn
but agree it is annoying and counterproductive when I ask you guy on the forum for help
Cheers
Yes there is nothing wrong with commenting to help you remember what you are learning. Just try to format your comments so the code is still easy to read and not swamped by them.
RaptorUK: I don't agree . . too many comments ( unless we are talking irrelevant padding and "eye candy" ) are much better than none . . .
RaptorUK I was looking back at some help you gave me with this indicator and trying to work on my nemesis
That is: understanding and getting my loops right and having the code execute the way I want.
In this example you helped me, by suggesting the use of 3 different "while" loops, each calculating a separate buffer value.
I am not sure I understand why this could not be done all inside one loop.
Would you or another person on the forum help me understand this better by explaining this.
When I look in the code base:
As long as the Condition of the operator 'while' is true: The program passes the control to the operator of the cycle body; after all operators in the cycle body have been executed, it passes the control to the header to test the truth of the Condition. If the Condition of the operator 'while' is false, the control must be passed to the operator that follows the cycle operator 'while'.
I read this as meaning that as long as the 3 buffers can be calculated (until i is not greater than 0) the loop should calculate......but it does not seem to work this way in practice
Any help always appreciated.....
i=Bars-Counted_bars-1; // Index of the first uncountedwhile(i>=0) // Loop for uncounted bars
{
OBV[i]=iOBV(NULL,0,PRICE_CLOSE,i); // Value of 0 buffer on i bar
AveOBV[i]=iMAOnArray(OBV,0,Period_MA,0,MA_Method,i);
Gap[i]= (OBV[i]-AveOBV[i]);
i--; // Calculating index of the next bar
}
RaptorUK I was looking back at some help you gave me with this indicator and trying to work on my nemesis
That is: understanding and getting my loops right and having the code execute the way I want.
In this example you helped me, by suggesting the use of 3 different "while" loops, each calculating a separate buffer value.
I am not sure I understand why this could not be done all inside one loop.
It's because you are using iMAOnArray() . . . although because you are counting down through the bars, left to right as in real time, it may work.
Many people increment their bar number variable in their for or while loops in Indicators, if you then include an iMAOnArray() call in this loop the data that it needs from the Array has not yet been written to the Array, for example lets take a random bar number . . 175, as the loop progresses through the bars the array is filled, at our chosen example bar the value for the Array (buffer) is filled and then the iMAOnArray() call tries to work with the Array data for bar 175, 176, 177,etc. but the values for bar 176, 177, etc have not yet been calculated.
For loop puts loop control in one place for readability
i=Bars-Counted_bars-1; // Index of the first uncountedwhile(i>=0) // Loop for uncounted bars
{
OBV[i]=iOBV(NULL,0,PRICE_CLOSE,i); // Value of 0 buffer on i bar
AveOBV[i]=iMAOnArray(OBV,0,Period_MA,0,MA_Method,i);
Gap[i]= (OBV[i]-AveOBV[i]);
i--;// Calculating index of the next bar
}
For loop puts loop control in one place for readability
thank you to you both, exactly the description I was looking for from RaptorUk and the chance to look at working loop code side by side (priceless!!..thanks WHRoeder)
it is these basics and subtleties that I want to fully inderstand before I venture into the world of EAs
that is whyI keep going back to my old postings trying to get it straight in my head
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
but the code for my indicator draws the histogram one bar late.
Any help finding the error would be greatly appreciated !!!!!
Your indenting doesn't help me, I hope it helps you . . . try this . . .
thanks SDC, point taken about the commenting, I have been using the extra commenting as a tool to remind myself what each line does as I learn
but agree it is annoying and counterproductive when I ask you guy on the forum for help
Cheers
Thanks RaptorUK, everything seems to work now except,
I still can't work out why the buffers calculate the correct values
(values matching the actual MT4 indicators in the next chart window)
but the code for my indicator draws the histogram one bar late.
Any help finding the error would be greatly appreciated !!!!!
Thanks, yes I will work on the indenting, I promise !!
Code now works exactly as planned.
Working code attached below for anyone interested.
THANKS AGAIN FOR YOUR HELP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I don't agree . . too many comments ( unless we are talking irrelevant padding and "eye candy" ) are much better than none . . .
RaptorUK I was looking back at some help you gave me with this indicator and trying to work on my nemesis
That is: understanding and getting my loops right and having the code execute the way I want.
In this example you helped me, by suggesting the use of 3 different "while" loops, each calculating a separate buffer value.
I am not sure I understand why this could not be done all inside one loop.
Would you or another person on the forum help me understand this better by explaining this.
When I look in the code base:
As long as the Condition of the operator 'while' is true: The program passes the control to the operator of the cycle body; after all operators in the cycle body have been executed, it passes the control to the header to test the truth of the Condition.
If the Condition of the operator 'while' is false, the control must be passed to the operator that follows the cycle operator 'while'.
I read this as meaning that as long as the 3 buffers can be calculated (until i is not greater than 0) the loop should calculate......but it does not seem to work this way in practice
Any help always appreciated.....
RaptorUK I was looking back at some help you gave me with this indicator and trying to work on my nemesis
That is: understanding and getting my loops right and having the code execute the way I want.
In this example you helped me, by suggesting the use of 3 different "while" loops, each calculating a separate buffer value.
I am not sure I understand why this could not be done all inside one loop.
Many people increment their bar number variable in their for or while loops in Indicators, if you then include an iMAOnArray() call in this loop the data that it needs from the Array has not yet been written to the Array, for example lets take a random bar number . . 175, as the loop progresses through the bars the array is filled, at our chosen example bar the value for the Array (buffer) is filled and then the iMAOnArray() call tries to work with the Array data for bar 175, 176, 177,etc. but the values for bar 176, 177, etc have not yet been calculated.
thank you to you both, exactly the description I was looking for from RaptorUk and the chance to look at working loop code side by side (priceless!!..thanks WHRoeder)
it is these basics and subtleties that I want to fully inderstand before I venture into the world of EAs
that is whyI keep going back to my old postings trying to get it straight in my head
thanks again !!!