Data from EA does not match data in indicator charts.

 
Hi,

Thank you for the mql4 platform. It is fascinating but right now I am stuck.

I am Testing and cannot get the iWPR and iATR data from an EA to equal D1 %R(14) and ATR(14) charts. I want the EA to make a decision once per day at midnight.

// EA Code

int            daylastrun=0;

int start() {

    if(TimeHour(TimeCurrent()) == 0 && daylastrun != TimeDay(TimeCurrent())) {

            daylastrun = TimeDay(TimeCurrent());
        
            wR_Current    = iWPR(NULL,PERIOD_D1,14,0);
            ATR_Current   = iATR(NULL,PERIOD_D1,14,0);
                   
            Print(wR_Current, ATR_Current);

    }
}

This does fire once a day as intended but the data in the Journal tab output does not match the data on the %R and ATR indicator charts. Any advice?

Thanks,
tuxisthecat
 

Posting this led me to this thread which describes a better method for timing:


'I get multiple prints for one daily candle, sometimes even 15 prints at random time stamps for the same day'


Reading that thread led me to use code which does have the correct data. I also learned that a full day of ticks is needed to match the chart data (which makes alot of sense :-).


datetime barTime; // global variable

if( barTime < Time[0] ) {
     // we have a new bar opened
     barTime = Time[0]; // keep the new bar open time

     wR_Current    = iWPR(NULL,0,14,1);
     ATR_Current   = iATR(NULL,0,14,1);

     Print(wR_Current, " ", ATR_Current);

}

Thanks fbj for the explanation.

 

TTC

> EA to make a decision once per day at midnight

extern int StartHour=0; 
// Relevant on H1 charts - allows for different broker timezones

if (Hour()==StartHour && Volume[0]==1) // First tick of new hourly bar
  {
    // Do stuff here


  }

Good Luck

-BB-

Reason: