**tomyang03:**

hi there,

I am new to mql5. Really new to this. I am looking at the code for the simple MA function. I am trying to understand how the codes work and reflect the functions listed on

http://www.metatrader5.com/en/terminal/help/analytics/indicators/trend_indicators/ma#sma.

**<CODE DELETED>**

**Please** read some other posts before posting . . .

**When posting code** please use the ** SRC** button:

**How to use the SRC button.**

I am new to mql5. Really new to this. I am looking at the code for the simple MA function. I am trying to understand how the codes work and reflect the functions listed on

http://www.metatrader5.com/en/terminal/help/analytics/indicators/trend_indicators/ma#sma.

double SimpleMA(const int position,const int period,const double &price[])

{

//---

double result=0.0;

//--- check position

if(position>=period-1 && period>0)

{

//--- calculate value

for(int i=0;i<period;i++) result+=price[position-i];

result/=period;

}

//---

return(result);

Simple Moving Average (SMA)

Simple, in other words, arithmetical moving average is calculated by summing up the prices of instrument closure over a certain number of single periods (for instance, 12 hours). This value is then divided by the number of such periods.

SMA = SUM (CLOSE (i), N) / N

Where:

SUM — sum;

CLOSE (i) — current period close price;

N — number of calculation periods.

how does the program get those input parameters ie position , period , price ?

lets say the position = 4

and since position>=period-1

4>=period-1

5 >= period

and solving for period , we get period is less than or equal to 5,

result+=price[position-i];

so for the first iteration, so we start adding from the 4th position.

result = price [4]

and then we divide result by period where period,

result/=period;

so even though we have started summing the price from the 4th position,we have to divide by a period with period = 5 ?