Are you trying to avoid 0 divide?
Is v3[] a line buffer ?
At the beginning of the indicator there might not be a value for iMA(), in which case iMA() would return zero. You would not usually want to assign that zero to an indicator line because it would be an erroneous value that would cause the line to dip thousands of pips down to zero. To avoid that you would leave that buffer index unassigned because its default value is the special constant EMPTY_VALUE at which no line will be drawn.
The for loop below v3[i]
Is there any reason to create a conditional comparison instead of directly assigning v3[i] = val3;
?
IE one vs the other below:
I think I understand that the EMA by default already has the buffer value for every bar so in that case would not be needed.
I don't understand why the fractal indicator creates hundreds of indicators on the chart without the >0 comparison.
Thanks all this does help me understand this a bit more.
The zero comparison is probably more of a boots and braces error prevention than an absolute neccessity. The key is to understand what happens if any zeros do get assigned to a line buffer that is following prices, such as a MA. The result is very undesireable.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is there any reason to create a conditional comparison instead of directly assigning v3[i] = val3;
?
IE one vs the other below:
for(int i=Bars-1; i>=0; i--)
{val3=iMA(NULL,0,40,0,MODE_EMA,PRICE_CLOSE,i);
v3[i] = val3;
// vs conditional below
if (val3 > 0)
{
v3[i] = val3;
}
Please advise
Thanks