Line Positioning Query

 

Hi hope someone might help me with this query.

Instead of having a horizontal line across my entire chart at calculated price levels, I wish to:

  • control the length of the horizontal line; and
  • reference the line's  horizontal position relative to the chart window (not time); and
  • have the lines vertical position vary with price (changing at the close of each bar for example)

Is this possible? If yes, help please....

If I try this using:

ObjectCreate ("Line", OBJ_TREND, 0, 0, 0, 0, 0); etc

then I assume I must reference the start and finish of the horizontal line by time and not chart window

so I tried using this approach, where my generated horizontal line was a label made up of text:

if (ObjectFind   ("Line") == -1)
           ObjectCreate ("Line", OBJ_LABEL,0,0,0);                      
           ObjectSet    ("Line", OBJPROP_CORNER,   1);                       
           ObjectSet    ("Line", OBJPROP_XDISTANCE,10);                    
           ObjectSet    ("Line", OBJPROP_YDISTANCE,100);        
           ObjectSet    ("Line", OBJPROP_COLOR, Black);
           ObjectSetText("Line", "____",font_size,"Arial",Black);

Whilst this works for a specified OBJPROP_YDISTANCE equal to a fixed integer

I need the horizontal line to change levels with the change of price, and if I insert

OBJPROP_YDISTANCE=(iClose(NULL, PERIOD_H1, 0), the code compiles without error,

But my label disappears.

Would someone suggest a solution?

Note: I do have this working where I specify the line position relative to Time[0], but it gets messy when I change screen sizes

thanks in advance !!

 
What are you trying to do with this horizontal line ?
Note: I do have this working where I specify the line position relative to Time[0], but it gets messy when I change screen sizes

You have to use a trend line, with time and price. What is "messy" when you change "screen sizes" ?

 
pullend:


If I try this using:

ObjectCreate ("Line", OBJ_TREND, 0, 0, 0, 0, 0); etc

then I assume I must reference the start and finish of the horizontal line by time and not chart window

so I tried using this approach, where my generated horizontal line was a label made up of text:

<SNIP>

Whilst this works for a specified OBJPROP_YDISTANCE equal to a fixed integer

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.

 
pullend:

Hi hope someone might help me with this query.

Instead of having a horizontal line across my entire chart at calculated price levels, I wish to:

  • control the length of the horizontal line; and
  • reference the line's  horizontal position relative to the chart window (not time); and
  • have the lines vertical position vary with price (changing at the close of each bar for example)

Is this possible? If yes, help please....


Whilst this works for a specified OBJPROP_YDISTANCE equal to a fixed integer

I need the horizontal line to change levels with the change of price, and if I insert

OBJPROP_YDISTANCE=(iClose(NULL, PERIOD_H1, 0), the code compiles without error,

But my label disappears.

You need to red the Documentation for ObjectSet()  the second parameter is one of these . . .  Object properties enumeration  not your price position . . . 

If you want to place an object by pixel coordinates then pick one that is placed by pixel coordinates,  if you want to place an object by time and price use an object type that is placed by time and price . . . . if you need to mix coordinate types then you have to convert one of the coordinates to/from a pixel value. 

 
RaptorUK:

You need to red the Documentation for ObjectSet()  the second parameter is one of these . . .  Object properties enumeration  not your price position . . . 

If you want to place an object by pixel coordinates then pick one that is placed by pixel coordinates,  if you want to place an object by time and price use an object type that is placed by time and price . . . . if you need to mix coordinate types then you have to convert one of the coordinates to/from a pixel value. 


Thanks Raptor I spent a fair bit of time reading the documentation before the post, but as usual just did not get my language quite correct.

I knew the difference in required object properties, just did not know that you could could convert co-ordinates to pixel values, in this case my price values to pixell values

Again as usual you have poined me in right direction.

I've just made a search and noticed a few threads on "converting co-ordinates"

So will go away and research, then report back

thanks again!!

 
angevoyageur:
What are you trying to do with this horizontal line ?

You have to use a trend line, with time and price. What is "messy" when you change "screen sizes" ?



With a LOT of help from Raptor in a previous thread, I have put together an indicator that shows me price levels of other time frames, visible as small horizontal lines, drawn on my active chart, right of the current candle. ( I have my charts set up with Chart Shift On)

This works nicely and allows me to offset the lines to varying degrees.

However, if I change monitor sizes or computers, I find that my lines visible previously on a 23inch monitor, are not visible on my laptop etc

ie. they are pushed off the screen

As I type, thinking that rather than converting cordinates to pixel values, perhaps I should just add an external screen size "factor" and allow me to scale back my offsets with one simple change

Hope this makes sense, the base code below

 
pullend:

With a LOT of help from Raptor in a previous thread, I have put together an indicator that shows me price levels of other time frames, visible as small horizontal lines, drawn on my active chart, right of the current candle. ( I have my charts set up with Chart Shift On)

This works nicely and allows me to offset the lines to varying degrees.

However, if I change monitor sizes or computers, I find that my lines visible previously on a 23inch monitor, are not visible on my laptop etc

ie. they are pushed off the screen

As I type, thinking that rather than converting cordinates to pixel values, perhaps I should just add an external screen size "factor" and allow me to scale back my offsets with one simple change

Hope this makes sense, the base code below


sorry code would not attach, so will add in file


Files:
_mtf-levels.mq4  17 kb
Reason: