File Name: PixelSpacingEx.efs
Description:
Example formula illustrating the usage of the cx and cy parameters of the drawTextPixel() function. The formula draws a table containing 3 columns and 2 rows of text labels where the width and height of the labels is set by the cx and cy parameters.
Formula Parameters:
Column Width: 70
Row Thickness: -1
Font Size: 10
X Start: 20
Y Start: 20
Notes:
See comments in formula code.
Download File:
PixelSpacingEx.efs
EFS Code:
Description:
Example formula illustrating the usage of the cx and cy parameters of the drawTextPixel() function. The formula draws a table containing 3 columns and 2 rows of text labels where the width and height of the labels is set by the cx and cy parameters.
Formula Parameters:
Column Width: 70
Row Thickness: -1
Font Size: 10
X Start: 20
Y Start: 20
Notes:
See comments in formula code.
Download File:
PixelSpacingEx.efs
EFS Code:
PHP Code:
/**************
Provided By : eSignal (c) Copyright 2004
Description: Pixel Spacing Example
drawTextPixel(xBar, yValue, Text, [FGColor], [BGColor], [Flags],
[FontName], [FontSize], [TagName], [cx], [cy])
This function is used to draw text on the chart at precise pixel
locations. It is used in conjunction with the getTextHeight() and
getTextWidth() functions.
xBar: Relative position where text should appear.
yValue: y-axis value where text should appear
Text: The text that should be displayed
FGColor: Optional. If not provided, pass null. Foreground color of the text.
BGColor: Optional. if not provided, pass null. Background color of the text
Flags: Text Flags (these can be ORd together). Pass null if not using flags.
FontName: Optional. If not provided, pass null. Otherwise, pass a font name (e.g, "Courier" or "Arial").
FontSize: Optional. If not provided, pass null. Otherwise, pass the font size to use (e.g., 11 or 15 or 8, etc.)
TagName: A unique identifier for this text object.
cx: Optional. Pixel spacing control.
cy: Optional. Pixel spacing control.
Notes:
The cx and cy parameters control the
width (cx) and height (cy) of the text label. They are also
available in the drawTextRelative and drawTextAbsolute functions,
but are not very useful unless you are using them in combination
with text flags, RELATIVETOTOP, RELATIVETOLEFT and RELATIVETOBOTTOM.
Both cx and cy require whole numbers.
You can pass positive or negative numbers to these parameters.
If you use positive whole numbers 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 approxomate 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.
The formula example below draws a table containing
3 columns and 2 rows of text labels.
*************/
var nFontCY = 0;
var nFontCX = 0;
var nColWidth = 0;
var nRowThickness = 1;
var nFontSize = 10;
function preMain() {
setStudyTitle("Pixel Spacing Help Example");
setShowCursorLabel(false);
setShowTitleParameters(false);
/***** Column Width is used here for the cx parameter *****/
var fp = new FunctionParameter("inputColWidth", FunctionParameter.NUMBER);
fp.setName("Column Width");
fp.setDefault(70);
/***** Row Thickness is used here for the cy parameter *****/
var fp = new FunctionParameter("inputRowThickness", FunctionParameter.NUMBER);
fp.setName("Row Thickness");
fp.setDefault(-1);
var fp = new FunctionParameter("inputFontSize", FunctionParameter.NUMBER);
fp.setName("Font Size");
fp.setLowerLimit(1);
fp.setDefault(10);
/*****
With drawTextPixel, X Start = the number of pixels from the left of
the window.
With drawTextRelative or Absolute, X Start will be the bar index unless
the RELATIVETO### text flags are used. In which case the values
will represent pixels.
*****/
var fp = new FunctionParameter("inputXstart", FunctionParameter.NUMBER);
fp.setName("X Start");
fp.setLowerLimit(1);
fp.setDefault(20);
/*****
With drawTextPixel, Y Start = the number of pixels from the top of
the window.
With drawTextRelative or Absolute, Y Start will be relative to the
price scale of the chart symbol unless the RELATIVETO### text
flags are used. In which case the values will represent pixels.
*****/
var fp = new FunctionParameter("inputYstart", FunctionParameter.NUMBER);
fp.setName("Y Start");
fp.setLowerLimit(1);
fp.setDefault(20);
}
var bEdit = true;
function main(inputColWidth, inputRowThickness, inputFontSize,
inputXstart, inputYstart) {
// prevents the formula from executing except at bar 0 and on new bar.
if(getCurrentBarIndex() != 0 && getBarState() != BARSTATE_NEWBAR) return;
// initialization routine to set values for global variables
if (bEdit == true) {
nColWidth = Math.round(inputColWidth);
nRowThickness = Math.round(inputRowThickness);
nFontSize = Math.round(inputFontSize);
/***** Used for setting the space between x/y anchors for text
labels based on the font height *****/
if (nRowThickness < 0) {
nFontCY = getTextHeight("A", null, nFontSize)*(nRowThickness);
} else {
nFontCY = -nRowThickness;
}
/***** This will get the maximum width for the specified string
based on the specified font type. If the font type is not
specified it uses a default Arial. *****/
if (nColWidth < 0) {
nFontCX = getTextWidth("Row ## Col ##", null, nFontSize);
} else {
nFontCX = nColWidth;
}
bEdit = false;
}
var nX = inputXstart;
var nY = inputYstart;
// ROW 1 //
drawTextPixel(nX, nY, "Row 1 Col 1", Color.white, Color.blue,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r1c1", nColWidth, nRowThickness);
drawTextPixel(nX+=nFontCX, nY, "Row 1 Col 2", Color.white, Color.blue,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r1c2", nColWidth, nRowThickness);
drawTextPixel(nX+=nFontCX, nY, "Row 1 Col 3", Color.white, Color.blue,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r1c3", nColWidth, nRowThickness);
// ROW 2 //
nX = inputXstart;
nY -= nFontCY;
drawTextPixel(nX, nY, "Row 2 Col 1", Color.white, Color.blue,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r2c1", nColWidth, nRowThickness);
drawTextPixel(nX+=nFontCX, nY, "Row 2 Col 2", Color.white, Color.blue,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r2c2", nColWidth, nRowThickness);
drawTextPixel(nX+=nFontCX, nY, "Row 2 Col 3", Color.white, Color.blue,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r2c3", nColWidth, nRowThickness);
return;
}