ObjectCreate bug

 

I have problem with ObjectCreate in MQL5.

I coded as below and it seems working in backtest mode.

ObjectCreate(_Symbol,iTime(Symbol(),Period(),bar)+":Arrow",OBJ_ARROW,1, iTime(Symbol(),Period(),bar),Top_Level);


But,when I actually put the indicator to real charts,arrows are not created.

And ObjectCreate function return no error.

Anyone know how to solve this bug?

 
Tomoyuki Nakazima:

I have problem with ObjectCreate in MQL5.

I coded as below and it seems working in backtest mode.

ObjectCreate(_Symbol,iTime(Symbol(),Period(),bar)+":Arrow",OBJ_ARROW,1, iTime(Symbol(),Period(),bar),Top_Level);


But,when I actually put the indicator to real charts,arrows are not created.

And ObjectCreate function return no error.

Anyone know how to solve this bug?

Not a bug

Error in your code - starting from the wrong window in which you are trying to create the object. Correct your code - nothing wrong with ObjectCreate()

 
Mladen Rakic:

Not a bug

Error in your code - starting from the wrong window in which you are trying to create the object. Correct your code - nothing wrong with ObjectCreate()

No,I just realized OBJ_ARROW does not work.

OBJ_ARROW_UP works completely fine though.


I just realized I do not like mql5 too.

Anyway,never mind this thread.I will close this.

 
It's the same for MQL4 so no difference.
 
Marco vd Heijden:
It's the same for MQL4 so no difference.

Do you mean OBJ_ARROW does not work in mql4 too?

Or just am I dumb?

 

The code will be the same MQL4 and MQL5.

The problem is in your code.

Here are the font codes:


Here is some code to create an arrow, you can see the first parameter is Chart_ID where you used _Symbol in your code, which is not a bug but just wrong coding.

//+------------------------------------------------------------------+ 
//| Create the arrow                                                 | 
//+------------------------------------------------------------------+ 
bool ArrowCreate(const long              chart_ID=0,           // chart's ID 
                 const string            name="Arrow",         // arrow name 
                 const int               sub_window=0,         // subwindow index 
                 datetime                time=0,               // anchor point time 
                 double                  price=0,              // anchor point price 
                 const uchar             arrow_code=252,       // arrow code 
                 const ENUM_ARROW_ANCHOR anchor=ANCHOR_BOTTOM, // anchor point position 
                 const color             clr=clrRed,           // arrow color 
                 const ENUM_LINE_STYLE   style=STYLE_SOLID,    // border line style 
                 const int               width=3,              // arrow size 
                 const bool              back=false,           // in the background 
                 const bool              selection=true,       // highlight to move 
                 const bool              hidden=true,          // hidden in the object list 
                 const long              z_order=0)            // priority for mouse click 
  { 
//--- set anchor point coordinates if they are not set 
   ChangeArrowEmptyPoint(time,price); 
//--- reset the error value 
   ResetLastError(); 
//--- create an arrow 
   if(!ObjectCreate(chart_ID,name,OBJ_ARROW,sub_window,time,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create an arrow! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set the arrow code 
   ObjectSetInteger(chart_ID,name,OBJPROP_ARROWCODE,arrow_code); 
//--- set anchor type 
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 
//--- set the arrow color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- set the border line style 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
//--- set the arrow's size 
   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 arrow 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); 
  } 
//+------------------------------------------------------------------+ 
//| Move the anchor point                                            | 
//+------------------------------------------------------------------+ 
bool ArrowMove(const long   chart_ID=0,   // chart's ID 
               const string name="Arrow", // object name 
               datetime     time=0,       // anchor point time coordinate 
               double       price=0)      // anchor point price coordinate 
  { 
//--- if point position is not set, move it to the current bar having Bid price 
   if(!time) 
      time=TimeCurrent(); 
   if(!price) 
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID); 
//--- reset the error value 
   ResetLastError(); 
//--- move the anchor point 
   if(!ObjectMove(chart_ID,name,0,time,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to move the anchor point! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Change the arrow code                                            | 
//+------------------------------------------------------------------+ 
bool ArrowCodeChange(const long   chart_ID=0,   // chart's ID 
                     const string name="Arrow", // object name 
                     const uchar  code=252)     // arrow code 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- change the arrow code 
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_ARROWCODE,code)) 
     { 
      Print(__FUNCTION__, 
            ": failed to change the arrow code! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Change anchor type                                               | 
//+------------------------------------------------------------------+ 
bool ArrowAnchorChange(const long              chart_ID=0,        // chart's ID 
                       const string            name="Arrow",      // object name 
                       const ENUM_ARROW_ANCHOR anchor=ANCHOR_TOP) // anchor type 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- change anchor type 
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor)) 
     { 
      Print(__FUNCTION__, 
            ": failed to change anchor type! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Delete an arrow                                                  | 
//+------------------------------------------------------------------+ 
bool ArrowDelete(const long   chart_ID=0,   // chart's ID 
                 const string name="Arrow") // arrow name 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- delete an arrow 
   if(!ObjectDelete(chart_ID,name)) 
     { 
      Print(__FUNCTION__, 
            ": failed to delete an arrow! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Check anchor point values and set default values                 | 
//| for empty ones                                                   | 
//+------------------------------------------------------------------+ 
void ChangeArrowEmptyPoint(datetime &time,double &price) 
  { 
//--- if the point's time is not set, it will be on the current bar 
   if(!time) 
      time=TimeCurrent(); 
//--- if the point's price is not set, it will have Bid value 
   if(!price) 
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID); 
  } 
//+------------------------------------------------------------------+ 
 
Tomoyuki Nakazima:

Do you mean OBJ_ARROW does not work in mql4 too?

All is working with mql4 and mql5 objects, including OBJ_ARROW. Just learn how to use it.

Or just am I dumb?

Do you really want an answer ?