Download MetaTrader 5
To add comments, please log in or register
Register as a seller and start making profit!
Agent86
915
Agent86 2014.02.05 02:14 
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
Ubzen
5392
Ubzen 2014.02.05 02:55  

Are you trying to avoid 0 divide?

Ian Venner
2583
Ian Venner 2014.02.05 04:55  

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.

Simon Gniadkowski
Moderator
17975
Simon Gniadkowski 2014.02.05 09:54  
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.
Agent86
915
Agent86 2014.02.05 14:15  
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.
Ian Venner
2583
Ian Venner 2014.02.05 16:18  

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.

/
To add comments, please log in or register