/******************************************************************** Title: Kirshenbaum Plot for eSignal 7.x By: Chris D. Kryza (Divergence Software, Inc.) Email: c.kryza@gte.net Incept: 07/09/2003 Version: 1.1.0 ===================================================================== Fix History: 11/30/2003 - Fix to StdErr calculation. Added function parameter 1.1.0 menu code. 07/09/2003 - Initial Release 1.0.0 ===================================================================== Project Description: Kirshenbaum Bands. Parameters: EMAPeriod: The period of the Exponential Moving Average to calculate. Default is 20 bars. LPeriod: The period of the linear regression to calculate. The default is 20. StdErr: The number of standard errors to use in the band projection. The default is 1.75. If you come across any fixes or have any ideas on how to spruce it up, I would appreciate it if you would let me know (c.kryza@gte.net). Dislaimer: For educational purposes only! Obviously, no guarantees whatsoever and use at your own risk. **********************************************************************/ //Global Variables var grID = 0; var nBarCounter = 0; var nStudy1 = null; var aFPArray = new Array(); var bInitialized = false; //== PreMain function required by eSignal to set things up function preMain() { setPriceStudy(true); setStudyTitle("Kirshenbaum Bands"); setCursorLabelName("HiBand", 0 ); setCursorLabelName("MidBand", 1 ); setCursorLabelName("LoBand", 2); setDefaultBarFgColor( Color.blue, 0 ); setDefaultBarFgColor( Color.red, 1 ); setDefaultBarFgColor( Color.blue, 2 ); //unrem this if you don't want the study tu update on every tick //setComputeOnClose(); grID = 0; //initialize formula parameters x=0; aFPArray[x] = new FunctionParameter( "EMAPeriod", FunctionParameter.NUMBER); with( aFPArray[x] ) { setName( "EMA Length" ); setLowerLimit( 2 ); setUpperLimit( 125 ); setDefault( 20 ); } x++; aFPArray[x] = new FunctionParameter( "LPeriod", FunctionParameter.NUMBER); with( aFPArray[x] ) { setName( "Regression Length" ); setLowerLimit( 2 ); setUpperLimit( 125 ); setDefault( 20 ); } x++; aFPArray[x] = new FunctionParameter( "StdErr", FunctionParameter.NUMBER); with( aFPArray[x] ) { setName( "Standard Errors" ); setLowerLimit( 0 ); setUpperLimit( 20 ); setDefault( 1.75 ); } } //== Main processing function function main( EMAPeriod, LPeriod, StdErr ) { var x, y; var nEMA; var aRegress; var nTmp; var nSum; var nSE; var nUpperBand; var nLowerBand; //study is initializing if (getBarState() == BARSTATE_ALLBARS) { return null; } if ( bInitialized == false ) { nStudy1 = null; nStudy1 = new MAStudy( EMAPeriod, 0, "Close", MAStudy.EXPONENTIAL ); bInitialized = true; } //called on each new bar if ( getBarState() == BARSTATE_NEWBAR ) { nBarCounter++; } if ( nStudy1 == null || nBarCounter < Math.max( LPeriod, EMAPeriod ) ) return; nEMA = nStudy1.getValue( MAStudy.MA ); aRegress = OrderPoints( LPeriod ); nSum = x = 0; y = LPeriod-1; while ( xnUpperBand && close() < nUpperBand ) { drawTextRelative( 0, high(), "q", Color.red, null, Text.ONTOP | Text.BOTTOM | Text.CENTER, "Wingdings 3", 10, nBarCounter ); } if ( low() nLowerBand ) { drawTextRelative( 0, low(), "p", Color.green, null, Text.ONTOP | Text.TOP | Text.CENTER, "Wingdings 3", 10, nBarCounter ); } return new Array ( nUpperBand, nEMA, nLowerBand ); } /************************************************* SUPPORT FUNCTIONS **************************************************/ function OrderPoints( points ) { var a,b,c,d; var b0,b1; var x,xx,xy; a=b=c=d=0; xy = points-1; x=0; while(x