How to move an Label Object to the Current Price position?

 

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);
  }
 
   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 ? 

 

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

 

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 

 
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 

 

Hello 

Can I ask how you anchor the text with time and price. I thinking of displaying the bid price to it.

 
lsqnet79:

Hello 

Can I ask how you anchor the text with time and price. I thinking of displaying the bid price to it.

Keith Watford:

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

Reason: