drawTextRelative( barIndex, yValue, text, fgColor, bgColor, Flags, fontName, fontSize [, tagID] [, cx] [, cy] )
The drawTextRelative function allows you to draw text objects at any location on your chart. Any text object created with drawTextRelative will 'stick' to the location where it was originally anchored. So, a text object originally created at a bar index of -10 will be at a bar index of -20 after 10 new bars come in.
Parameters
barIndex
|
the bar index where the text object will be anchored (x-axis)
|
yValue
|
the series value where the text object will be anchored (y-axis)
|
text
|
the symbol or text string to draw
|
fgColor
|
optional. the foreground color to use or null
|
bgColor
|
optional. the background color to use or null
|
Flags
|
optional. see Text Flags below or use null
|
fontName
|
optional. the font to use when creating the text object or null
|
fontSize
|
optional. the size of the font to use or null
|
tagID
|
optional. a unique identifier for this text object or null
|
cx
|
optional. pixel spacing control - or omitted
|
cy
|
optional. pixel spacing control - or omitted
|
Text Flags
Text.BOLD
|
display the text in bold
|
Text.ITALIC
|
display the text in italics
|
Text.UNDERLINE
|
underline the text
|
Text.LEFT
|
align the text to the left
|
Text.RIGHT
|
align the text to the right
|
Text.TOP
|
align the text to the top
|
Text.BOTTOM
|
align the text to the bottom
|
Text.ONTOP
|
draw the text on top of the study
|
Text.FRAME
|
draws a frame around the text using fgColor as the frame color
|
Text.BUTTON
|
draws the text as a button. fgColor and bgColor are ignored
|
Text.RELATIVETOLEFT
|
keeps the text fixed at a relative pixel distance from the left chart axis
|
Text.RELATIVETOBOTTOM
|
keeps the text fixed at a relative pixel distance from the bottom chart axis
|
Text.RELATIVETOTOP
|
keeps the text fixed at a relative pixel distance from the top chart axis
|
Text.CENTER
|
horizontally center the text over the bar
|
Text.VCENTER
|
vertically center the text at the series value
|
Text.PRESET
|
(new in EFS2) allows drawTextRelative to use the location flags described in the drawText function.
|
Note: Text flags can be ORed together to combine various attributes (e.g., Text.ITALIC | Text.BOLD | Text.UNDERLINE)
|
Notes re the cx and cy parameters
· | The cx and cy parameters control the width (cx) and height (cy) of the text label. They are not very useful unless you are using them in conjunction with the text flags RELATIVETOTOP, RELATIVETOLEFT and RELATIVETOBOTTOM. Without these flags the parameters will be relative to the bar index for cx and the price scale for cy. |
· | Both cx and cy require whole numbers. |
· | You can pass positive or negative numbers to these parameters. If you use positive whole number then the size is based on that number of pixels: |
· | cx of 15 will be the width of the text label of 15 pixels |
· | cy of 15 will be the height of the text label of 15 pixels |
· | If you use negative whole numbers then the size is relative to the specified font size: |
· | cx of -15 will be the approximate width of 15 characters of the specified font |
· | cy of -2 will be 2 times the height of the specified font. -3 would be 3 times the height, etc. |
Usage
//draw the letter X at the 55.0 price level 10 bars back, color the text blue
//and display it in the Courier New font, center it over the bar
drawTextRelative( -10, 55.0, "X", Color.blue, null, Text.ONTOP | Text.CENTER, "Courier New", 10 );
//use the Text.PRESET flag to draw the letter B above the high of the current bar, color it red and
//display it with a bold attribute in a 12-pt fontsize.
drawTextRelative( 0, AboveBar1, "B", Color.red, null, Text.PRESET | Text.BOLD, null, 12 );
Special Characters
|