I am new to esignal and not have done any coding. How do I produce a line on a chart that is some price above/below an EMA or other study?
Announcement
Collapse
No announcement yet.
Line Above an EMA
Collapse
X
-
Re: Line Above an EMA
Welcome to eSignal.
It's a steep learning curve.
I thought I would lend a hand since I had the code to do just what you want to do and it only took about 10 minutes. You shouldn't have to waste hours figuring this kind of stuff out.
The TRO_TRADE_ZONES_MA allows YOU to enter the moving average type, length, offset, and band colors.
You can also move the button around, but leave it alone until after you figure a few things out...lol
In the screenshot, I am using an ema(5) with an offset of .25.
The study plots a line .25 above and another .25 below the value of the ema(5). It also shades the area to make it easier to see.
I hope this helps.
MAY ALL YOUR FILLS BE COMPLETE.
Here's the code:
PHP Code:
/*************************************
Alexis C. Montenegro © April 2004
Use and or modify this code freely. If you redistribute it
please include this and or any other comment blocks and a
description of any changes you make.
..........................................................
TRO_TRADE_ZONES_MA 20060730 PLOTS TRADE ZONE LINES based on moving avg
Modifying Programmer: Avery T. Horton, Jr. aka *************
****************************************/
debugClear();
var xAvgr1c1 = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("TRO_TRADE_ZONES");
setCursorLabelName("Long Top ", 0);
setCursorLabelName("Long Bot ", 1);
setCursorLabelName("Open ", 2);
setCursorLabelName("Short Top", 3);
setCursorLabelName("Short Bot", 4);
setCursorLabelName("PrevClose", 5);
setDefaultBarFgColor(Color.blue,0);
setDefaultBarFgColor(Color.blue,1);
setDefaultBarFgColor(Color.lime,2);
setDefaultBarFgColor(Color.red,3);
setDefaultBarFgColor(Color.red,4);
setDefaultBarFgColor(Color.magenta,5);
setDefaultBarThickness(2,0);
setDefaultBarThickness(2,1);
setDefaultBarThickness(2,2);
setDefaultBarThickness(2,3);
setDefaultBarThickness(2,4);
setDefaultBarThickness(2,5);
setPlotType(PLOTTYPE_FLATLINES,0);
setPlotType(PLOTTYPE_FLATLINES,1);
setPlotType(PLOTTYPE_FLATLINES,2);
setPlotType(PLOTTYPE_FLATLINES,3);
setPlotType(PLOTTYPE_FLATLINES,4);
setPlotType(PLOTTYPE_FLATLINES,5);
// checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/PrevDay-OHLC.efs");
}
var vOpen = null;
var vOpen1 = null;
var vHigh = null;
var vHigh1 = null;
var vLow = null;
var vLow1 = null;
var vClose1 = null;
var vMid = null;
var vMid1 = null;
askForInput();
var iDecimals = new FunctionParameter("iDecimals", FunctionParameter.NUMBER);
iDecimals.setDefault( 2 );
var iAvgType1 = new FunctionParameter("iAvgType1", FunctionParameter.STRING);
iAvgType1.addOption("Simple");
iAvgType1.addOption("Exponential");
iAvgType1.addOption("Weighted");
iAvgType1.setDefault( "Exponential" );
iAvgType1.setName("Fast AVG Type");
var iLength1 = new FunctionParameter("iLength1", FunctionParameter.NUMBER);
iLength1.setDefault( 05 );
iLength1.setName("AVG Length");
var iOffset1 = new FunctionParameter("iOffset1", FunctionParameter.NUMBER);
iOffset1.setDefault( .10 );
var iColorLong = new FunctionParameter("iColorLong", FunctionParameter.COLOR);
iColorLong.setDefault( Color.RGB(215,255,195));
var iColorShort = new FunctionParameter("iColorShort", FunctionParameter.COLOR);
iColorShort.setDefault( Color.RGB(254,233,233));
var iButtonX = new FunctionParameter("iButtonX", FunctionParameter.NUMBER);
iButtonX.setDefault( 50 );
var iButtonY = new FunctionParameter("iButtonY", FunctionParameter.NUMBER);
iButtonY.setDefault( 15 );
function main( iDecimals, iAvgType1 , iLength1, iOffset1 ,
iColorLong , iColorShort, iButtonX , iButtonY ) {
// if (close(-1)==null)
// return;
// initialize upon first loading formula
if(getBarState() == BARSTATE_ALLBARS) {
drawTextPixel( iButtonX, iButtonY , " TRO_TradeZone_MA @URL=EFS:editParameters", Color.white,
Color.green,
Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.ONTOP|Text.BOLD|Text.BUTTON,
"Comic Sans MS", 13, "UpExp");
vDate = new Date();
vInterval = getInterval();
vSymbol = 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;
}
if(getBarState()==BARSTATE_NEWBAR&&getDay()!=getDay(-1)) {
vHigh1 = vHigh;
vLow1 = vLow;
vOpen1 = vOpen;
vClose1 = formatPriceNumber( close(-1) ) * 1 ;//comment out this line if using alternate
vClose1
vMid1 = formatPriceNumber( vMid ) * 1 ;
vHigh = high();
vLow = low();
vOpen=open();
}
if( iAvgType1 == "Simple" ) { xAvgr1c1 = sma( iLength1 , inv(vInterval) ) } ;
if( iAvgType1 == "Exponential" ) { xAvgr1c1 = ema( iLength1 , inv(vInterval) ) } ;
if( iAvgType1 == "Weighted" ) { xAvgr1c1 = ema( iLength1 , inv(vInterval) ) } ;
vLongTop = rnd(xAvgr1c1 + iOffset1, iDecimals) ;
vShortTop = rnd(xAvgr1c1 - iOffset1, iDecimals) ;
if (vOpen1 == null || vLow1 == null || vHigh1 == null || vClose1 == null) {
return;
} else {
setBarBgColor(iColorLong ,0, xAvgr1c1, vLongTop );
setBarBgColor(iColorShort, 1, vShortTop, xAvgr1c1 );
return new Array( vLongTop, rnd( xAvgr1c1, iDecimals), vShortTop ) ;
}
}
function editParameters() {
askForInput("TRO_TRADE_ZONES_MA");
return;
}
// rnd function
function rnd(value, iDecimals ) { // Round the price to iDecimals digits
value = value * Math.pow(10, iDecimals);
return Math.round(value, iDecimals) / Math.pow(10, iDecimals);
}
Originally posted by iholmes89
I am new to esignal and not have done any coding. How do I produce a line on a chart that is some price above/below an EMA or other study?Last edited by buzzhorton; 07-30-2006, 11:51 PM.
Comment