[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Kirshenbaum Bands



PureBytes Links

Trading Reference Links

This will probably mean nothing to you.  But this is what I got from
Esignal:
/********************************************************************
Title:		Kirshenbaum Plot for eSignal 7.x
By:         Chris D. Kryza (Divergence Software, Inc.)
Email:      c.kryza@xxxxxxx
Incept:     07/09/2003
Version:    1.0.0


=====================================================================
Fix History:
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@xxxxxxx).

Dislaimer: For educational purposes only! Obviously, no guarantees 
whatsoever and use at your own risk.

**********************************************************************/


//Global Variables
var grID                = 0;
var nStudy1				= null;
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;

}

//== Main processing function
function main( EMAPeriod, LPeriod, StdErr ) {
var x;
var nEMA;
var nVal1;
var nSum;
var nSE;
var nUpperBand;
var nLowerBand;
	

	if ( EMAPeriod == null ) {
		EMAPeriod = 20;
	}
	
	if ( LPeriod == null ) {
		LPeriod = 20;
	}
	
	if ( StdErr == null ) {
		StdErr = 1.75;
	}



	//study is initializing
    if (getBarState() == BARSTATE_ALLBARS) {
        return null;
    }

	if ( bInitialized == false ) {
		nStudy1 = null;
		nStudy1	= new MAStudy( EMAPeriod, "close", MAStudy.EXPONENTIAL );		
		bInitialized = true;
	}

	if ( nStudy1 == null ) return;

	nEMA 	= nStudy1.getValue( MAStudy.MA );
	nVal1 	= OrderPoints( LPeriod );
	
	nSum = x = 0;
	while ( x<LPeriod ) {
		nSum += ( close(-x) - nVal1 ) * ( close(-x) - nVal1 );
		x++;
	}
	nSum /= LPeriod;
	nSE = Math.sqrt( nSum );
	
	nUpperBand = nEMA + ( StdErr * nSE );
	nLowerBand = nEMA - ( StdErr * nSE );
	
	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<points) {
		xx=x+1;
		a+=xx;
		b+=close( -(xy) );
		c+=xx*xx;
		d+=xx * close( -(xy) );
		xy--;
		x++;
	}
			
	b1 = (a*b - points*d)/(a*a - points*c);
	b0 = (b - b1*a)/points;
	
	result = b0 + b1*points;
	
	return( result );
}

//== gID function assigns unique identifier to graphic/text routines
function gID() {
    grID ++;
    return( grID );
}


//== displayError function displays an error to the user
function displayError( ErrStr ) {
  
    drawTextRelative(20, 50, ErrStr, Color.maroon, Color.lightgrey, 
Text.FRAME | Text.ONTOP | Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM,
null, 16, gID());    
    
}


















--- In amibroker@xxxxxxxxxxxxxxx, "Anthony Faragasso" <ajf1111@xxxx>
wrote:
> 
> 
> Anyone have the AFL formula for the following bands:
> 
> Kirshenbaum Bands
> 
> 
> 
> Thanks
> 
> Anthony
> 
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/