MQL4 Custom Alert is One Bar Late?

 

I made a custom moving average alert system in MQL4 that is suppose to alert me each time my two moving averages cross each other. I am quite new to coding so for whatever reason I get an alert but it is exactly one candle late. Any help would be greatly appreciated.

Here is the code for my Custom Indicator:


extern int MA1Period=1;
extern int MA1Shift=0;
extern int MA1Method=1;
extern int MA1AppliedPrice=1;

extern int MA2Period=10;
extern int MA2Shift=0;
extern int MA2Method=1;
extern int MA2AppliedPrice=1;

double AlertTag;
int BarsOnChart = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
double CurrentMA1 = iMA(NULL,0,MA1Period,MA1Shift,MA1Method,MA1AppliedPrice,1);
double PreviousMA1 = iMA(NULL,0,MA1Period,MA1Shift,MA1Method,MA1AppliedPrice,2);
double CurrentMA2 = iMA(NULL,0,MA2Period,MA2Shift,MA2Method,MA2AppliedPrice,1);
double PreviousMA2 = iMA(NULL,0,MA2Period,MA2Shift,MA2Method,MA2AppliedPrice,2);

if(PreviousMA1<PreviousMA2 && CurrentMA1>CurrentMA2 && Bars != BarsOnChart)
   if (IsNewCandle()==true)AlertCall(0);
   AlertTag=(double)Time[0];
   
if(PreviousMA1>PreviousMA2 && CurrentMA1<CurrentMA2 && Bars != BarsOnChart)
   if (IsNewCandle()==true)AlertCall(1);
   AlertTag=(double)Time[0];
//--- return value of prev_calculated for next call
   return(0);
  }
//+------------------------------------------------------------------+
void AlertCall(int Call)
{
      if (Call==0)
         Alert("YOU GOT AN (up) CROSS SON");
      if (Call==1)
         Alert("YOU GOT A (down) CROSS SON");
}
bool IsNewCandle()
{
     
      if (Bars == BarsOnChart)
      return (false);
      BarsOnChart = Bars;
      return(true);
}

I'm not totally sure what to do with the OnCalculate function so I'm pretty sure that block of code is useless in my program as well. My apologies for any unorthodox or sloppy code.

Reason: