This indicator dose not refresh data

Ahmed Abd El Aziz  

Hello


I wander what is the mistake in this indicator because it isn't update the data on chart every candle?


#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_width1 1
#property indicator_color1 0x40FF00
#property indicator_label1 "Buy"
#property indicator_chart_window
 string            InpName="Label";         // Label name 
 int               InpX=777;                // X-axis distance 
 int               InpY=50;                // Y-axis distance 
 string            InpFont="Arial";         // Font 
 int               InpFontSize=14;          // Font size 
 color             InpColor=clrRed;         // Color 
 double            InpAngle=0.0;            // Slope angle in degrees 
 ENUM_ANCHOR_POINT InpAnchor=ANCHOR_CENTER; // Anchor type 
 bool              InpBack=false;           // Background object 
 bool              InpSelection=false;       // Highlight to move 
 bool              InpHidden=false;          // Hidden in the object list 
 long              InpZOrder=0;             // Priority for mouse click 
//--------------------------------------------------------------------------------------------------------
//--- indicator buffers
double Buffer1[];
double myPoint; //initialized in OnInit
double Open[];
double Close[];
double Low[];
double High[];
//+------------------------------------------------------------------+ 
//| Create a text label                                              | 
//+------------------------------------------------------------------+ 
bool LabelCreate(const long              chart_ID=0,               // chart's ID 
                 const string            name="Label",             // label name 
                 const int               sub_window=0,             // subwindow index 
                 const int               x=0,                      // X coordinate 
                 const int               y=0,                      // Y coordinate 
                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // chart corner for anchoring 
                 const string            text="Label",             // text 
                 const string            font="Arial",             // font 
                 const int               font_size=10,             // font size 
                 const color             clr=clrRed,               // color 
                 const double            angle=0.0,                // text slope 
                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type 
                 const bool              back=false,               // in the background 
                 const bool              selection=false,          // highlight to move 
                 const bool              hidden=true,              // hidden in the object list 
                 const long              z_order=0)                // priority for mouse click 
  { 
  

//--- create a text label 
   if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create text label! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set label coordinates 
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 
//--- set the chart's corner, relative to which point coordinates are defined 
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 
//--- set the text 
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 
//--- set text font 
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 
//--- set font size 
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 
//--- set the slope angle of the text 
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); 
//--- set anchor type 
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 
//--- set color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the label by mouse 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Script program start function                                    | 
//+------------------------------------------------------------------+ 
int OnInit()
  { 
   double Market_Price1= iHigh(_Symbol,PERIOD_CURRENT,1);
   double TP1 = NormalizeDouble(Market_Price1,5);

//--- store the label's coordinates in the local variables 
   int x=InpX; 
   int y=InpY;
//--- chart window size 
   long x_distance; 
   long y_distance; 

   if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance)) 
     { 
      Print("Failed to get the chart width! Error code = ",GetLastError()); 
       
     } 
   if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance)) 
     { 
      Print("Failed to get the chart height! Error code = ",GetLastError()); 
       
     } 
//--- check correctness of the input parameters 
   if(InpX<0 || InpX>x_distance-1 || InpY<0 || InpY>y_distance-1) 
     { 
      Print("Error! Incorrect values of input parameters!"); 
     } 
//--- create a text label on the chart 
if(!LabelCreate(0,InpName,0,888,44,CORNER_LEFT_UPPER,""+(string)TP1,InpFont,InpFontSize, 
clrBlue,InpAngle,InpAnchor,InpBack,InpSelection,InpHidden,InpZOrder)) 
{ 

}
//=============================================================================================================  
   SetIndexBuffer(0, Buffer1);
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(0, PLOT_ARROW, 241);
   
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   
   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);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
     }
   else
      limit++;
   datetime Time[];
   
   if(CopyOpen(Symbol(), PERIOD_CURRENT, 0, rates_total, Open) <= 0) return(rates_total);
   ArraySetAsSeries(Open, true);
   if(CopyClose(Symbol(), PERIOD_CURRENT, 0, rates_total, Close) <= 0) return(rates_total);
   ArraySetAsSeries(Close, true);
   if(CopyLow(Symbol(), PERIOD_CURRENT, 0, rates_total, Low) <= 0) return(rates_total);
   ArraySetAsSeries(Low, true);
   if(CopyHigh(Symbol(), PERIOD_CURRENT, 0, rates_total, High) <= 0) return(rates_total);
   ArraySetAsSeries(High, true);
   if(CopyTime(Symbol(), Period(), 0, rates_total, Time) <= 0) return(rates_total);
   ArraySetAsSeries(Time, true);
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(200000-1, rates_total-1-150)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   

      //Indicator Buffer 1
      if(((Open[1+i] >= Close[1+i])||(Open[1+i] <= Close[1+i]))
      )
        {
         Buffer1[i] = High[1+i]; 
         
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
Carl Schreiber  
Code-Debugging - Programme entwickeln - MetaEditor Hilfe
Code-Debugging - Programme entwickeln - MetaEditor Hilfe
  • www.metatrader5.com
MetaEditor hat einen eingebauten Debugger, mit dem Sie die Programmausführung Schritt für Schritt (durch einzelne Funktionen) ü...
Ahmed Abd El Aziz  
Carl Schreiber #:

Use Comment() and/or Print() or the debugger to show the relevant variables and the debugger:

    https://www.metatrader5.com/de/metaeditor/help/development/debug
    https://www.mql5.com/en/articles/654
    https://www.mql5.com/en/articles/35
    https://www.mql5.com/en/articles/2041
    https://www.mql5.com/en/articles/150

I really tried to read this articles and made many tries. I thought that the mistake in deleting object or return.

Is am right?