2009 Mar: MACD Reversed Crossover Strategy, by Donald W. Pendergast Jr.

ICE Data Services -

MACD_RevCrossover.efs  

EFSLibrary - Discussion Board  

File Name: MACD_RevCrossover.efs

Description:
MACD Reversed Crossover Strategy, by Donald W. Pendergast Jr.

 

Formula Parameters:

  • Fast Length : 12
  • Slow Length : 26
  • Smoothing : 9

Notes:
The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com

 

Download File:
MACD_RevCrossover.efs



EFS Code:

/*********************************
Provided By:  
    eSignal (Copyright c eSignal), a division of Interactive Data 
    Corporation. 2009. All rights reserved. This sample eSignal 
    Formula Script (EFS) is for educational purposes only and may be 
    modified and saved under a new file name.  eSignal is not responsible
    for the functionality once modified.  eSignal reserves the right 
    to modify and overwrite this EFS file with each new release.

Description:        
    MACD Reversed Crossover Strategy, by Donald W. Pendergast Jr.

Version:            1.0  01/08/2009

Formula Parameters:                     Default:
    Fast Length                         12
    Slow Length                         26
    Smoothing                           9

Notes: 
    The related article is copyrighted material. If you are not
    a subscriber of Stocks & Commodities, please visit www.traders.com.

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

var fpArray = new Array();
var bInit = false;
var bVersion = null;

function preMain() {
    setPriceStudy(false);
    setShowTitleParameters( false );
    setStudyTitle("MACD Reversed Crossover Strategy");
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.black);
    setCursorLabelName("MACD", 0);
    setCursorLabelName("Signal", 1);
    setDefaultBarFgColor(Color.green, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
    

    var x=0;
    fpArray[x] = new FunctionParameter("FastLength", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Fast Length");
        setLowerLimit(1);		
        setDefault(12);
    }
    fpArray[x] = new FunctionParameter("SlowLength", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Slow Length");
        setLowerLimit(1);		
        setDefault(26);
    }
    fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Smoothing");
        setLowerLimit(0);		
        setDefault(9);
    }
}

var xMACD = null;
var xSignal = null;

function main(FastLength, SlowLength , Smoothing) {

    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;   

    if (getCurrentBarIndex() == 0) return;

    if ( bInit == false ) { 
        xMACD = macd(FastLength, SlowLength, Smoothing);
        xSignal = macdSignal(FastLength, SlowLength, Smoothing);
        bInit = true; 
    } 

    if (xSignal.getValue(-1) == null) return;
    
    if(xSignal.getValue(-2) >= xMACD.getValue(-2) && 
       xSignal.getValue(-1) < xMACD.getValue(-1) && !Strategy.isLong()) {
		Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
    }	

	if(xSignal.getValue(-1) > xMACD.getValue(-1) && Strategy.isLong()) {
		Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.THISBAR);
	}	

	if(Strategy.isLong())
		setPriceBarColor(Color.lime);
	else setPriceBarColor(Color.black);
	
	return new Array(xMACD.getValue(0), xSignal.getValue(0));
}

function verify() {
    var b = false;
    if (getBuildNumber() < 779) {
        drawTextAbsolute(5, 35, "This study requires version 8.0 or later.", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "error");
        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "upgrade");
        return b;
    } else {
        b = true;
    }
    return b;
}