Getting Error => Error code = 4200

 

All the news and vertical line successfully showing in chart but in Experts tab under Terminal keep showing Error code = 4200 for both TextObject and Vertical Line.


Error : Error code = 4200

//+------------------------------------------------------------------+
//| Creating Text object                                             |
//+------------------------------------------------------------------+
bool TextCreate(const long              chart_ID=0,               // chart's ID
                const string            name="Text",              // object name
                const int               sub_window=0,             // subwindow index
                datetime                time=0,                   // anchor point time
                double                  price=0,                  // anchor point price
                const string            text="Text",              // the text itself
                const color             clr=clrRed,               // color
                const string            font="Arial",             // font
                const int               font_size=10,             // font size
                const double            angle=90,                // text slope
                const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_LOWER, // 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
  {

//--- reset the error value
   ResetLastError();
//--- create Text object
   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
     {
      Print(__FUNCTION__,
            ": failed to create \"Text\" object! Error code = ",GetLastError());
      return(false);
     }
//--- 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 object 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);
  }

//+------------------------------------------------------------------+
//| Create the Verticle line                                         |
//+------------------------------------------------------------------+
bool VLineCreate(const long            chart_ID=0,        // chart's ID
                 const string          name="VLine",      // line name
                 const int             sub_window=0,      // subwindow index
                 datetime              time=0,            // line time
                 const color           clr=clrBlue,        // line color
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style
                 const int             width=1,           // line width
                 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 vertical line
   if(!ObjectCreate(chart_ID,name,OBJ_VLINE,sub_window,time,0))
     {
       ": failed to create \"Vline\" object! Error code = ",GetLastError());
      return(false);
     }
//--- set line color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line display style
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- 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 line by mouse
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
   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);
  }


if(news_High && (eImpact[qi][n]=="High"))
        {

            VLineCreate(0,"Tr_VLine"+TimeToString(eTime[qi][n]),0,eTime[qi][n]+(TimeCurrent()-TimeLocal()),clrRed,STYLE_SOLID);
            TextCreate(0,"NFtext_H"+TimeToString(eTime[qi][n] - 1),0,eTime[qi][n]+(TimeCurrent()-TimeLocal()-60),max_price,eTitle[qi][n],clrRed);
           
         if((tn <= eTime[qi][n] && tn >= (eTime[qi][n]-minBefore*60)) || (tn >= eTime[qi][n] && tn <= (eTime[qi][n]+minAfter*60)))
           {
            PauseHighNewsCheck = "NewsTime";
            newsresult = 1;
           } else { PauseHighNewsCheck = "NoNews"; }
        }
      if(news_Medium && (eImpact[qi][n]=="Medium"))
        {

            VLineCreate(0,"Tr_VLine"+TimeToString(eTime[qi][n]),0,eTime[qi][n]+(TimeCurrent()-TimeLocal()),clrOrange,STYLE_SOLID);
            TextCreate(0,"NFtext_M"+TimeToString(eTime[qi][n] - 2),0,eTime[qi][n]+(TimeCurrent()-TimeLocal()-60),max_price,eTitle[qi][n],clrOrange);
           
         if((tn <= eTime[qi][n] && tn >= (eTime[qi][n]-minBefore1*60)) || (tn >= eTime[qi][n] && tn <= (eTime[qi][n]+minAfter1*60)))
           {
            PauseMediumNewsCheck = "NewsTime";
            newsresult = 1;
           } else { PauseMediumNewsCheck = "NoNews"; }
        }
      if(news_Low && (eImpact[qi][n]=="Low"))
        {

            VLineCreate(0,"Tr_VLine"+TimeToString(eTime[qi][n]),0,eTime[qi][n]+(TimeCurrent()-TimeLocal()),clrYellow,STYLE_SOLID);
            TextCreate(0,"NFtext_L"+TimeToString(eTime[qi][n] - 3),0,eTime[qi][n]+(TimeCurrent()-TimeLocal()-60),max_price,eTitle[qi][n],clrYellow);
           
         if(((tn <= eTime[qi][n]) && (tn >= (eTime[qi][n]-minBefore2*60))) || ((tn >= eTime[qi][n]) && (tn <= (eTime[qi][n]+minAfter2*60))))
           {
            PauseLowNewsCheck = "NewsTime";
            newsresult = 1;
           } else { PauseLowNewsCheck = "NoNews"; }
        }



Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
anuj71: Error : Error code = 4200

You know what the error is and why. Stop trying to create the same object multiple times.

 
William Roeder #:
You know what the error is and why. Stop trying to create the same object multiple times.

I did not understand what you mean to say. I am not creating same object every time. Each object have unique name and unique title/time

 
anuj71 #: I did not understand what you mean to say. I am not creating same object every time. Each object have unique name and unique title/time

You are using the same name irrespective of the type of news (high, medium, low) ...

"Tr_VLine"+TimeToString(eTime[qi][n])

You made it unique for the other objects but not the "Tr_VLine" above ...

"NFtext_H"+TimeToString(eTime[qi][n] - 1)
"NFtext_M"+TimeToString(eTime[qi][n] - 2)
"NFtext_L"+TimeToString(eTime[qi][n] - 3)