This indicator dose not refresh data

Ahmed Abd El Aziz  


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 
 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 
            ": failed to create text label! Error code = ",GetLastError()); 
//--- set label coordinates 
//--- set the chart's corner, relative to which point coordinates are defined 
//--- set the text 
//--- set text font 
//--- set font size 
//--- set the slope angle of the text 
//--- set anchor type 
//--- set color 
//--- display in the foreground (false) or background (true) 
//--- enable (true) or disable (false) the mode of moving the label by mouse 
//--- hide (true) or display (false) graphical object name in the object list 
//--- set the priority for receiving the event of a mouse click in the chart 
//--- successful execution 
//| 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; 

      Print("Failed to get the chart width! Error code = ",GetLastError()); 
      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 

   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;

//| 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);
   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]; 
         Buffer1[i] = EMPTY_VALUE;
Carl Schreiber  
Code-Debugging - Programme entwickeln - MetaEditor Hilfe
Code-Debugging - Programme entwickeln - MetaEditor Hilfe
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:

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

Is am right?