vertical line

 

hello,

 https://www.mql5.com/en/docs/objects/objectcreate

a vertical line doesn't appear in my chart window (Bar 0 is needed) of a custom indicator

when this function is defined (definition part)

bool  ObjectCreate(

   long         chart_id,    
   string       name,        
   ENUM_OBJECT  type,        
   int          sub_window,  
   datetime     time1        

   );

and in the OnCalculate part  ObjectCreate(0,"N",OBJ_VLINE,0,0,0) is used ?

----

when trying ObjectCreate(0,"N",OBJ_VLINE,0,0);  (subwindow and time)  > the message "function must have a body" appears

For helpful hints thanks in advance

Documentation on MQL5: Object Functions / ObjectCreate
Documentation on MQL5: Object Functions / ObjectCreate
  • www.mql5.com
Object Functions / ObjectCreate - Reference on algorithmic/automated trading language for MetaTrader 5
 

Try this:

ObjectCreate(ChartID(), "N", OBJ_VLINE, 0, Time[0],0);


 

 
fxnew5: "function must have a body" appears
bool  ObjectCreate(
   long         chart_id,    
   string       name,        
   ENUM_OBJECT  type,        
   int          sub_window,  
   datetime     time1        
   );
  1. You have what appears to be a definition but  where is no function body
    returnType FunctionName(type arg1, ...){ function body }
  2. ObjectCreate is a MT5 function, already defined. You can't use that name.
ObjectCreate - Object Functions - MQL4 Reference
ObjectCreate - Object Functions - MQL4 Reference
  • docs.mql4.com
ObjectCreate - Object Functions - MQL4 Reference
 
Janusz Trojca:

Try this:

ObjectCreate(ChartID(), "N", OBJ_VLINE, 0, Time[0],0);


 

thanks Janusz & WH, but this looks like the MT4 code?

in MT4 I just tried it, works fine and pratical (nothing to declare first) to use as usual.... but in my MT5 code this command doesn't work.

"Time[0] undeclared identifier"


the MT5 description in the manual looks similar to MT4, but it seems that one has to declare such a function("ObjectCreate") first or not?

but what's the final step to get a vertical line placed (MT5) on Bar 0 ??

test code is empty apart from

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {ObjectCreate(ChartID(), "N", OBJ_VLINE, 0, Time[0],0);        return(0);}

 

Yes, you are right. In MQL5 Time[0] doesn't exist, so you must obtain last candle time by CopyRates function:

   MqlRates rates[];
   CopyRates(_Symbol, _Period, 0, 1, rates);  
   ObjectCreate(ChartID(), "N", OBJ_VLINE, 0, rates[0].time,0);