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

[EquisMetaStock Group] Momentum Divergence Indicator



PureBytes Links

Trading Reference Links

Anyone has Price Headley's Momentum Divergence Indicator in 
metastock?

Here is esignal format. Don't know how to translate to metastock.



********************************************************************
Title:		MomentumDivergence Script for eSignal 7.x
By:         Chris D. Kryza (Divergence Software, Inc.)
Email:      c.kryza@xxxxxxx
Incept:     03/17/2003
Version:    1.0.0


=====================================================================
Fix History:
03/17/2003 -   Initial Release
1.0.0

=====================================================================
Project Description:   

Price Headley's Momentum Divergence Indicator. This study normalizes
MACD and price and can help to identify periods of strong momentum.
See 
http://bigtrends.iqchart.com/partner/bigtrends/education/technical_di
vergance.asp
for a more in-depth description.

Recommended Period values are 15 or 40.

=====================================================================

Various parameters can be adjusted via the eSignal Edit Studies 
option:


frFast:			Fast component of the MACD calculation. 
Default value
				is 12.
				
frSlow:			Slow component of the MACD calculation. 
Default value
				is 26.
				
frPeriod:		Lookback period for the combined 
calculation. Default
				value is 40.		
						


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 stFast				= null;
var stSlow				= null;
var nMA1				= 0;
var nMA2				= 0;
var nBarcount			= 0;
var oHiLo				= null;
var oClose				= null;
var bInitialized		= false;

var aFast				= new Array();
var aSlow				= new Array();





//== PreMain function required by eSignal to set things up
function preMain() {
var x;

    setPriceStudy(false);
    setStudyTitle("MOMDiv Plot");
    setCursorLabelName("MACD%", 0);
    setCursorLabelName("Close%", 1);
    setDefaultBarFgColor( Color.red,   0 );
    setDefaultBarFgColor( Color.blue,  1 );
    
    //plot the buy/sell bands
    addBand( 90.0, PS_SOLID, 2, Color.black );
    addBand( 30.0, PS_SOLID, 2, Color.black );
    
    //setComputeOnClose();
    
    //Initialize the arrays
    for (x=0; x<205; x++) {
    	aFast[x] = 0.0;
    	aSlow[x] = 0.0;
    }
    grID = 0;

}

//== Main processing function
function main( frFast, frSlow, frPeriod ) {
var x;
var nRet1, nRet2;
var nPlot1, nPlot2;
	
	if (frPeriod==null) {
		frPeriod = 40;
	}
	//if not-a-number, return an error
	if (isNaN( frPeriod ) ) {
		displayError("Error: Invalid frPeriod setting. Must 
be a positive integer value.");
		return;
	}
	//period should be between 2 and 200
	frPeriod = Math.max( Math.min( frPeriod, 200 ), 2 );
	
	if (frFast==null) {
		frFast = 12;
	}
	//if not-a-number, return an error
	if (isNaN( frFast ) ) {
		displayError("Error: Invalid frFast setting. Must 
be a positive integer value.");
		return;
	}
	if (frSlow==null) {
		frSlow = 26;
	}
	//if not-a-number, return an error
	if (isNaN( frSlow ) ) {
		displayError("Error: Invalid frSlow setting. Must 
be a positive integer value.");
		return;
	}
	
    if (getBarState() == BARSTATE_ALLBARS) {
        return null;
    }
    
    //Set up our studies on the first pass through
    if (bInitialized==false) {
    	bInitialized = true;
    	
		stFast	= new MAStudy(frFast, 0, "Close", 
MAStudy.EXPONENTIAL);
		stSlow	= new MAStudy(frSlow, 0, "Close", 
MAStudy.EXPONENTIAL); 
		
		//initialize our objects
		oHiLo = new Object();
		oHiLo.Val1 = 0.0;
		oHiLo.Val2 = 0.0;   
		oClose = new Object();
		oClose.Val1 = 0.0;
		oClose.Val2 = 0.0;	
    }
    
    nBarcount++;
    
    if (nBarcount < Math.max(frFast, frSlow)+frPeriod+5) return;
    	

	//cycle the arrays on new bar
	if (getBarState() == BARSTATE_NEWBAR) {
		aFast.unshift( 0 );
		aSlow.unshift( 0 );
		aFast.pop();
		aSlow.pop();
	}
	
	//get our MA values
	nMA1 = stFast.getValue( MAStudy.MA );
	nMA2 = stSlow.getValue( MAStudy.MA );

	aFast[0] = nMA1;
	aSlow[0] = nMA2;
	
	getHiLoMACD( frPeriod, oHiLo );
	
	getHiLoClose( frPeriod, oClose );
	
	nRet1 = oHiLo.Val1 - oHiLo.Val2;
	if (nRet1==0) nRet1 = 50;
	
	nRet2 = oClose.Val1 - oClose.Val2;
	if (nRet2==0) nRet2 = 50;

	//macd divergence plot	
	nPlot1 = 100 * ((nMA1-nMA2) - oHiLo.Val2) / nRet1;
	
	//close divergence plot
	nPlot2 = 100 * (close() - oClose.Val2) / nRet2;
	
	if ((!isNaN( nPlot1 )) && (!isNaN( nPlot2 ))) {
		return new Array( nPlot1, nPlot2 );
	}
	


}

function getHiLoMACD( nPeriod, oReturn ) {
var x;
var HH = -999999999.0;
var LL =  999999999.0;


	for(x=0; x<nPeriod; x++) {
		HH = Math.max( aFast[x]-aSlow[x], HH );
		LL = Math.min( aFast[x]-aSlow[x], LL );
	}
	
	oReturn.Val1 = HH;
	oReturn.Val2 = LL;
	return;
}
	
	
function getHiLoClose( nPeriod, oReturn ) {
var x;
var HH = -999999999.0;
var LL =  999999999.0;


	for(x=0; x<nPeriod; x++) {
		HH = Math.max( close(-x), HH );
		LL = Math.min( close(-x), LL );
	}
	
	oReturn.Val1 = HH;
	oReturn.Val2 = LL;
	return;
}
		
		




/*************************************************
             SUPPORT FUNCTIONS                    
**************************************************/    
    
//== 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 ) {
	clearText();  
    drawTextRelative(20, 50, ErrStr, Color.maroon, Color.lightgrey,  
Text.FRAME | Text.ONTOP | Text.RELATIVETOLEFT | 
Text.RELATIVETOBOTTOM, null, 16, gID());    
    
}



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Free shipping on all inkjet cartridge & refill kit orders to US & Canada. Low prices up to 80% off. We have your brand: HP, Epson, Lexmark & more.
http://www.c1tracking.com/l.asp?cid=5510
http://us.click.yahoo.com/GHXcIA/n.WGAA/ySSFAA/BefplB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx

 

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