Discussion of article "Custom Indicators in MQL5 for Newbies" - page 2

 
serg7771959:

Nicholas!

Can you tell me why when I try to fill an indicator array in a loop using the formula Mass[ i ]= Mass[ i+1]+A; where A is a variable, compilation goes without errors, but when I join the window I get the message array out of range (array out of range)?


Because the loop should be made taking into account the cell where the last entry will be made. If the size of the Mass[] array, let's say, is 10, the loop from zero to 9 (this is the index of the last cell of the array), then at i==9, you try to write to the cell with the index 9+1. The array does not have cell 10. So you get an output outside the array.
 
We need more tutorials like this one!!!
 

Nikolay, thank you. It's a great tutorial!
But I think that variable

const int begin

will always be zero valued, in the code. Is it significant for calculation?

 
igorsds:

Nikolay, thank you. It's a great tutorial!
But I think that variable

will always be zero valued, in the code. Is it significant for calculation?

The value of "begin" will be different depending on what indicator applied to. If you apply to RSI, "begin" will be 14, for example.

 

If you try to compile for the first time, you may get buffer error. So please change the amount of buffers:

#property indicator_buffers 2

Later on, you can switch back to 1 (one) buffer:

#property indicator_buffers 1

 
How do i combine with fibo zigzag
 

I don't understand. Suppose

rates_total == MA_Period - 1

and this is the first call of the function so

prev_calculated == 0

and also begin == 0

then the condition in the first if (rates_total < MA_Period - 1 + begin) evaluates to false

then

first = MA_Period - 1 would be executed

but then NO CALCULATIONS because the condition in the first for loop evaluates to false.

I think the first if condition should be

if( rates_total < MA_Period + begin )

am I missing something here?

 

And one more. Why should I start calculating from the bar with the number (prev_calculated - 1), if I already calculated the indicator prev_calculated times?

For example, I calculated the indicator 5 times for the bars 0, 1, 2, 3 and 4. I don't need to calculate it on the bar 4 again. I should continue from the bar 5.

 
LRDPRDX #:

And one more. Why should I start calculating from the bar with the number (prev_calculated - 1), if I already calculated the indicator prev_calculated times?

For example, I calculated the indicator 5 times for the bars 0, 1, 2, 3 and 4. I don't need to calculate it on the bar 4 again. I should continue from the bar 5.

Ok. I think I am not correct here, because the 4th bar might have been changed since my last calculation. So the (prev_calculated - 1) looks right.
 
Scams the order of the day. Bravi