Average price per hour

 

I want to calculate the average price of curreny EUR/USD for the first hour of the trade,

mathematically this is achieved as follow:

TotalSum = everyTick price

Then the TotalSum is divided by the number of Ticks added to each other.

How do I implement this into an EA?

 

you have already written the pseudocode.

should be an easy task to convert to mql code.

static double total=0;
static double tickcount=0;
static double avg=0;
total+=Bid;
tickcount++;

static datetime curr=0;
if(curr!=Time[0]){
  curr=Time[0];
  avg=total/tickcount;
  total=0;
  tickcount=0;
}


this code is just for learning purpose, i didn't check/test it.
 

I tested this and works fine, but I have no idea how to set a timeframe (to anylize the average just for 1 hour)



static double TotalSUM = 0; // the total amount of money of all the bids
static double Average = 0; // The average price
static int counter = 0; // The total number of tick per unit time


int start()
{

double Price = Bid;

TotalSUM += Bid;

counter++;

Average = (TotalSUM/counter);
Alert("New tick ",counter," Price = ",Price, " TotalSUM = ",TotalSUM," Average Price is =", Average);
return(0);
}

 
change Time in my code with iTime(Symbol(),PERIOD_H1,0)
 

Can we just use a MA?

  • 1 MINUTE PERIOD
  • LAST 60 PERIODS (MINUTES)
  • APPLIED AT: PRICE_MEDIAN
Something like this:
iMA("EURUSD",PERIOD_M1,60,0,MODE_SMA,PRICE_MEDIAN,0);

thks.
NIERO

 
what it is an MA??
 

Hi Dario, "MA" means "Moving Average". Its a widely used tecnical indicator.

You can start some about https://www.metatrader5.com/en/terminal/help/indicators/trend_indicators/ma

Dario:
what it is an MA??

[]'s
Daniel Niero

 
dniero:

Hi Dario, "MA" means "Moving Average". Its a widely used tecnical indicator.

You can start some about https://www.metatrader5.com/en/terminal/help/indicators/trend_indicators/ma

[]'s
Daniel Niero

Thank you

This is exactly the type of Expert Advisor I am trying to develop, maybe you know where I can find one ready to download? I am sure it is a classic coded EA

Dario

 

I found the Moving Average in the list of ready to use EA of the MT4 platform, now I would like to understand more of its code:

what does it means:

#define MAGICMA 20050610

Reason: