Required Help for MQL4 Programing

 
Hi Everybody,

Wishing you a Happy New Year.

Actually I am New to MetaTrader 4 Programing. And also I don't have any experience in Programing. I just trying to learn from the basics. When I tried to make a EA, I failed to calculate the "Average". This is because of, as i told you before, I am new to this.

I request you to, if anybody can solve this problem, this will be very helpful for me.

Here is the problem which I am Facing.


-------------------------------------------------
double myhigh,myhighavg;

myhigh=High[1] - Close[2];

---------------------------------------------------------
myhighavg= 14 days average of "myhigh"

--------------------------------------------------------------
this is what i want to learn for you, how we can code for 14 days or 7 days or 21 days average of "myhigh"

still if you can't understand, plz reply to this.

I waiting for you replies with help
 
extern int days=14;

double myhighave=0; 
for(int shift=days; shift>=1; shift--) myhighave += High[shift]-Close[shift+1];
myhighave /= days;
 
WHRoeder:


Very much Thanks for your reply.

If you don't mind, can you explain it ? bcoz I told you before, I am new to programming


It will be very much helpful for me


once again Very much thanks for your intention to help me

 
extern int days=14; // Number of days 

double myhighave=0; // initialaze a double variable with name 'myhighave'

for(int shift=days; shift>=1; shift--){      // Shift = days; runs this loop until shift lesser or equal to 1; Shift decrement by 1
   myhighave += High[shift]-Close[shift+1];  // myhighave = myhighave +(High[shift]-Close[shift+1]) differece between high and close(previous bar)
}
myhighave /= days;   // all days difference dividided by days AKA. Average
Reason: