Indicator return EMPTY_VALUE in EA
int limit=rates_total-prev_calculated; for(int i=limit-2; i>=0; i--)
Why are you subtracting 2?
Thank you for your help, you pointed the problem :)
I was using [i+1] earlier in the 'for' loop and limit-1 would produce an array out of range. Then I found a bug. After several hours (!!) of unsuccessful attempts I tried to isolate the bug by reducing the code but didn't realize that limit-2 made a big difference with limit-1. And it's still not clear for me.
With limit-1, or limit-2, limit-3, etc... there are enough bars in the past to calculate the MA, so why does iMA returns EMPTY_VALUE in the EA? Maybe because of the case limit=1 which cause an infinite loop?
I was using [i+1] earlier in the 'for' loop and limit-1 would produce an array out of range. Then I found a bug. After several hours (!!) of unsuccessful attempts I tried to isolate the bug by reducing the code but didn't realize that limit-2 made a big difference with limit-1. And it's still not clear for me.
With limit-1, or limit-2, limit-3, etc... there are enough bars in the past to calculate the MA, so why does iMA returns EMPTY_VALUE in the EA? Maybe because of the case limit=1 which cause an infinite loop?
BGen:
With limit-1, or limit-2, limit-3, etc... there are enough bars in the past to calculate the MA, so why does iMA returns EMPTY_VALUE in the EA? Maybe because of the case limit=1 which cause an infinite loop?
With limit-1, or limit-2, limit-3, etc... there are enough bars in the past to calculate the MA, so why does iMA returns EMPTY_VALUE in the EA? Maybe because of the case limit=1 which cause an infinite loop?
There may be when prev_calculated==0
but what about when
int limit=rates_total-prev_calculated;
calculates at 0 or 1?
for(int i=limit-2; i>=0; i--)
will not be executed as i will equal either -1 or -2
Ok now I understand why the problem does not appear when I run the indicator on the terminal.
whroeder1, your solution seems efficient in all cases. I will keep it for future projects.
Problem solved. Thank you very much to both of you for taking the time to help me. And others :)
whroeder1, your solution seems efficient in all cases. I will keep it for future projects.
Problem solved. Thank you very much to both of you for taking the time to help me. And others :)
Hello and sorry for my bad english.
I made this very simple indicator that draws a SMA using iMA (totally useless but consider it like an exercice for me). It works fine when I use it manually on the terminal but always returns EMPTY_VALUE in an EA. Could you please help me understand what's wrong ?
Here's the indicator:
And the EA: