Indicator not loading on second chart

 

Good day,

I have created this indicator to look for fair value gaps and it loads fine for 1 chart. But if I try to load it onto a second chart then it does not load. Can anybody advise why this would be the case? I did not limit the indicator to a specific chart. I would appreciate any assistance. I could not find anything in the forums related to this. I am using Mt5.

//+------------------------------------------------------------------+
//|                                                        H1FVG.mqh |
//|                                                      Bilal Jagot |
//|                                            https://www.noweb.com |
//+------------------------------------------------------------------+
#property copyright "Bilal Jagot"
#property link      "https://www.noweb.com"
//+------------------------------------------------------------------+
//| defines                                                          |
//+------------------------------------------------------------------+
// #define MacrosHello   "Hello, world!"
// #define MacrosYear    2010
//+------------------------------------------------------------------+
//| DLL imports                                                      |
//+------------------------------------------------------------------+
// #import "user32.dll"
//   int      SendMessageA(int hWnd,int Msg,int wParam,int lParam);
// #import "my_expert.dll"
//   int      ExpertRecalculate(int wParam,int lParam);
// #import
//+------------------------------------------------------------------+
//| EX5 imports                                                      |
//+------------------------------------------------------------------+
// #import "stdlib.ex5"
//   string ErrorDescription(int error_code);
// #import
//+------------------------------------------------------------------+
//--- indicator settings
#property indicator_chart_window
input bool SetAlerts = false;
input bool SendMobileNotification = false;
input color UpFVG_Border_Color = clrDodgerBlue;
input color DownFVG_Border_Color = clrDarkRed;
input bool myDebug = false;

//To limit to a specific period
//MqlDateTime str1;
//   TimeToStruct(TimeLocal(),str1);
//   if(str1.min%15==0)

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {

  }
//+------------------------------------------------------------------+
//| FVG over 3 bars                                                  |
//+------------------------------------------------------------------+
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[])
  {
   if(rates_total<5)
      return(0);
   
   int start=5;
   //If there has been no new candle then no need to process
   if (prev_calculated < rates_total) {
     start = 5;
   }
   else
     {
      start = prev_calculated;
     }
   
   double fvg_up;
   double fvg_down;

//--- main cycle of calculations
   for(int i=start; i<rates_total-2 && !IsStopped(); i++)
     {
      if (myDebug) Print("start= ",start,"i= ",i,"rate_total=",rates_total,"prev_calc=",prev_calculated);
      fvg_up = low[i]-high[i-2];
      fvg_down = low[i-2]-high[i];
      
      //--- FVG on up close[i]> close[i+2] fvg = low[i]-high[i+2] if fvg>0 then we have an FVG
      if(close[i] > close[i-2] && fvg_up > 1 && high[i]>high[i-1] && high[i-1]>high[i-2]) {         
         ObjectCreate(0,TimeToString(time[i],TIME_MINUTES),OBJ_RECTANGLE,0,time[i-2],high[i-2],time[i],low[i]);
         ObjectSetInteger(0,TimeToString(time[i],TIME_MINUTES),OBJPROP_SELECTABLE, true);
         ObjectSetInteger(0,TimeToString(time[i],TIME_MINUTES),OBJPROP_COLOR,UpFVG_Border_Color);
         ObjectSetInteger(0,TimeToString(time[i],TIME_MINUTES),OBJPROP_WIDTH, 2);
         
         //Set Alert on low[i]
         
         //Send notification
         if(SendMobileNotification)
           {
            SendNotification("UP FVG on "+Symbol()+":"+ TFName(Period()));
           }
      }
      
      //--- FVG on down close[i] < close [i+2] fvg=low[i+2]-high[i] if fvg>0 then we have an FVG
      if(close[i] < close[i-2] && fvg_down > 1 && low[i]<low[i-1] && low[i-1]<low[i-2]) {
      
         ObjectCreate(0,TimeToString(time[i],TIME_MINUTES),OBJ_RECTANGLE,0,time[i-2],low[i-2],time[i],high[i]);
         ObjectSetInteger(0,TimeToString(time[i],TIME_MINUTES),OBJPROP_SELECTABLE, true);
         ObjectSetInteger(0,TimeToString(time[i],TIME_MINUTES),OBJPROP_COLOR,DownFVG_Border_Color);
         ObjectSetInteger(0,TimeToString(time[i],TIME_MINUTES),OBJPROP_WIDTH, 2);
         
         //Set Alert on high[i]
         
         //Send notification
         if(SendMobileNotification)
           {
            SendNotification("DOWN FVG on "+Symbol()+":"+ TFName(Period()));
           }
      }
         
      if (myDebug) Print("i=",i," @ ",time[i],"FVG up=",fvg_up," FVG down=",fvg_down,"close[i]=",close[i],"close[i-1]=",close[i-1],"close[i-2]",close[i-2]);
      
      //Get inputs "Set Alerts, Send Notifications, Rectangle width, Specific timeframe"
      //Draw a rectangle for 10 candles going forward
      //Set an alert at the start of the FVG
     }
     
//--- OnCalculate done. Return new prev_calculated.
   if (myDebug) Print("Rates_total=",rates_total,"Prev_calculated",prev_calculated);
   return(rates_total);
  }

string TFName( int tf )
 {
  switch(tf) 
   {
      case PERIOD_M1: return(" M1"); break;
      case PERIOD_M5: return(" M5"); break;
      case PERIOD_M15: return(" M15"); break;
      case PERIOD_M30: return(" M30"); break;
      case PERIOD_H1: return(" H1"); break;
      case PERIOD_H4: return(" H4"); break;
      case PERIOD_D1: return(" Daily"); break;
      case PERIOD_W1: return(" Weekly"); break;
      default: return(" Monthly");
   }
  return("Unknown");
 }
 
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(ChartID(),0,OBJ_RECTANGLE);
  }
//+------------------------------------------------------------------+
 
Bilal Jagot:

Good day,

I have created this indicator to look for fair value gaps and it loads fine for 1 chart. But if I try to load it onto a second chart then it does not load. Can anybody advise why this would be the case? I did not limit the indicator to a specific chart. I would appreciate any assistance. I could not find anything in the forums related to this. I am using Mt5.

You mean it loads if you choose the second chart as first chart? Strange enough... please check the chart that is not working separately. If it loads on a chart does not mean it is not going to face bugs in all charts.

 
Maybe the chart have an different timeframe what you dont have in your list