custom indicator why variable > 0 vs directl assignment

 
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:

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
 

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.

 
Agent86:
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:


Perhaps the code has been copied from an Indicator where there is not a buffer value for every bar, for example fractals, with a MA there is a buffer value for every bar so the comparison isn't needed.
 
It is an EMA for this particular one and I also have fractals in my custom indicator in which the fractal indicator does require it while the EMA does not.

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.