Gap finder with number of historical arrows to show

 

Hey guys hope everyone is doing well. I am seeking help to fix a free indicator.

I just had a free Gap finder indicator that i have tried to edit. It has 4 buffers. Bullish, bearish gaps and also filled gaps arrows. The source code can only hide filled gaps arrow but not the original gap arrows even with the historical bars set to minimum

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                  VOLUME GAPS.mq4 |
//|                                    Copyright 2023,  ISMAIL LEMIN |
//+------------------------------------------------------------------+
//| This indicator plots Bullish Gaps and Bearish gaps.              |
//| It also plots or hides closed gaps.                              |
//| Trader can select the minimum gap size in points.                |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023 ISMAIL LEMIN"
#property description "VOLUME GAPS Indicator"
#property version   "2.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   4
//--- plot Bullish Gaps
#property indicator_label1  "GAP UP"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Bearish Gaps
#property indicator_label2  "GAP DOWN"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Closed Bullish Gaps
#property indicator_label3  "UP Closed"
#property indicator_type3   DRAW_ARROW
#property indicator_color3  clrGreen
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot Closed Bearish Gaps
#property indicator_label4  "DOWN Closed"
#property indicator_type4   DRAW_ARROW
#property indicator_color4  clrRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- input parameters
input int      min_gap_size=10;//Min gap size in points
input bool     check_closed_gaps=true;//Check for closed gaps
input int      history_bars=500;//Max history bars for closed gaps
input bool     hide_closed_gaps=true;//Hide closed gaps
input bool     show_alert=true;//Show Alerts
input bool     notify=true; //Send notifications    i added this option for phone notifications
//--- indicator buffers
double         up_openBuffer[];
double         dn_openBuffer[];
double         up_closedBuffer[];
double         dn_closedBuffer[];
datetime       bar_time=0;//to control signals on current bar
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- input validations
   if(min_gap_size<1)
     {
      Alert("Invalid Gap Size, must be > 0");
      return(INIT_PARAMETERS_INCORRECT);
     }
//--- indicator buffers mapping
   SetIndexBuffer(0,up_openBuffer);
   SetIndexBuffer(1,dn_openBuffer);
   SetIndexBuffer(2,up_closedBuffer);
   SetIndexBuffer(3,dn_closedBuffer);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   SetIndexArrow(0,236);
   SetIndexArrow(1,238);
   SetIndexArrow(2,120);
   SetIndexArrow(3,120);

   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;
//-- check for new gaps --------------------------------------------------------
   limit=MathMax(limit,2);
   for(int i=limit-2; i>=0; i--)
     {
      if(i==0)
        {
         if(Time[0]==bar_time) continue;
         else bar_time=Time[0];
        }
      if(up_openBuffer[i]!=EMPTY_VALUE || dn_openBuffer[i]!=EMPTY_VALUE) continue;
      if(Open[i]>Close[i+1]+min_gap_size*Point) //bullish gap
        {
         up_openBuffer[i]=Open[i];
         if(show_alert && i==0) Alert("Bullish Gap "+DoubleToStr(MathAbs((Open[i]-Close[i+1])/Point),0)+" on "+Symbol()+","+periodName(_Period)+" @ "+DoubleToStr(Open[i],Digits));
         if(notify && i==0) SendNotification("Bullish Gap "+DoubleToStr(MathAbs((Open[i]-Close[i+1])/Point),0)+" on "+Symbol()+","+periodName(_Period)+" @ "+DoubleToStr(Open[i],Digits)); // added this line for notification
        
        }
      if(Open[i]<Close[i+1]-min_gap_size*Point) //bearish gap
        {
         dn_openBuffer[i]=Open[i];
         if(show_alert && i==0) Alert("Bearish Gap "+DoubleToStr(MathAbs((Open[i]-Close[i+1])/Point),0)+" on "+Symbol()+","+periodName(_Period)+" @ "+DoubleToStr(Open[i],Digits));
         if(notify && i==0) SendNotification("Bearish Gap "+DoubleToStr(MathAbs((Open[i]-Close[i+1])/Point),0)+" on "+Symbol()+","+periodName(_Period)+" @ "+DoubleToStr(Open[i],Digits)); // added this line for notification
          
        }
     }
//-- check for closed gaps ----------------------------------------
   if(check_closed_gaps)
     {
      for(int i=history_bars-1; i>=0; i--)
        {
         if(up_closedBuffer[i]!=EMPTY_VALUE || dn_closedBuffer[i]!=EMPTY_VALUE) continue;
         if(up_openBuffer[i]==EMPTY_VALUE && dn_openBuffer[i]==EMPTY_VALUE) continue;
         if(up_openBuffer[i]!=EMPTY_VALUE)
           {
            if((i>0 && Low[iLowest(Symbol(),0,MODE_LOW,i+1,0)]<=Close[i+1]) || (i==0 && Low[0]<=Close[1]))//bullish gap closed
              {
               if(hide_closed_gaps) up_openBuffer[i]=EMPTY_VALUE;
               else
                 {
                  up_openBuffer[i]=EMPTY_VALUE;
                  up_closedBuffer[i]=Open[i];
                 }
               if(show_alert && i==0) Alert("Bullish Gap Closed "+" on "+Symbol()+","+periodName(_Period)+" @ "+DoubleToStr(Close[i],Digits));
               if(notify && i==0) SendNotification("Bullish Gap Closed "+" on "+Symbol()+","+periodName(_Period)+" @ "+DoubleToStr(Close[i],Digits));  // added this line for notification
              
              }

           }
         if(dn_openBuffer[i]!=EMPTY_VALUE)
           {
            if((i>0 && High[iHighest(Symbol(),0,MODE_HIGH,i+1,0)]>=Close[i+1]) || (i==0 && High[0]>=Close[1]))//bearish gap closed
              {
               if(hide_closed_gaps) dn_openBuffer[i]=EMPTY_VALUE;
               else
                 {
                  dn_openBuffer[i]=EMPTY_VALUE;
                  dn_closedBuffer[i]=Open[i];
                 }
               if(show_alert && i==0) Alert("Bearish Gap Closed "+" on "+Symbol()+","+periodName(_Period)+" @ "+DoubleToStr(Close[i],Digits));
               if(notify && i==0) SendNotification("Bearish Gap Closed "+" on "+Symbol()+","+periodName(_Period)+" @ "+DoubleToStr(Close[i],Digits)); // added this line for notification
             
              }

           }

        }
     }
   return(rates_total);
  }
//+---------------------------------------------------------------------------+
//| a function to return period name as a string to be used in alert messages |
//+---------------------------------------------------------------------------+

string periodName(int period)
  {
   switch(period)
     {
      case 1: return("M1");
      case 5: return("M5");
      case 15: return("M15");
      case 30: return("M30");
      case 60: return("H1");
      case 240: return("H4");
      case 1440: return("D1");
      case 10080: return("W1");
      case 43200: return("MN1");
      default: return("");
     }
  }
//+------------------------------------------------------------------+


.  This results to a cluttered chart with so many diagonal arrows 

Also, I added a line for sending notification, but the notifications are not coming. Am not sure what I did wrong with the notification line.

Kindly someone help me hide the historical gaps arrow alongside the filled gaps arrows. Also if possible the notification code line.

Thank you in advance.

 
Your topic has been moved to the section: MQL4 and MetaTrader 4 — Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Re. notifications I would start with a dedicated function with error handling, example:

#property strict

input bool notify = true;
//+------------------------------------------------------------------+
void OnStart()
  {
   int i = 0;
   if(i == 0)
     {
      string message = StringFormat("Bearish Gap %g on %s,%s @ %g", MathAbs((Open[i] - Close[i + 1]) / Point), Symbol(), (_Period), Open[i]);
      MobileNotification(message);
     }
  }
//+------------------------------------------------------------------+
void MobileNotification(string message)
  {
   if(!notify)
      return;
   if(TerminalInfoInteger(TERMINAL_NOTIFICATIONS_ENABLED) == false)
     {
      Print("Notifications are not enabled in the terminal. Exiting...");
     }
   else
     {
      ResetLastError();
      if(!SendNotification(message))
         Print("Error sending notification. Error code = ", GetLastError());
     }
  }
//+------------------------------------------------------------------+
 
Marcin Madrzak #:

Re. notifications I would start with a dedicated function with error handling, example:

Hey Marcin, hope you are doing well. Could you please just guide me on where to place the line. Is it a new function call or an iteration. Kindly help me get notification line to work. I really need the help because am not very good at coding. 
 
Marcin Madrzak #:

Re. notifications I would start with a dedicated function with error handling, example:

Hello Marcin, I fixed the notifications issue thanks for your help. 

I still can't edit the history bar to hide the original arrows. It will only hide the arrows gaps that were fully filled leaving the chart with so many diagonal arrows .please help ,e fix that .honestly am not good at coding still struggling financially to afford full programming. Please help me fix the indicator. I will really appreciate it.

Reason: