2014 Sep: Finding The Golden Triangle by Charlotte Hudgin

ICE Data Services -

 

TheGoldenTriangleStrategy.efs  

EFSLibrary - Discussion Board  

 

File Name: TheGoldenTriangleStrategy.efs

 

Description:
Finding The Golden Triangle by Charlotte Hudgin

 

Formula Parameters:

TheGoldenTriangleStrategy.efs

  • Length SMA: 50
  • Consider Days of White Space: 20
  • Consider Days to Compare Volume: 0
  • Entry Position Color: lime
  • Exit Position Color: red

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

 

Download File:
TheGoldenTriangleStrategy.efs


TheGoldenTriangleStrategy.efs



EFS Code:

TheGoldenTriangleStrategy.efs

/*********************************
Provided By:  
    Interactive Data Corporation (Copyright В© 2014) 
    All rights reserved. This sample eSignal Formula Script (EFS)
    is for educational purposes only. Interactive Data Corporation
    reserves the right to modify and overwrite this EFS file with 
    each new release. 

Description:        
    Finding The Golden Triangle by Charlotte Hudgin

Formula Parameters:                     Default:
Length SMA                              50
Consider Days of White Space            20
Consider Days to Compare Volume         0
Entry Position Color                    lime
Exit Position Color                     red

Version:            1.00  07/07/2014

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

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

var fpArray = new Array();

function preMain(){
    
    setStudyTitle("TheGoldenTriangleStrategy");
    setPriceStudy(true);
    
    setCursorLabelName("Moving Average", 0);    

    var x = 0;

    fpArray[x] = new FunctionParameter("fpLenSMA", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("Length SMA");
        setLowerLimit(1);
        setDefault(50);
    }

    fpArray[x] = new FunctionParameter("fpDaysWS", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("Consider Days of White Space");
        setLowerLimit(1);
        setDefault(20);
    }

    fpArray[x] = new FunctionParameter("fpDaysVolume", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("Consider Days to Compare Volume");    
        setLowerLimit(0);
        setDefault(0);
    }

    fpArray[x] = new FunctionParameter("fpEntryColor", FunctionParameter.COLOR);
    with(fpArray[x++]){
        setName("Entry Position Color");    
        setDefault(Color.lime);
    }

    fpArray[x] = new FunctionParameter("fpExitColor", FunctionParameter.COLOR);
    with(fpArray[x++]){
        setName("Exit Position Color");    
        setDefault(Color.red);
    }
}

var bInit = false;
var bVersion = null;

var xOpen = null;
var xHigh = null;
var xLow = null;
var xClose  = null;
var xVolume = null;

var xPriceSMA = null;
var xVolumeSMA = null;
var xHignesVol = null;

var nCurrDaysWS = 0;
var nLotSize = 0;

var bPriceConfirm = false;
var bVolumeConfirm = false;

var nPivotPrice = null;

function main(fpLenSMA, fpDaysWS, fpDaysVolume, fpEntryColor, fpExitColor){
    
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;

    if (!bInit){
        
        xOpen = open();
        xHigh = high();
        xLow = low();
        xClose = close();
        xVolume = volume();
        
        if (fpDaysVolume != 0)
            xHignesVol = highest(fpDaysVolume, xVolume);
                
        xPriceSMA = sma(fpLenSMA);
        xVolumeSMA = sma(fpLenSMA, xVolume);
        
        nLotSize = Strategy.getDefaultLotSize();
        
        bInit = true;
    }

    if (getBarState() == BARSTATE_ALLBARS){
        bPriceConfirm = false;
        bVolumeConfirm = false;
        
        nCurrDaysWS = 0;
    };
                            
    var nOpen = xOpen.getValue(0);
    var nHigh = xHigh.getValue(0);
    var nLow  = xLow.getValue(0);
    var nClose = xClose.getValue(0);
    var nPriorClose = xClose.getValue(-1);
    var nVolume = xVolume.getValue(0);

    var nPriceSMA = xPriceSMA.getValue(0);
    var nVolumeSMA = xVolumeSMA.getValue(0);

    var nHignesVol = 0;

    if (fpDaysVolume != 0)    
        nHignesVol = xHignesVol.getValue(-1);
       
    if (nPriorClose == null || nPriceSMA == null || nVolumeSMA == null || nHignesVol == null)
        return;
    
    if (getCurrentBarIndex() != 0){
        
        if (Strategy.isInTrade() && nHigh >= nPivotPrice){
        
            var nExitPrice = Math.max(nOpen, nPivotPrice);
                
            Strategy.doSell("Exit", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nExitPrice);                                                                               
            drawShapeRelative(0, AboveBar1, Shape.DOWNTRIANGLE, null, fpExitColor, Text.PRESET, getCurrentBarIndex() + "Exit");
            drawTextRelative(0, AboveBar2, "Exit", fpExitColor, null, Text.PRESET|Text.CENTER, null, null, getCurrentBarIndex() + "Exit");
            drawTextRelative(0, AboveBar3, nLotSize + " @ " + formatPriceNumber(nExitPrice), fpExitColor, null, Text.PRESET|Text.CENTER, null, null, getCurrentBarIndex() + "ExitSettings"); 
            
            bPriceConfirm = false;
            bVolumeConfirm = false; 
        };
    
        if (!bPriceConfirm && nCurrDaysWS >= fpDaysWS && nLow <= nPriceSMA && nClose >= nPriceSMA){
        
            bPriceConfirm = true;
               
            for (var j = 0; j > -getCurrentBarCount()-1; j--){
          
                nPivotPrice = xHigh.getValue(j-1);
            
                if (xHigh.getValue(j) > xHigh.getValue(j-1)){
                    nPivotPrice = xHigh.getValue(j);
                    break;
                }
            } 
        
            if (nVolume > nVolumeSMA && nVolume > nHignesVol)
                bVolumeConfirm = true;
        };


        if (bPriceConfirm && !bVolumeConfirm){
            if (nVolume > nVolumeSMA && nVolume > nHignesVol && nClose > nPriceSMA && nClose > nPriorClose) 
                 bVolumeConfirm = true;
        };
    
        if (bPriceConfirm && bVolumeConfirm && !Strategy.isInTrade()){
            
            var nEntryPrice = xOpen.getValue(1);
        
            if (nEntryPrice > nPivotPrice){
                bPriceConfirm = false;
                bVolumeConfirm = false;
            } else{
                Strategy.doLong("Entry", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);                                                                               
                drawShapeRelative(1, BelowBar1, Shape.UPTRIANGLE, null, fpEntryColor, Text.PRESET, getCurrentBarIndex() + "Entry");
                drawTextRelative(1, BelowBar2, "Entry", fpEntryColor, null, Text.PRESET|Text.CENTER, null, null, getCurrentBarIndex() + "Entry");
                drawTextRelative(1, BelowBar3, nLotSize + " @ " + formatPriceNumber(nEntryPrice), fpEntryColor, null, Text.PRESET|Text.CENTER, null, null, getCurrentBarIndex() + "EntrySettings"); 
            };
        };
    };

    if (nLow > nPriceSMA)
        nCurrDaysWS ++
    else
        nCurrDaysWS = 0;
    
    
    return nPriceSMA;
}

function verify(){
    
    var b = false;
    if (getBuildNumber() < 779){
        
        drawTextAbsolute(5, 35, "This study requires version 8.0 or later.", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "error");
        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "upgrade");
        return b;
    } 
    else
        b = true;
    
    return b;
}