Help a brother complete his indicator, Seniors;

 

I have this modified indicator that I bought from the freelance community. Now I want to refine it such that the arrows and message alert appear when the current candle closes below a selected MOVING AVERAGE. I started it but I’m stucked now so please, learned community assist a brother. Thanks.

NB: I'm not very sure of the CopyBuffer function for the MA_handle .

 

[indicator attached ]



//+------------------------------------------------------------------+
//|                                              RBR_DBD_Pattern.mq4 |
//|                                       Copyright © 2019, tidicofx |
//|                                               tidicofx@yahoo.com |
//|                                           developed for flyover1 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, tidicofx"
#property link      "tidicofx@yahoo.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_plots 2
#property indicator_buffers 2
#property indicator_color1 clrLimeGreen
#property indicator_width1 1
#property indicator_color2 clrRed
#property indicator_width2 1
//+------------------------------------------------------------------+
//| Input Parameters Definition                                      |
//+------------------------------------------------------------------+
input string                  hint0                         = "===== general settings =====";
input int                     Candle1BodySize               = 50;
input ENUM_TIMEFRAMES         RsiTF                         = PERIOD_CURRENT;
input int                     RsiPeriod                     = 14;
input ENUM_APPLIED_PRICE      RsiApplied                    = PRICE_CLOSE;
input bool                    ShowArrow                     = true;

input group                                                "===== MA Settings  ======"
input ENUM_TIMEFRAMES          MA_TF                        = PERIOD_CURRENT;
input int                     _MAPeriod                     =14 ;
input int                     _MA_Shift                     = 0;
input ENUM_MA_METHOD          _MA_Method                    =MODE_EMA;
input ENUM_APPLIED_PRICE      _MAPrice                      =PRICE_CLOSE ;

input group                                               "===== ALERTS SETTINGS  ======"

input bool                    PopupAlert                    = true;
input bool                    PushAlert                     = true;
input bool                    MailAlert                     = false;
input bool                    SoundAlert                    = false;
input string                  SoundFile                     = "alert.wav";
//+------------------------------------------------------------------+
//| Local Parameters Definition                                      |
//+------------------------------------------------------------------+
string lbl = "BIG CANDLE ALERT.";
double up[], dn[];
datetime lastAlert;
int   rsi_handle=-1 ;
int MA_handle;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
  //------------------------------------------------------------------
  IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
  if (ShowArrow) PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_ARROW); else PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetInteger(0, PLOT_ARROW, 233); PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, +10); SetIndexBuffer(0, up); PlotIndexSetString(0, PLOT_LABEL, "Up");
  if (ShowArrow) PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_ARROW); else PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetInteger(1, PLOT_ARROW, 234); PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, -10); SetIndexBuffer(1, dn); PlotIndexSetString(1, PLOT_LABEL, "Dn");
  lastAlert = iTime(NULL, 0, 0);
  ArraySetAsSeries(up, true); ArraySetAsSeries(dn, true);
  
  MA_handle=iMA(_Symbol,PERIOD_CURRENT,_MAPeriod,_MA_Shift,_MA_Method,_MAPrice);
  rsi_handle = iRSI(NULL, RsiTF, RsiPeriod, RsiApplied);
  if(rsi_handle==INVALID_HANDLE)
    {
     Print("Can't Use Rsi ");
     return INIT_FAILED ;
    }
   ChartRedraw();
  //------------------------------------------------------------------
  return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  //------------------------------------------------------------------
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,      // size of input time series
                 const int prev_calculated,  // bars handled in previous call
                 const datetime& time[],     // Time
                 const double& open[],       // open
                 const double& high[],       // high
                 const double& low[],        // low
                 const double& close[],      // close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread
)
{
  //------------------------------------------------------------------
  int limit = rates_total-prev_calculated;
  if (prev_calculated==0) limit = rates_total-5;
  ArraySetAsSeries(open, true); ArraySetAsSeries(close, true);
  ArraySetAsSeries(high, true); ArraySetAsSeries(low, true);
  ArraySetAsSeries(time, true);
  //------------------------------------------------------------------
  for (int i = limit; i >= 0; i--)
  {
    up[i] = EMPTY_VALUE; dn[i] = EMPTY_VALUE;
    if (MathAbs(close[i]-open[i]))
      if (MathAbs(close[i]-open[i])>=Candle1BodySize*_Point )


    {
      

if(close[i]>open[i] )
        up[i] = low[i];
      if (open[i]>close[i]) 
        dn[i] = high[i];

    }
  }
  //------------------------------------------------------------------
  
  double rsi[1];
    int rsi_cnt=CopyBuffer(rsi_handle,0,1,1,rsi);
    if(rsi_cnt<=0)return 0 ;
    
  double MA[1];
    int MA_cnt=CopyBuffer(MA_handle,0,1,1,MA);
    if(MA_cnt<=0)return 0 ;

  
  
  //------------------------------------------------------------------
  if (lastAlert!=time[0])
  {
     
      if(up[1] != EMPTY_VALUE)
      
        {
         string msg = Symbol()+"("+GetTimeFrameName(Period())+") "+TimeToString(time[0], TIME_MINUTES)+" BigUpClose , RSI ("+GetTimeFrameName(_Period) +") Value Is "+ DoubleToString(rsi[0],2);
         if(SoundAlert)
            PlaySound(SoundFile);
         if(PopupAlert)
            Alert(msg);
         if(PushAlert)
            SendNotification(msg);
         if(MailAlert)
            SendMail(msg, msg);
        }
      if(dn[1] != EMPTY_VALUE)
        {
         string msg = Symbol()+"("+GetTimeFrameName(Period())+") "+TimeToString(time[0], TIME_MINUTES)+" BigDnClose ,RSI ("+GetTimeFrameName(_Period) +") Value Is "+ DoubleToString(rsi[0],2);
         if(SoundAlert)
            PlaySound(SoundFile);
         if(PopupAlert)
            Alert(msg);
         if(PushAlert)
            SendNotification(msg);
         if(MailAlert)
            SendMail(msg, msg);
        }
      lastAlert= time[0];
     }
   
 //-------------------------------------------------------------------
    return (rates_total);
     
     }
//+------------------------------------------------------------------+
string GetTimeFrameName(ENUM_TIMEFRAMES period)
{
   switch(period)
   {
      case PERIOD_M1:  return ("M1");
      case PERIOD_M2:  return ("M2");
      case PERIOD_M3:  return ("M3");
      case PERIOD_M4:  return ("M4");
      case PERIOD_M5:  return ("M5");
      case PERIOD_M6:  return ("M6");
      case PERIOD_M10: return ("M10");
      case PERIOD_M12: return ("M12");
      case PERIOD_M15: return ("M15");
      case PERIOD_M20: return ("M20");
      case PERIOD_M30: return ("M30");
      case PERIOD_H1:  return ("H1");
      case PERIOD_H2:  return ("H2");
      case PERIOD_H3:  return ("H3");
      case PERIOD_H4:  return ("H4");
      case PERIOD_H6:  return ("H6");
      case PERIOD_H8:  return ("H8");
      case PERIOD_H12: return ("H12");
      case PERIOD_D1:  return ("D1");
      case PERIOD_W1:  return ("W1");
      case PERIOD_MN1: return ("MN1");
      case PERIOD_CURRENT: return (GetTimeFrameName(Period()));
   }
   return ("");
}
//+------------------------------------------------------------------+
double PipsToPoints(double pips)
{
  //------------------------------------------------------------------
  if (_Digits == 5 || _Digits == 3) pips *= 10;
  return (pips * _Point);
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+
double PointsToPips(double points)
{
  //------------------------------------------------------------------
  if (_Digits == 5 || _Digits == 3) points /= 10;
  return (points / _Point);
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+

            
Files: