CCI_Strategy

ICE Data Services -

CCI_Strategy.efs  
EFSLibrary - Discussion Board  

File Name: CCI_Strategy.efs

Description:
CCI Strategy

Formula Parameters:

  • Slow moving average length: 10
  • Fast moving average length: 20

Notes:

The Commodity Channel Index (CCI) is best used with markets that display cyclical or seasonal characteristics, and is formulated to detect the beginning and ending of these cycles by incorporating a moving average together with a divisor that reflects both possible and actual trading ranges. The final index measures the deviation from normal, which indicates major changes in market trend.

To put it simply, the Commodity Channel Index (CCI) value shows how the instrument is trading relative to its mean (average) price. When the CCI value is high, it means that the prices are high compared to the average price; when the CCI value is down, it means that the prices are low compared to the average price. The CCI value usually does not fall outside the -300 to 300 range and, in fact, is usually in the -100 to 100 range.

Download File:
CCI_Strategy.efs


EFS Code:

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

Provided By:  

    eSignal (Copyright c eSignal), a division of Interactive Data 
    Corporation. 2008. 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:        

    This study calculates CCI strategy

Version:            1.0  09/30/2008

Notes:

    The Commodity Channel Index (CCI) is best used with markets that display cyclical or 
    seasonal characteristics, and is formulated to detect the beginning and ending of these 
    cycles by incorporating a moving average together with a divisor that reflects both possible 
    and actual trading ranges. The final index measures the deviation from normal, which indicates 
    major changes in market trend.
    
    To put it simply, the Commodity Channel Index (CCI) value shows how the instrument is trading 
    relative to its mean (average) price. When the CCI value is high, it means that the prices are 
    high compared to the average price; when the CCI value is down, it means that the prices are low 
    compared to the average price. The CCI value usually does not fall outside the -300 to 300 range 
    and, in fact, is usually in the -100 to 100 range.

Formula Parameters:                     Default:

    Slow moving average length          10
    Fast moving average length          20

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

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

function preMain() {
    setPriceStudy(false);
    setStudyTitle("CCI Strategy"); 
    setCursorLabelName("CCI MA Slow",0);
    setDefaultBarFgColor(Color.red,0);
    setCursorLabelName("CCI MA FAST",1);
    setDefaultBarFgColor(Color.blue,1);
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.grey);

    askForInput();
    var x = 0;
    fpArray[x] = new FunctionParameter("FastMA", FunctionParameter.NUMBER);
	with(fpArray[x++]) {
        setLowerLimit(1);		
        setDefault(10);
    }
    
    fpArray[x] = new FunctionParameter("SlowMA", FunctionParameter.NUMBER);
	with(fpArray[x++]) {
        setLowerLimit(1);		
        setDefault(20);
    }
}

var xSMA = null;
var xFMA = null;

function main(FastMA,SlowMA) {

    var nBarState = getBarState();
    
    if(nBarState == BARSTATE_ALLBARS) {
        if (FastMA == null) FastMA = 10;
        if (SlowMA == null) SlowMA = 20;
    }
    
    if (bInit == false) {
        var xCCI = cci(10);
        if (xCCI == null) return;
        xSMA = sma(SlowMA, xCCI);
        xFMA = sma(FastMA, xCCI);
        bInit = true;
    }

    if(getCurrentBarIndex()==0) return;
    
    var nSMA = xSMA.getValue(0);
    var nFMA = xFMA.getValue(0);
    
	if(nSMA < nFMA && !Strategy.isLong()) 
		Strategy.doLong("Long", Strategy.CLOSE, Strategy.THISBAR);

	if(nSMA > nFMA && !Strategy.isShort()) 
		Strategy.doShort("Short", Strategy.CLOSE, Strategy.THISBAR);

	if(Strategy.isLong())
       		setPriceBarColor(Color.lime);

	if(Strategy.isShort())
        	setPriceBarColor(Color.red);

	return new Array(nSMA, nFMA);
}