Difference between indicator timing and EA timing question

 

Ok, I'm a newbie to MQ4, but I have a lot of programming experience, therefore I understand the syntax and logic fairly well.

I have created a custom indicator that uses a manually calculated MACD formula (the internal one doesn't seem to work right for me) to identify my buy and sell signals. I accurately see my indicators on the charts with the period defined (let's say 5m).

I have modified a buy/sell EA to utilize my formula to trigger buys and sells, however the buy/sell triggers are not synced with the custom indicator signals on my graph. It appears that the timing reference being used for the chart (5m) does not seem to match the EA execution, instead it seems to be triggering the script every time there is a new bit of data, and therefore the values triggering buy/sell do not correspond with my indicators. What I want to happen is calculate my formula only every 5 minutes to correspond with the 5m chart indicators I am using. What am I missing here about EA time control and referencing?

Is there a better way to trigger events based on custom indicators?


example

 

datetime time = 0;

int start()

{

if(time != Time[0])

{

//this will trigger on the first tick of each new bar

time = Time[0];

//add calculations here

}

return(0);

}

 
Global variable or internal static. And use the SRC button for code people!
int start() {
   static datetime time;
   if (time > Time[0]) { time=Time[0]; // reset
      //...