You will not learn anything if you get other people to do it for you, the only way is to do it yourslf so you understand it, the only way to do it yourself is to examine each line of code, break it down and figure out exactly what it is doing and there are several ways of doing that.
for(int i=1;i<=limit ;i++)
{ if( MathAbs(Close[i]-Open[i])/(High[i]-Low[i])<0.50
) // what is this parentheses doing here ? How can you expect to write code that works if you are this sloppy about it ?
boring[i]=Close[i];
}
These are all things you could do that would help you find the cause of the problem
You said you checked the journal tab, did you look in the experts tab next to it ?
I already told you last week your code was causing array out of range did you look that up to find out what it means ?
There is a debugger in metaeditor you could try to learn how to use it to debug your code.
You could use Print() so you could check what the values of your variables were when the code was running.
If you had clicked on the experts tab it would tells you your indicator did zero divide on this line, changing timeframes had nothing to do with it.
So that has to mean this High[i]-Low[i] was zero for some reason. If you look at the indicator on the chart you can see the indicator drew some of its values then stops at a bar where there is only one tick. If there is only one tick high[i] == low[i] so that would cause a zero divide
Now make sure high[i]-low[i] does not get used if it is zero.
int limit=rates_total-prev_calculated;
if(limit<=0) limit=300;
//---for(int i=1;i<=limit ;i++)
{
if(High[i] - Low[i] == 0) continue;// --------------- skip this barif( MathAbs(Close[i]-Open[i])/(High[i]-Low[i])<0.50 )
{boring[i]=Close[i];
}}
//--- return value of prev_calculated for next callreturn(rates_total);
}
Now you will see the experts tab tells you the code did not zero divide anymore but it generates array out of range error on this line.
if(high[i] - low[i] == 0)
So what happens if you take out all the calculations and condidtions to test the loop ?
int limit=rates_total-prev_calculated;
if(limit<=0) limit=300;
//---for(int i=1;i<=limit ;i++)
{
boring[i]=Close[i];
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
Now the experts tab reports array out of range again, this time on this line:
boring[i]=Close[i];
So now you know your code causes array out of range every time a price array is used in the loop. So figure out what is wrong with the loop and why Close[i], Low[i], High[i] is out of range. You can seee the indicator draws all the way to the end of the chart so the error must be at the end, the highest array indexes.
int limit=rates_total-prev_calculated; // what is the value of limit in this calculation when prev_calulated == 0 ?
if(limit<=0) limit=300;
//---for(int i=1;i<=limit;i++) // how does the value of limit compare with the highest available Close[] array index ?
It appears you are trying to make an indicator without learning how to code a loop that works correctly first. There are plenty of examples of how to do this. Look at the code for the included indicators and experiment with them until you understand exactly how they work then try to make an indicator to draw a simple single line that works properly before you try to make it perform calculations.
Sorry, I misguided you, I apolgize, indicator can be coded like that :
int limit = -1;
if( prev_calculated == 0 ) limit = rates_total - 3000;// will calculate 3000 Barsif( prev_calculated > 0 ) limit = rates_total-prev_calculated;
for(int i=limit; i>=0; i--)
{
if(High[i] - Low[i] == 0) continue;// --------------- skip this bar
// Please test it, check if it's OK;
// Put the indicator in a backtest EA, say MACDSample, to check it
Thank you for your explanation.
I see it better now.
SCFX
Hi,
I scratch my head with that crazy error.
Still this simple indicator of 4 rows code disappear when I change timeframe.
Crazily enough, I applied the suggestions posted here already but still failed.
I feel so bad...
Please help me.
Many thanks,
SCFX
Hi,
I scratch my head with that crazy error.
Still this simple indicator of 4 rows code disappear when I change timeframe.
Crazily enough, I applied the suggestions posted here already but still failed.
I feel so bad...
Please help me.
Many thanks,
SCFX
Thanks for replying.
On my journal, there is no such notice but when I change TF, this indicator is removed.
I still cannot fix it yet.
SCFX
2014.05.18 08:41:31.080 Custom indicator H_889_boring GBPUSD,H1: removed
2014.05.18 08:41:25.441 Custom indicator H_889_boring GBPUSD,H4: loaded successfully
I still cannot fix it yet.
SCFX
That is because you are not trying very hard.
You will not learn anything if you get other people to do it for you, the only way is to do it yourslf so you understand it, the only way to do it yourself is to examine each line of code, break it down and figure out exactly what it is doing and there are several ways of doing that.
These are all things you could do that would help you find the cause of the problem
If you had clicked on the experts tab it would tells you your indicator did zero divide on this line, changing timeframes had nothing to do with it.
So that has to mean this High[i]-Low[i] was zero for some reason. If you look at the indicator on the chart you can see the indicator drew some of its values then stops at a bar where there is only one tick. If there is only one tick high[i] == low[i] so that would cause a zero divide
Now make sure high[i]-low[i] does not get used if it is zero.
Now you will see the experts tab tells you the code did not zero divide anymore but it generates array out of range error on this line.
if(high[i] - low[i] == 0)So what happens if you take out all the calculations and condidtions to test the loop ?
Now the experts tab reports array out of range again, this time on this line:
So now you know your code causes array out of range every time a price array is used in the loop. So figure out what is wrong with the loop and why Close[i], Low[i], High[i] is out of range. You can seee the indicator draws all the way to the end of the chart so the error must be at the end, the highest array indexes.
It appears you are trying to make an indicator without learning how to code a loop that works correctly first. There are plenty of examples of how to do this. Look at the code for the included indicators and experiment with them until you understand exactly how they work then try to make an indicator to draw a simple single line that works properly before you try to make it perform calculations.
@ scfx
The only person who can fix is you. Or go to https://www.mql5.com/en/job
and post the job there.
...
Please SDC, no need to be so harsh, even if you are right.
Please SDC, no need to be so harsh, even if you are right.
lol I reworded my post a little bit ;)
Sorry, I misguided you, I apolgize, indicator can be coded like that :
If the chart has less than 3000 bars it will still be out of range.