T3 MACO

ICE Data Services -

T3_MACO.efs  
EFSLibrary - Discussion Board  

File Name: T3_MACO.efs

Description:
T3 MACO

Formula Parameters:

  • Fast MA : 5
  • Slow MA : 8
  • Length MACO : 5
  • b : 0.7

Notes:

Download File:
T3_MACO.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:        
    T3 MACO
Version:            1.0  09/17/2009
 
Formula Parameters:                     Default:
    Fast MA                             5
    Slow MA                             8
    Length MACO                         5
    b                                   0.7
Notes:
    
**********************************/
var fpArray = new Array();
var bInit = false;

function preMain(){
    setPriceStudy(false);
    setShowCursorLabel(true);
    setShowTitleParameters(false);
    setStudyTitle("T3 MACO");
    setCursorLabelName("T3 MACO", 0);
    setPlotType(PLOTTYPE_LINE, 0);
    setDefaultBarFgColor(Color.red, 0);
    var x = 0;
    fpArray[x] = new FunctionParameter("FastMA", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("Fast MA");
        setLowerLimit(1);
        setDefault(5);
    }    
    fpArray[x] = new FunctionParameter("SlowMA", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("SlowMA");
        setLowerLimit(1);
        setDefault(8);
    }    
    fpArray[x] = new FunctionParameter("LengthMACO", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("Length MACO");
        setLowerLimit(1);
        setDefault(5);
    }        
    fpArray[x] = new FunctionParameter("nB", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("b");
        setLowerLimit(0.0001);
        setDefault(0.7);
    }            
}

var xT3MACO = null;

function main(SlowMA, FastMA, LengthMACO, nB) {
var nBarState = getBarState();
var nT3MACO = 0;
    if (nBarState == BARSTATE_ALLBARS) {
        if(SlowMA == null) SlowMA = 5;
        if(FastMA == null) FastMA = 8;
        if(LengthMACO == null) LengthMACO = 8;
        if(nB == null) nB = 0.7;        
	}
	if (bInit == false) {
        addBand(0, PS_SOLID, 1, Color.black, "Zero");
        xT3MACO = efsInternal("Calc_T3MACO", LengthMACO, SlowMA, FastMA, nB);
        bInit = true;
	}
	nT3MACO = xT3MACO.getValue(0);
	if (nT3MACO == null) return;
    return nT3MACO;
}

var bSecondInit = false;
var xEMA3 = null;
var xEMA4 = null;
var xEMA5 = null;
var xEMA6 = null;
var c1=0;
var c2=0;
var c3=0;
var c4=0;
var b2=0;
var b3=0;

function Calc_T3MACO(LengthMACO, SlowMA, FastMA, nB) {
var nRes = 0;
var e3=0;
var e4=0;
var e5=0;
var e6=0;
    if (!bSecondInit) {
        b2 = Math.pow(nB, 2); 
        b3 = b2 * nB;
        c1 = - b3;
        c2 = (3 * (b2 + b3));
        c3 = -3 * (2 * b2 +  nB + b3);
        c4 = (1 + 3 *  nB + b3 + 3 * b2);
        xEMA3 = ema(LengthMACO, ema(LengthMACO, ema(LengthMACO, efsInternal("Calc_MA", SlowMA, FastMA))));
        xEMA4 = ema(LengthMACO, xEMA3);
        xEMA5 = ema(LengthMACO, xEMA4);
        xEMA6 = ema(LengthMACO, xEMA5);
        bSecondInit = true;
    }
    e3 = xEMA3.getValue(0);
    e4 = xEMA4.getValue(0);
    e5 = xEMA5.getValue(0);
    e6 = xEMA6.getValue(0);
    if (e6 == null) return;
    nRes = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3;
    return nRes;
}

var bThridInit = false;
var xEMAF = null;
var xEMAS = null;

function Calc_MA(SlowMA, FastMA) {
var nRes = 0;
var nEMAF = 0;
var nEMAS = 0;
    if (!bThridInit) {
        xEMAF = ema(FastMA);
        xEMAS = ema(SlowMA);
        bThridInit = true;
    }
    nEMAF = xEMAF.getValue(0);
    nEMAS = xEMAS.getValue(0);
    if (nEMAF == null || nEMAS == null) return;
    nRes = nEMAF - nEMAS;
    return nRes;
}