How to loop x Up bar only and vice versa ?

 

Hello all,

I am learning mql code at the moment, and I am stuck at this problem, not ideas how to loop it , can any one please give  me a sample code.

basically, I would like to create a separate indicator display 2 data series as following.

1. display simple moving average of x bar for only UP CANDLE of Open price

1. display simple moving average of x bar for only DOWN CANDLE of Open price

thanks

 
  1. The easiest MA is exponential  alpha=2.0/(length+1); new=old + alpha(value-old)
  2. For the current candle, decide if it's up or down, update the appropriate buffer.
 
William Roeder:
  1. The easiest MA is exponential  alpha=2.0/(length+1); new=old + alpha(value-old)
  2. For the current candle, decide if it's up or down, update the appropriate buffer.

Thanks..one more question.

another task that i would like to do is looping to average every other bar, can you give me an example. 

1. display moving average of  even bar (0,2,4,6,8...)

2. display moving average of  odds bar (1,3,5,7,9....)

Reason: