EMA Angle

ICE Data Services -


EMAAngle.efs  EFSLibrary - Discussion Board
  

File Name: EMAAngle.efs


Description:
EMA Angle


Formula Parameters:
Length : 34
AngleTreshold : 0.2
StartEMAShift : 6
EndEMAShift : 0
Price Scale : 10000

Notes:

Download File:
EMAAngle.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:            EMA AngleVersion:            1.0  09/30/2009 Formula Parameters:                     Default:    Length                              34    AngleTreshold                       0.2    StartEMAShift                       6    EndEMAShift                         0    Price Scale                         10000Notes:    **********************************/var fpArray = new Array();var bInit = false;function preMain(){    setPriceStudy(false);    setShowCursorLabel(true);    setShowTitleParameters(false);    setStudyTitle("EMA Angle");    setCursorLabelName("EMAAngle", 0);    setPlotType(PLOTTYPE_HISTOGRAM, 0);    setDefaultBarFgColor(Color.red, 0);    setDefaultBarThickness(2,0);    var x = 0;    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(1);        setDefault(34);    }        fpArray[x] = new FunctionParameter("AngleTreshold", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(0.00001);        setDefault(0.2);    }        fpArray[x] = new FunctionParameter("StartEMAShift", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(1);        setDefault(6);    }            fpArray[x] = new FunctionParameter("EndEMAShift", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(0);        setDefault(0);    }                fpArray[x] = new FunctionParameter("PriceScale", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(0);        setDefault(10000);    }                }var xMA = null;function main(Length, AngleTreshold, StartEMAShift, EndEMAShift, PriceScale) {var nBarState = getBarState();var nEndMA = 0;var nStartMA = 0;var nAngle = 0;var dFactor = 3.14159 / 180.0;var mFactor = PriceScale;var ShiftDif = StartEMAShift - EndEMAShift;    if (nBarState == BARSTATE_ALLBARS) {        if(Length == null) Length = 34;        if(AngleTreshold == null) AngleTreshold = 0.2;        if(StartEMAShift == null) StartEMAShift = 6;        if(EndEMAShift == null) EndEMAShift = 0;                if(PriceScale == null) PriceScale = 10000;        	}    mFactor = PriceScale;	    mFactor /= ShiftDif;	if (bInit == false) {        xMA = ema(Length, ohlc4());        bInit = true;	}	nEndMA = xMA.getValue(-EndEMAShift);	nStartMA = xMA.getValue(-StartEMAShift);	if (nEndMA == null || nStartMA == null) return;	nAngle = mFactor * (nEndMA - nStartMA);    if(nAngle > AngleTreshold) setBarFgColor(Color.green)        else if (nAngle < -AngleTreshold) setBarFgColor(Color.red)            else setBarFgColor(Color.black);    return nAngle;}