MACD

ICE Data Services -

macd(), macdSignal(), macdHist() Built-in Study Functions

MACD is short for Moving Average Convergence Divergence. The MACD looks at the difference between a short-term moving average and a long-term moving average. A third moving average is taken of the difference and used as a signal line.

Syntax
macd(  nFastLength , nSlowLength , nSmoothing [, Series | sym() | inv() ][, nBarIndex ] )
macdSignal( nFastLength , nSlowLength , nSmoothing [, Series | sym() | inv() ][, nBarIndex ] )
macdHist(  nFastLength , nSlowLength , nSmoothing [, Series | sym() | inv() ][, nBarIndex ] )

Parameters
Parameter: Description: Default:
nFastLength Required. Number of periods to use for the fast MACD calculation.

 

n/a nSlowLength Required. Number of periods to use for the slow MACD calculation.

 

n/a nSmoothing Required. Number of periods to use for the MACD smoothing calculation.

 

n/a Series or
sym() or
inv()
[Optional]   Series Object or function of sym() or inv() to determine symbol/interval source for the study.

 

Chart's sym/inv nBarIndex [Optional]  Bar index of series to retrieve.

 

n/a


Return Value(s)

Returns a Series Object when nBarIndex is not specified.

Returns a single value when nBarIndex is specified.


Notes
Only available in versions 7.9 or later.

The MACD study that can be applied to the Advanced Chart from the Basic Studies menu will not match the calculated values of the built-in EFS studies due to the Simple Moving Average (Signal Line) option that is used by default in the Basic Studies MACD.  The EFS built-in study functions do not have a simple moving average option.  Their calculations are based on exponential moving averages by default.  To force the Basic Studies MACD to match the results of the EFS MACD functions, be sure to uncheck the Simple Moving Average options in the Edit Studies menu for the Basic Studies MACD to set their calculations to exponential averages.


Code Examples
Single Line Indicator:
function main() {    return new Array(macd(12, 26, 9),                      	          macdSignal(12, 26, 9),                      	          macdHist(12, 26, 9) );}

Single Line Study-on-Study Indicator:
function main() {    return new Array(macd(12, 26, 9, hl2()),                      macdSignal(12, 26, 9, hl2()),                      macdHist(12, 26, 9, hl2()) );}

Retrieve single values:
function main() {    var nValue_0 = macdSignal(12, 26, 9, 0);  // Current Bar Index    var nValue_1 = macdSignal(12, 26, 9, -1); // Prior Bar Index             return new Array(nValue_0, nValue_1);}

Initialize Series Objects:
//global Series Object variablesvar xStudy1 = null;var xStudy2 = null;var xStudy3 = null;function main() {    if (xStudy1 == null) xStudy1 = macd(12, 26, 9);    if (xStudy2 == null) xStudy2 = macdSignal(12, 26, 9);    if (xStudy3 == null) xStudy3 = macdHist(12, 26, 9);            // retrieve single values for conditional statements    var nValue1_0 = xStudy1.getValue(0);  // Current Bar Index value    var nValue2_0 = xStudy2.getValue(0);  // Current Bar Index value    var nValue3_0 = xStudy3.getValue(0);  // Current Bar Index value    var nValue1_1 = xStudy1.getValue(-1); // Prior Bar Index value        // Plot Current Bar Index Value        return new Array(nValue1_0, nValue2_0, nValue3_0);  }

Initialize a Series Object based on an external interval:
// global Series Object variablesvar xStudy1 = null;var xStudy2 = null;var xStudy3 = null;var bInit = false;  // Initialization flagfunction main() {    if (bInit == false) {        xStudy1 = macd(12, 26, 9, inv(20));   // 20-min interval        xStudy2 = macdSignal(12, 26, 9, inv(20));  // 20-min interval        xStudy3 = macdHist(12, 26, 9, inv(20));   // 20-min interval        bInit = true;    }            // retrieve single values for conditional statements    var nValue1_0 = xStudy1.getValue(0);  // Current Bar Index value    var nValue1_1 = xStudy1.getValue(-1); // Prior Bar Index value            // Synchronized Series plot    return new Array(getSeries(xStudy1),                     getSeries(xStudy2),                     getSeries(xStudy3) );  }


Initialize a Series Object based on an external symbol and interval:
// global Series Object variablesvar xStudy1 = null;var xStudy2 = null;var xStudy3 = null;var bInit = false;  // Initialization flagfunction main() {    if (bInit == false) {        xStudy1 = macd(12, 26, 9, sym("IBM,20"));   // IBM 20-min interval        xStudy2 = macdSignal(12, 26, 9, sym("IBM,20"));  // IBM 20-min interval        xStudy3 = macdHist(12, 26, 9, sym("IBM,20"));   // IBM 20-min interval        bInit = true;    }            // retrieve single values for conditional statements    var nValue1_0 = xStudy1.getValue(0);  // Current Bar Index value    var nValue1_1 = xStudy1.getValue(-1); // Prior Bar Index value            // Synchronized Series plot    return new Array(getSeries(xStudy1),                     getSeries(xStudy2),                     getSeries(xStudy3) );  }


See Also
Series Object
getSeries()
Built-in Study Functions
eSignal Forum Search Engine
Help Guides
Tutorials