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

 

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.
 
LRDPRDX #:

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?

 
I'm newbie here so I don't know how to this..and how to start..can you teach me how? And how this will work?

 
nellypingos #:
I'm newbie here so I don't know how to this..and how to start..can you teach me how? And how this will work?

Start by reading the full article. It is intended to help you learn how to program indicators in MT5.

After that copy the example program into your terminal and attach it to a chart. Or use it in your EA. How to do that? There are other articles about it. (Hint: you will need the iCustom() function.)