Code: Select all
/*****************************************************************
TRO_SM_HHLL 20060728 HIGHER HIGH/LOWER LOW SLOT MACHINE INDICATOR
Programmer: Avery T. Horton, Jr. aka TheRumpledOne
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.
Verwendete Indikatoren:
*****************************************************************/
var nFontCY = 0;
var nFontCX = 0;
var nColWidth = 0;
var nRowThickness = 1;
var nFontSize = 10;
var sStr;
var tStr;
var diff1 =0;
var diff2 =0;
var midpoint1 =0;
var realtimepivot =0;
var xInit = false;
var xMiddle = null;
var xGap = null;
var xHiOp = null;
var xOpLo = null;
var xOpen = null;
var xHigh = null;
var xLow = null;
var xClose = null;
var kHH = null;
var kLH = null;
var kHL = null;
var kLL = null;
var zSymbol = null;
function preMain() {
setStudyTitle("TRO_SM_HHLL");
setShowCursorLabel(false);
setShowTitleParameters(false);
var iButtonX = new FunctionParameter("iButtonX", FunctionParameter.NUMBER);
iButtonX.setDefault( 1 );
var iButtonY = new FunctionParameter("iButtonY", FunctionParameter.NUMBER);
iButtonY.setDefault( 1 );
var iFontSize = new FunctionParameter("iFontSize", FunctionParameter.NUMBER);
iFontSize.setDefault( 10 );
var iDecimals = new FunctionParameter("iDecimals", FunctionParameter.NUMBER);
iDecimals.setDefault( 2 );
iDecimals.setName("Round to X decimals");
/***** Column Width is used here for the cx parameter *****/
var fp = new FunctionParameter("inputColWidth", FunctionParameter.NUMBER);
fp.setName("Column Width");
fp.setDefault(80);
/***** Row Thickness is used here for the cy parameter *****/
var fp = new FunctionParameter("inputRowThickness", FunctionParameter.NUMBER);
fp.setName("Row Thickness");
fp.setDefault(-1.2);
var fp = new FunctionParameter("inputFontSize", FunctionParameter.NUMBER);
fp.setName("Font Size");
fp.setLowerLimit(1);
fp.setDefault(11);
/*****
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(5);
/*****
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 fp4 = new FunctionParameter("roundlen", FunctionParameter.NUMBER);
fp4.setName("roundlen");
fp4.setLowerLimit(0);
fp4.setDefault(2);
}
var bEdit = true;
function main(
inputColWidth, inputRowThickness, inputFontSize,
inputXstart, inputYstart,
iDecimals,
iFontSize, iButtonX, iButtonY) {
// initialize upon first loading formula
if(getBarState() == BARSTATE_ALLBARS) {
drawTextPixel( iButtonX , iButtonY, " TRO_SM_HHLL @URL=EFS:editParameters", Color.white, Color.lime,
Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.ONTOP|Text.BOLD|Text.BUTTON,
"Comic Sans MS", 13, "UpExp");
vDate = new Date();
iInterval = getInterval();
vSymbol = getSymbol().toUpperCase();
xSymbol = getSymbol().toUpperCase();
// for RTH, eg, to convert, ES Z2 to ES Z2=2
var rootSymbol = vSymbol.substring(0,3);
if (rootSymbol == "ES " || rootSymbol == "NQ ")
if ( vSymbol.indexOf("=2") == -1 ) vSymbol += "=2";
vSymbol += ",D";
return null;
}
// 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;
//DISPLAY COLUMN HEADINGS
tStr= "Symbol" ;
drawTextPixel(nX, nY, tStr, Color.blue, Color.lightgrey,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r4c0", nColWidth, nRowThickness);
tStr= "Highs" ;
drawTextPixel(nX+=nFontCX, nY, tStr, Color.blue, Color.lightgrey,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r4c1", nColWidth, nRowThickness);
tStr= "Lows" ;
drawTextPixel(nX+=nFontCX, nY, tStr, Color.blue, Color.lightgrey,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r4c2", nColWidth, nRowThickness);
//Zeile2
nX = inputXstart;
nY -= nFontCY;
if(xInit==false){
// INITIALIZE ROW 1
xOpen = open( ) ;
xHigh = high( ) ;
xLow = low( ) ;
xClose = close( ) ;
xInit=true;
} // xInit
sStr = xSymbol ;
drawTextPixel(nX, nY, sStr, Color.white, Color.black,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r3c0", nColWidth, nRowThickness);
if (getBarState() == BARSTATE_NEWBAR) {
// PROCESS ROW 1 COLUMN 1
if( xSymbol != zSymbol) {
kHH = 0 ;
kLH = 0 ;
kHL = 0 ;
kLL = 0 ;
}
var zOpen = xOpen.getValue(0) ;
var zClose = xClose.getValue(0) ;
var zClose1 = xClose.getValue(-1) ;
var zHigh = xHigh.getValue(0) ;
var zHigh1 = xHigh.getValue(-1) ;
var zLow = xLow.getValue(0) ;
var zLow1 = xLow.getValue(-1) ;
var zMid1 = rnd( ((zHigh1 + zLow1) * .50) , 2 ) ;
var zGap = rnd( (zOpen - zClose1) , 2) ;
zSymbol = xSymbol ;
if( zHigh > zHigh1 ) {
kHH = kHH + 1;
kLH = -1;
xFGColor = Color.black;
xBGColor = Color.lime;
sStr = "HH " + kHH ;
; }
else
if( zHigh < zHigh1 ) {
kHH = -1;
kLH = kLH + 1;
xFGColor = Color.black;
xBGColor = Color.red;
sStr = "LH " + kLH;
}
else {
xFGColor = Color.black;
xBGColor = Color.yellow;
sStr = "=H"
}
drawTextPixel(nX+=nFontCX, nY, sStr, xFGColor, xBGColor,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r3c1", nColWidth, nRowThickness);
// PROCESS ROW 1 COLUMN 2
if( zLow > zLow1 ) {
kHL = kHL + 1;
kLL = -1;
xFGColor = Color.black;
xBGColor = Color.lime;
sStr = "HL " + kHL;
}
else
if( zLow < zLow1 ) {
kHL = -1;
kLL = kLL + 1;
xFGColor = Color.black;
xBGColor = Color.red;
sStr = "LL " + kLL;
}
else {
xFGColor = Color.black;
xBGColor = Color.yellow;
sStr = "=L"
}
drawTextPixel(nX+=nFontCX, nY, sStr, xFGColor, xBGColor,
Text.FRAME | Text.CENTER | Text.VCENTER | Text.BOLD,
null, nFontSize, "r3c2", nColWidth, nRowThickness);
/*
debugPrint( "kLL : " + kLL + "\n" )
debugPrint( "kHL : " + kHL + "\n" );
debugPrint( "kLH : " + kLH + "\n" )
debugPrint( "kHH : " + kHH + "\n" );
debugPrint( "getCurrentBarIndex() : " + getCurrentBarIndex() + "\n" );
debugPrint( "xSymbol : " + xSymbol + "\n" );
debugPrint( "--------------- " + "\n" );
*/
} // nstate
return; // MAIN
}
//==rnd will round to N digits.
function rnd(value, N) {
var n;
var mult=1;
for(n=0;n<N;n++) mult*=10;
value*=mult;
return Math.round( value,N)/mult;
}
function editParameters() {
askForInput("TRO_SM_HHLL");
return;
}
/*
if( kHH == null) kHH = 0 ;
if( kLH == null) kLH = 0 ;
if( kHL == null) kHL = 0 ;
if( kLL == null) kLL = 0 ;
*/