2004 Dec: TrendTriggerFactor.efs

ICE Data Services -

TrendTriggerFactor.efs  
EFSLibrary - Discussion Board  

File Name: TrendTriggerFactor.efs

Description:

This indicator is from the December 2004 article, Trend Trigger Factor, by M.H. Pee.

Formula Parameters:

  • TTF Length: 15
  • TTF Thickness: 2

Notes:
The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.

Download File:
TrendTriggerFactor.efs


EFS Code:

/*****************************************************************
Provided By : eSignal. (c) Copyright 2004
Study:        Trend Trigger Factor (TTF) by M.H. Pee
Version:      1.0

10/6/2004

Notes:

Formula Parameters:                 Default:
TTF Length                          15
TTF Thickness                       2
*****************************************************************/

function preMain() {
    setStudyTitle("Trend Trigger Factor ");

    setCursorLabelName("TTF", 0);
    setDefaultBarThickness(2, 0);
    
    setShowTitleParameters(false);
    addBand(100, PS_SOLID, 2, Color.red, "upper");
    addBand(0, PS_SOLID, 2, Color.grey, "zero");
    addBand(-100, PS_SOLID, 2, Color.blue, "lower");
    
    var fp1 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
    fp1.setName("TTF Length");
    fp1.setLowerLimit(1);
    fp1.setDefault(15);
    
    var fp2 = new FunctionParameter("nThick", FunctionParameter.NUMBER);
    fp2.setName("TTF Thickness");
    fp2.setLowerLimit(1);
    fp2.setDefault(2);
}

var bEdit = true;
var nHighBP = null;
var nHighSP = null;
var nLowBP = null;
var nLowSP = null;
var aHigh = null;
var aLow = null;
var nTTF = null;

function main(nLength, nThick) {
    if (bEdit == true) {
        setDefaultBarThickness(nThick, 0);
        if (aHigh == null) aHigh = new Array(nLength*2);
        if (aLow == null) aLow = new Array(nLength*2);
        bEdit = false;
    }

    var nH = high(0);
    var nL = low(0);
    
    if (getBarState() == BARSTATE_NEWBAR) {
        nHighBP = null;
        nHighSP = null;
        nLowBP = null;
        nLowSP = null;
        aHigh.pop();
        aHigh.unshift(nH);
        aLow.pop();
        aLow.unshift(nL);
        for (i = 0; i < (nLength*2); i++) {
            if (i == 0) {
                nHighBP = aHigh[i];
                nLowSP = aLow[i];
            }
            if (i == nLength) {
                nHighSP = aHigh[i];
                nLowBP = aLow[i];
            }
            // Buy Power High, Sell Power Low
            if (i < nLength) {
                nHighBP = Math.max(nHighBP, aHigh[i]);
                nLowSP = Math.min(nLowSP, aLow[i]);
            }
            // Buy Power Low, Sell Power High
            if (i >= nLength) {
                nHighSP = Math.max(nHighSP, aHigh[i]);
                nLowBP = Math.min(nLowBP, aLow[i]);
            }
        }
    }

    aHigh[0] = nH;
    aLow[0] = nL;

    nHighBP = Math.max(nHighBP, aHigh[0]);
    nLowSP = Math.min(nLowSP, aLow[0]);
    
    if (close((-nLength*2)) == null) return;
    
    var nBuyPower = (nHighBP - nLowBP);
    var nSellPower = (nHighSP - nLowSP);
    nTTF = ((nBuyPower - nSellPower) / (0.5 * (nBuyPower + nSellPower))) *100;
    
    // Colors
    if (nTTF <= -100) {
        setBarFgColor(Color.red, 0);
    } else if (nTTF < 0 && nTTF > -100) {
        setBarFgColor(Color.maroon, 0);
    } else if (nTTF >= 0 && nTTF < 100) {
        setBarFgColor(Color.navy, 0);
    } else if (nTTF >= 100) {
        setBarFgColor(Color.blue, 0);
    }
    
    return nTTF;
}