Download MetaTrader 5
To add comments, please log in or register
Hundreds of articles will help you to create a trading robot. Come and read them!
Wemerson Guimaraes
535
Wemerson Guimaraes 2016.01.18 20:05 

Hi, i need to move an label object to the current price position but not works... please see the code:

 

int OnInit(){
   
   if( ObjectFind("MyLabel") == -1)
      ObjectCreate(0, "MyLabel", OBJ_LABEL, 0, 0, 0);

   return(INIT_SUCCEEDED);

}

void OnDeinit(const int reason){

   if( ObjectFind("MyLabel") >=0 )
      ObjectDelete(0, "MyLabel");
      
}

//+------------------------------------------------------------------+
//| 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[])
  {
   ObjectSetText( "MyLabel", "My Text on label", 12, "Times New Roman", clrRed);
   ObjectSetInteger( "MyLabel", 0, Time[0], Close[0]); // Current Time, Current Price
   
   return(rates_total);
  }
Keith Watford
Moderator
7862
Keith Watford 2016.01.18 20:19  
   ObjectSetInteger( "MyLabel", 0, Time[0], Close[0]); // Current Time, Current Price

 

 You need to include the property that you are modifying.

Time can be modified by an integer,

price usually requires a double, so use ObjectSetDouble() for price

Why not use ObjectMove ? 

Wemerson Guimaraes
535
Wemerson Guimaraes 2016.01.18 20:28  

Sorry... paste wrong... this is the right... But not works!

 

...
   ObjectSetText( "MyLabel", "My Text on label", 12, "Times New Roman", clrRed);
   ObjectMove( "MyLabel", 0, Time[0], Close[0]); // Current Time, Current Price... Right!?!
   
   return(rates_total)

 

Need to move at the example on the image below and keep it at right of the current bar

 ObjectMove

Keith Watford
Moderator
7862
Keith Watford 2016.01.18 21:26  

Sorry,

I failed to notice that you had actually created a label.

A label is anchored by pixels. You need OBJ_TEXT to anchor with time and price 

Wemerson Guimaraes
535
Wemerson Guimaraes 2016.01.18 21:56  
GumRai:

Sorry,

I failed to notice that you had actually created a label.

A label is anchored by pixels. You need OBJ_TEXT to anchor with time and price 

Tx my friend... works fine now!

Anchor at current price 

/
To add comments, please log in or register