Building mt4 signal indicator; I need help

 

Good day gurus, pls am trying to design a signal indicator but seems not giving desire result.


It only shows the arrow on the chart, it doesn't popup alert at current price.

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 3
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 3
#property indicator_color2 0x0000FF
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

extern int Shift8 = -12;
extern int Shift25 = 0;
extern int Period2 = 8;
extern int Period1 = 25;
datetime time_alert; //used when sending alert
extern bool Audible_Alerts = true;
extern bool Push_Notifications = true;

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | SBD FX ANALYSTS @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "signal")
     {
      if(Audible_Alerts) Alert(type+" | SBD FX ANALYSTS @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
      if(Push_Notifications) SendNotification(type+" | SBD FX ANALYSTS @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexArrow(0, 241);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexArrow(1, 242);
   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[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_EMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_EMA, PRICE_CLOSE, i)
      && iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_EMA, PRICE_CLOSE, i+1) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_EMA, PRICE_CLOSE, i+1) //Moving Average crosses above Moving Average
      && iCCI(NULL, PERIOD_CURRENT, 50, PRICE_TYPICAL, i) > 0
      && iCCI(NULL, PERIOD_CURRENT, 50, PRICE_TYPICAL, i+1) < 0 //Commodity Channel Index crosses above fixed value
      )
        {
         Buffer1[i] = Low[i] - iMA(NULL, PERIOD_CURRENT, 14, 0, MODE_SMA, PRICE_CLOSE, i); //Set indicator value at Candlestick Low - Moving Average
         if(i == 0 && Time[0] != time_alert) { myAlert("signal", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_EMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_EMA, PRICE_CLOSE, i)
      && iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_EMA, PRICE_CLOSE, i+1) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_EMA, PRICE_CLOSE, i+1) //Moving Average crosses below Moving Average
      && iCCI(NULL, PERIOD_CURRENT, 50, PRICE_TYPICAL, i) < 0
      && iCCI(NULL, PERIOD_CURRENT, 50, PRICE_TYPICAL, i+1) > 0 //Commodity Channel Index crosses below fixed value
      )
        {
         Buffer2[i] = High[i] + iMA(NULL, PERIOD_CURRENT, 14, 0, MODE_SMA, PRICE_CLOSE, i); //Set indicator value at Candlestick High + Moving Average
         if(i == 0 && Time[0] != time_alert) { myAlert("signal", "Sell"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+//+------------------------------------------------------------------+

Kindly help me out. Thanks

 
cryptadels:

Good day gurus, pls am trying to design a signal indicator but seems not giving desire result.


It only shows the arrow on the chart, it doesn't popup alert at current price.

Kindly help me out. Thanks

Change this code

if(i == 0 && Time[0] != time_alert) { myAlert("signal", "Buy"); time_alert = Time[0]; } 

to

if(Time[i] != time_alert) { myAlert("signal", "Buy"); time_alert = Time[i]; } // this is only for buy signal and for sell signal please replace itu your self
 
Roberto Jacobs:

Change this code

to

Thanks for your response.

After changing the code as instructed, it actually gives popup alert but it the alerts are messed up. Instead of given alert once par bar, it gives on those previous one concurrently.

 
if(i == 0 
You are alerting on bar zero (the forming one.) Why do you think you wouldn't get an alert per tick?