drawtext left alignment
Forums › ProRealTime English forum › ProRealTime platform support › drawtext left alignment
- This topic has 2 replies, 3 voices, and was last updated 3 months ago by robertogozzi.
Tagged: Bottom, bottomleft, BottomRight, drawrectangle, drawtext, graphical, graphics, left, middle, right, Top, topleft, TopRight, xshift, yshift
-
-
07/26/2024 at 12:30 PM #235807
Hi, it seems that drawtext draws the text center aligned at the barindex position but I would like to draw text left-aligned at barindex (first character at barindex position) . How can it be done?
Thxdrawtext demo1234567defparam DRAWONLASTBARONLY = true//Drawtext CENTERED at barindexdrawtext("asdadsfadfasdffasfasfd",BarIndex, 1 )drawtext("asdfa sfd asdfaf" ,BarIndex, 2)drawtext("asd fasfd" ,BarIndex, 3)//How to drawtext left aligned at barindex ?RETURN 0, 407/26/2024 at 2:17 PM #235809Unfortunately there is no basic test alignment commands.
The way I get around this is to use the monospaced text style.
Monospaced, is the only style which give the same width for each text character.
Since all characters are the same width, prefacing the required text with spaces,
gives an element of control and allows you to move the text in relationship to the overall centred text block.
A example of left aligning would be to pre fill the same number of space of the text before the text.
The equal spacing of characters, moves the wanted text to start at approximately the middle of block, depending on odd/even number of characters.
Using a combination of monospaced characters, and spaces before and/or after can give enough control to place and align text in most places.
With other styles this doesn’t work as well, because different characters have different widths relative to the space character.
1234567defparam DRAWONLASTBARONLY = true//Drawtext Left alligned at barindexdrawtext(" asdadsfadfasdffasfasfd",BarIndex, 1,monospaced,standard,12 )drawtext(" asdfa sfd asdfaf" ,BarIndex, 2,monospaced,standard,12)drawtext(" asd fasfd" ,BarIndex, 3,monospaced,standard,12)//How to drawtext left aligned at barindex ?RETURN 0, 407/26/2024 at 5:03 PM #235812You can take advantage of these new graphical instructions (actually they were added over 1 year ago, in V11):
12345678910111213Xshift : defines an abscissa coordinate in pixel offset from the anchor pointYshift : defines an ordinate coordinate in vertical pixel offset from the anchor pointIndex : Defines an abscissa coordinate in barindex (classic way)Value : Set an ordinate coordinate in price/value (classic way)bottomright : bottom-right corner of the chart, the offset values will always be negative to shift left (X axis) and positive to shift up (Y axis).bottomleft : bottom-left corner of the graph - the offset values will always be positive in order to shift to the right (X axis) and up (Y axis).topright : top-right corner of the graph - the offset values will always be negative in order to shift to the left (X axis) and down (Y axis).topleft : top-left corner of the graph - the offset values will always be positive in order to shift to the right (X axis) and negative in order to shift down (Y axis).right : middle-right point of the graph - the shift values will always be negative to shift to the left (X axis) and can be positive or negative to shift up(+)/down(-) (Y axis)left : middle-left point of the graph - the shift values will always be positive to shift to the right (X axis) and can be positive or negative to shift up(+)/down(-) (Y axis)top : middle-top point of the graph - the shift values can be positive or negative for shift right(+)/left(-) (X axis) and will always be negative to shift down (Y axis)bottom : middle-low point of the graph - the shift values can be positive or negative for shift to the right(+)/left(-) (X-Axis) and will always be positive in order to shift up (Y-Axis)middle : middle point of the graph - the shift values can be positive or negative for shift to the right(+)/left(-) (X-Axis) and can be positive or negative for shift up(+)/down(-) (Y-Axis)so that your code could be written as (see attached pic):
12345678910111213141516defparam DRAWONLASTBARONLY = true////Drawtext CENTERED at barindex//drawtext("asdadsfadfasdffasfasfd",BarIndex, 1 )//drawtext("asdfa sfd asdfaf" ,BarIndex, 2)//drawtext("asd fasfd" ,BarIndex, 3)//--------------------------------------------------------------------------------------------------------------------drawrectangle(-370,0,-235,-20) anchor(TopRight) coloured("YellowGreen") bordercolor("Black")drawtext ("asdadsfadfasdffasfasfd", -305 ,-10) anchor(TopRight) coloured("Black")//drawrectangle(-370,-20,-235,-40) anchor(TopRight) coloured("Silver") bordercolor("Black")drawtext ("asdfa sfd asdfaf", -323 ,-30) anchor(TopRight) coloured("Black")//drawrectangle(-370,-40,-235,-60) anchor(TopRight) coloured("PapayaWhip") bordercolor("Black")drawtext ("asd fasfd", -341 ,-50) anchor(TopRight) coloured("Black")//--------------------------------------------------------------------------------------------------------------------RETURN 0, 4 -
AuthorPosts
Find exclusive trading pro-tools on