Set Button on Horizontal Line

 

I am trying to set a button at the high of a specific candle with a double click. 

The button is not showing up. Can someone please advise what is wrong with the attached code. 
Files:
Entry.mq4  5 kb
 
   ObjectSet("EntryButton", OBJPROP_XDISTANCE, HighPrice);       
       ObjectSet("EntryButton", OBJPROP_YDISTANCE, StartTime);
Anchor points (x,y) are pixels, not price or time.
 
William Roeder #:
Anchor points (x,y) are pixels, not price or time.

Thanks for the comment.

I changed it to:

       ObjectSet("EntryButton", OBJPROP_PRICE, HighPrice);       

       ObjectSet("EntryButton", OBJPROP_TIME, StartTime);

But the Button is static and not at the right place.

 
Manshir #: Thanks for the comment. I changed it to:  ObjectSet("EntryButton", OBJPROP_PRICE, HighPrice);  ObjectSet("EntryButton", OBJPROP_TIME, StartTime); But the Button is static and not at the right place.

I suggest you read the documentation again.

A button graphic object is anchored by the x,y pixel coordinates: OBJPROP_XDISTANCE, OBJPROP_YDISTANCE (see William's post #1)

It does not use price or time coordinates or properties.

 
Fernando Carreiro #:

I suggest you read the documentation again.

A button graphic object is anchored by the x,y pixel coordinates: OBJPROP_XDISTANCE, OBJPROP_YDISTANCE (see William's post #1)

It does not use price or time coordinates or properties.

I understand that button is anchored to x,y coordinates. Is there a way I can convert OHLC to x,y coordinates?
 
Manshir #: I understand that button is anchored to x,y coordinates. Is there a way I can convert OHLC to x,y coordinates?

Theoretically yes, but not at all practical. You would have to keep track of chart shifts in time and price constantly with chart events and constantly adjust.

Instead use other types of graphical objects that can be anchored to price/time and react to mouse click events on those objects instead, to change their states or visual appearances to mimic the functionality of a button. It will be simpler and easier than trying to convert x,y to price/time for a button object.

 
Manshir #: I understand that button is anchored to x,y coordinates. Is there a way I can convert OHLC to x,y coordinates?

Perhaps you should read the manual.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

You used ChartXYToTimePrice in your code. “Is there a way?” ChartTimePriceToXY

 
Fernando Carreiro #:

Theoretically yes, but not at all practical. You would have to keep track of chart shifts in time and price constantly with chart events and constantly adjust.

Instead use other types of graphical objects that can be anchored to price/time and react to mouse click events on those objects instead, to change their states or visual appearances to mimic the functionality of a button. It will be simpler and easier than trying to convert x,y to price/time for a button object.

You are right. I used the ChartTimePriceToXY but the button is constantly adjusting with chart shifts. 

Can you please suggest the most appropriate graphical object that I can use.

 
Manshir #: You are right. I used the ChartTimePriceToXY but the button is constantly adjusting with chart shifts. Can you please suggest the most appropriate graphical object that I can use.

That is up to you what type of visual you what to have. There are rectangles, triangles, elipses, arrows, text, bitmaps, etc.

 
Manshir #: ut the button is constantly adjusting with chart shifts.
The button never shifts with the chart; just like a label. You are moving it.
 
@William Roeder #: The button never shifts with the chart; just like a label. You are moving it.
But that is exactly the point! The OP wants it to shift and follow the candle, not stay fixed on the chart. He wants it relative to a candle.
Reason: