Announcement
Collapse
No announcement yet.
Highlight Help
Collapse
X
-
Try,
PHP Code:/*****************************************************************
Provided By:
Interactive Data Corporation (Copyright © eSignal) 2010.
All rights reserved. This sample eSignal Formula Script (EFS)
is for educational purposes only. Interactive Data Corporation
reserves the right to modify and overwrite this EFS file with
each new release.
******************************************************************/
//20130321 added extension lines && shading
var fpArray = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("Bollinger Bands");
setCursorLabelName("UprBB", 0);
setCursorLabelName("BasBB", 1);
setCursorLabelName("LwrBB", 2);
setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
setDefaultBarFgColor(Color.RGB(0xFE,0x69,0x00), 1);
setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 2);
setPlotType(PLOTTYPE_LINE,0);
setPlotType(PLOTTYPE_LINE,1);
setPlotType(PLOTTYPE_LINE,2);
setDefaultBarThickness(1,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(1,2);
askForInput();
var x=0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(20);
}
fpArray[x] = new FunctionParameter("StdDev", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(0);
setDefault(2);
}
fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("open");
addOption("high");
addOption("low");
addOption("close");
addOption("hl2");
addOption("hlc3");
addOption("ohlc4");
setDefault("close");
}
fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Offset", FunctionParameter.NUMBER);
with(fpArray[x++]){
setDefault(10);
}
fpArray[x] = new FunctionParameter("PlotUp_Lo_BB", FunctionParameter.BOOLEAN);
with(fpArray[x++]){
setDefault(true);
}
fpArray[x] = new FunctionParameter("PlotMidBB", FunctionParameter.BOOLEAN);
with(fpArray[x++]){
setDefault(true);
}
fpArray[x] = new FunctionParameter("BgColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setDefault(Color.RGB(130,245,255));
}
fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
with(fpArray[x++]){
setName("Show Parameters");
setDefault(false);
}
}
var bInit = false;
var xUpBB = null;
var xMidBB = null;
var xLoBB = null;
function main(Length,StdDev,Source,Symbol,Interval,Offset,PlotUp_Lo_BB,PlotMidBB,BgColor,Params) {
var minTick=getMinTick();
var valUp,valLo,pUp,pLo,xOff;
if(bInit == false){
if(Symbol == null) Symbol = getSymbol();
if(Interval == null) Interval = getInterval();
var vSymbol = Symbol+","+Interval;
xUpBB = offsetSeries(upperBB(Length,StdDev,eval(Source)(sym(vSymbol))),Offset);
xMidBB = offsetSeries(middleBB(Length,StdDev,eval(Source)(sym(vSymbol))),Offset);
xLoBB = offsetSeries(lowerBB(Length,StdDev,eval(Source)(sym(vSymbol))),Offset);
setShowTitleParameters(eval(Params));
setShowSeries(PlotUp_Lo_BB,0);
setShowSeries(PlotUp_Lo_BB,2);
setShowSeries(PlotMidBB,1);
bInit = true;
}
valUp=RoundAll(xUpBB.getValue(0));
valLo=RoundAll(xLoBB.getValue(0));
if(valUp==null || valLo==null) return;
pUp=(valUp+"").length;
pLo=(valLo+"").length;
xOff = parseInt(Offset/2)-Math.max(parseInt(pUp/2),parseInt(pLo/2))-1;
if(getCurrentBarIndex()==0){
drawLineRelative( -3, valUp, Offset+3, valUp, PS_SOLID, 4, Color.black, "BBu"+105 );
drawLineRelative( -3, valLo, Offset+3, valLo, PS_SOLID, 4, Color.black, "BBl"+105 );
drawLineRelative( -2, valLo+minTick, -2, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+106 );
drawLineRelative( -1, valLo+minTick, -1, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+107 );
drawLineRelative( 0, valLo+minTick, 0, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+108 );
drawLineRelative( 1, valLo+minTick, 1, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+109 );
drawLineRelative( 2, valLo+minTick, 2, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+110 );
drawLineRelative( 3, valLo+minTick, 3, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+111 );
drawLineRelative( 4, valLo+minTick, 4, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+112 );
drawLineRelative( 5, valLo+minTick, 5, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+113 );
drawLineRelative( 6, valLo+minTick, 6, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+114 );
drawLineRelative( 7, valLo+minTick, 7, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+115 );
drawLineRelative( 8, valLo+minTick, 8, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+116 );
drawLineRelative( 9, valLo+minTick, 9, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+117 );
drawLineRelative( 10, valLo+minTick, 10, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+118 );
drawLineRelative( 11, valLo+minTick, 11, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+119 );
drawLineRelative( 12, valLo+minTick, 12, valUp-minTick, PS_SOLID, 9, BgColor, "BBl"+120 );
drawLineRelative( 13, valLo+minTick, 13, valUp-minTick, PS_SOLID, 5, BgColor, "BBl"+121 );
drawTextRelative(xOff, valUp, valUp+"", Color.yellow, Color.black, Text.ONTOP | Text.VCENTER, "Courier New", 10, "PUp"+10);
drawTextRelative(xOff, valLo, valLo+"", Color.yellow, Color.black, Text.ONTOP | Text.VCENTER, "Courier New", 10,"PLo"+10 );
}
return new Array (getSeries(xUpBB),getSeries(xMidBB),getSeries(xLoBB));
}
function fnPaddingZeros(nInterger,szPaddingPos){
var x,nDecLength;
if((getMinTick()+"").indexOf(".")==-1) nDecLength = 0;
else{
x = (getMinTick() + "").split(".");
nDecLength = x[1].length;
}
if((nInterger+"").indexOf(".")==-1){
nPaddingLength = nDecLength; //if you want 0 for each missing decimal place
}else{
nPaddingLength = nDecLength - ((nInterger+"").length - ((nInterger+"").indexOf(".")+1));
}
//get the length of "nInterger"
var xInt = Math.abs(nInterger);
if((xInt+"").indexOf(".") == -1){
if(nDecLength!=0) xInt = xInt+".";
} else xInt = xInt +"";
var iLen = xInt.length;
iLen = iLen + nPaddingLength;
//convert integer to string
var sign = "";
var str = xInt;
if(nInterger < 0){
sign = "-";
xInt = (nInterger *= -1).toString();
}
while(xInt.length < iLen){
if(szPaddingPos == "start") { xInt = '0' + xInt; }
else if(szPaddingPos == "end") { xInt = xInt + '0'; }
}
return sign + xInt;
}
function RoundAll(Val){
var tick = getMinTick();
function rnd(value, N) {//N = round to N # of digits
var n;
var mult=1;
for(n=0;n<N;n++) mult*=10;
value*=mult;
return Math.round( value,N)/mult;
}
//////////////////////////////////Frac() goes with RoundToIncrement()//////////////
//== Frac functions returns the fractional portion of a real number
function Frac( iVal ) {
var x = Math.floor( iVal );
return( iVal - x );
}
//== Round the price to the nearest increment value
function RoundToIncrement( iVal, iInc ) {
var iInt = Math.floor( iVal );
var iFrac = Frac( iVal );
var iBase = Math.round( iFrac / iInc );
return( iInt + (iBase * iInc) );
}
//////////////////////////////////Frac() goes with RoundToIncrement()//////////////
if(tick == .25){
var y = RoundToIncrement(Val,tick)+"";
var Temp = y.indexOf(".");
if(Temp == -1) Temp = 0;
else Temp =Temp -1;
return 1*(fnPaddingZeros(y,"end"));
}else{
return 1*(fnPaddingZeros(rnd(Val,((tick+"").length-2)),"end"));
}
}
Comment