Previous Indicator Data value is off

 

Hey guys, I'm very new to MQL4, I'm trying to convert a setup from my mobile phone to EA. I coded the setup as custom indicator, but when I'm calling it from EA and comparing the suppose entry from my mobile app, I noticed the entry is bit off and found the indicator value are not accurate. The entry is when MA1 crossover MA5 & vice versa.

The setups are as attached, and below is the custom indicator code. Did I miss something?


#property indicator_separate_window
#property indicator_buffers 3 

extern int timeframe = PERIOD_CURRENT;

double macdBuffer[], ma1Buffer[], ma5Buffer[];
int limit, i;

void init()
{
   SetIndexBuffer(0, ma1Buffer);
   SetIndexBuffer(1, ma5Buffer);
   SetIndexBuffer(2, macdBuffer);
}

int start()
{
   int counted_bars=IndicatorCounted();
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   //---- the last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   //---- main loop
   ArraySetAsSeries(macdBuffer, true);
   ArraySetAsSeries(ma1Buffer, true);
   ArraySetAsSeries(ma5Buffer, true);
   for(i=0; i<limit; i++) 
   {
      macdBuffer[i] = iMACD(Symbol(), timeframe, 12, 26, 5, PRICE_CLOSE, MODE_MAIN, i);
   }
   
   for(i=0; i<limit; i++) 
   {
      ma1Buffer[i] = iMAOnArray(macdBuffer, 0, 1, 0, MODE_LWMA, i);
      ma5Buffer[i] = iMAOnArray(macdBuffer, 0, 5, 0, MODE_LWMA, i);
   }
   
   return (0);
}

Below is how I will call the custom indicator above from EA;

ma1 = iCustom(NULL, PERIOD_CURRENT, "CI_TMT", PERIOD_M5, 0, 0); 
ma5 = iCustom(NULL, PERIOD_CURRENT, "CI_TMT", PERIOD_M5, 1, 0);
ma1prev = iCustom(NULL, PERIOD_CURRENT, "CI_TMT", PERIOD_M5, 0, 1); 
ma5prev = iCustom(NULL, PERIOD_CURRENT, "CI_TMT", PERIOD_M5, 1, 1);
Files:
IMG_5617.PNG  56 kb
IMG_5618.PNG  58 kb
IMG_5619.PNG  58 kb
 
natsu901:

Hey guys, I'm very new to MQL4, I'm trying to convert a setup from my mobile phone to EA. I coded the setup as custom indicator, but when I'm calling it from EA and comparing the suppose entry from my mobile app, I noticed the entry is bit off and found the indicator value are not accurate. The entry is when MA1 crossover MA5 & vice versa.

Do you have screenshots of what you mean by "bit off"? A common issue is the use of indicator output for bar 0 - it gets outdated as soon as a new tick arrives (so I'm not sure if your mobile gets the ticks at the same instance as your pc...). Would be more accurate if you just compare bar 1 instead, and if they're bit off as well, then we'll probably have a problem with code.