B. Williams - Trading Zone

ICE Data Services -

ZoneTrade.efs  
EFSLibrary - Discussion Board  

File Name: ZoneTrade.efs

Description:
B. Williams - Trading Zone

Formula Parameters:

  • Fast SMA : 5
  • Slow SMA : 34

Notes:
The indicator is written by the fourth dimension of B. Williams - Trading Zone:

  • If the current bars of AC and AO are green, it shows that the zone is green.
  • If the current bars of @Q and @N red, it shows that the zone is red.
  • If the bars of AC and AO are differently directed then the bar is colored grey (grey zone).

Download File:
ZoneTrade.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:        
    B. Williams - Trading Zone
    
Version:            1.0  06/10/2009
 
Formula Parameters:                     Default:
    Fast SMA                            5  
    Slow SMA                            34
    
Notes:
    The indicator is written by the fourth dimension of B. Williams - Trading Zone:
    If the current bars of AC and AO are green, it shows that the zone is green.
    If the current bars of ÀÑ and ÀÎ red, it shows that the zone is red.
    If the bars of AC and AO are differently directed then the bar is colored grey (grey zone).
    
**********************************/
var fpArray = new Array();
var bInit = false;

function preMain(){
    setPriceStudy(true);
    setShowCursorLabel(true);
    setShowTitleParameters(false);
    setColorPriceBars(true);        
    setStudyTitle("ZoneTrade ");
    setDefaultBarFgColor(Color.black);
    var x = 0;
    fpArray[x] = new FunctionParameter("SMA_Len1", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("Fast SMA");
        setLowerLimit(1);
        setDefault(5);
    }    
    fpArray[x] = new FunctionParameter("SMA_Len2", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("Slow SMA");
        setLowerLimit(1);
        setDefault(34);
    }        
}

var xAC = null;
var xAO = null;

function main(SMA_Len1, SMA_Len2) {
var nBarState = getBarState();
var nAC = 0;
var nAC1 = 0;
var nAO = 0;
var nAO1 = 0;
var nDirAC = 0;
var nDirAO = 0;
    if (nBarState == BARSTATE_ALLBARS) {
        if(SMA_Len1 == null) SMA_Len1 = 5;
        if(SMA_Len2 == null) SMA_Len2 = 34;
	}
	if (bInit == false) {
        xAC = efsInternal("Calc_AC", SMA_Len1, SMA_Len2);
        xAO = efsInternal("Calc_AO", SMA_Len1, SMA_Len2);
        bInit = true;
	}
    setPriceBarColor(Color.grey);    	
    nAC = xAC.getValue(0);
    nAC1 = xAC.getValue(-1);
    nAO = xAO.getValue(0);
    nAO1 = xAO.getValue(-1);
    if (nAC1 == null || nAO1 == null) return;
    if (nAC > nAC1) nDirAC = 1;
    if (nAC < nAC1) nDirAC = 2; 
    if (nAO > nAO1) nDirAO = 1;
    if (nAO < nAO1) nDirAO = 2; 
    if (nDirAC == 1 && nDirAO == 1) {
        setPriceBarColor(Color.lime);    	        
    }
    if (nDirAC == 2 && nDirAO == 2) {
        setPriceBarColor(Color.red);    	
    }
	return;
}

var bSecondInit = false;
var xAO = null;
var xMA_AO = null;

function Calc_AC(SMA_Len1, SMA_Len2) {
var nRes = 0;
var nAO = 0;
var nMA_AO = 0;
    if (bSecondInit == false) {
        xAO = efsInternal("Calc_AO", SMA_Len1, SMA_Len2);
        xMA_AO = sma(SMA_Len1, xAO);
        bSecondInit = true;
    }
    nAO = xAO.getValue(0);
    nMA_AO = xMA_AO.getValue(0);
    if (nAO == null || nMA_AO == null) return;
    nRes = nAO - nMA_AO;
    return nRes;
}

var bThirdInit = false;
var xSMA1 = null;
var xSMA2 = null;

function Calc_AO(SMA_Len1, SMA_Len2) {
var nRes = 0;
var nSMA1 = 0;
var nSMA2 = 0;
    if (bThirdInit == false) {
        xSMA1 = sma(SMA_Len1);
        xSMA2 = sma(SMA_Len2);
        bThirdInit = true;
    }
    nSMA1 = xSMA1.getValue(0);
    nSMA2 = xSMA2.getValue(0);
    if (nSMA1 == null || nSMA2 == null) return;
    nRes = nSMA1 - nSMA2;
    return nRes;
}