Announcement

Collapse
No announcement yet.

2007 Jan: Exiting After Profitable Closes

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2007 Jan: Exiting After Profitable Closes

    File Name: HighestHighTrend.efs

    Description:
    This study is based on the January 2007 Trading System Lab article, Exiting After Profitable Closes, by Volker Knapp.

    Formula Parameters:
    Number of days for Trend Entry: 20
    Number of days for Counter Trend Entry: 10
    Number of days for Trend Exit: 20
    Number of days for Counter Trend Exit: 8
    Fixed Stop Percent: 0.10

    Notes:
    This system is a long only system compatible for Back Testing and real time analysis. The related article is copyrighted material. If you are not a subscriber of Active Trader Magazine, please visit www.activetradermag.com.

    Download File:
    HighestHighTrend.efs



    EFS Code:
    PHP Code:
    /***************************************
    Provided By : eSignal (c) Copyright 2006
    Description:  Exiting after profitable closes 
                  by Volker Knapp

    Version 1.0  11/13/2006

    Notes:
    * Jan 2007 Issue of Active Trader Magazine
    * Study requires version 8.0 or later.
    * Long only system, compatible for Back Testing
        and real time.
    * Parameters optimized for Daily interval.


    Formula Parameters:                     Default:
    Number of days for Trend Entry          20
    Number of days for Counter Trend Entry  10
    Number of days for Trend Exit           20
    Number of days for Counter Trend Exit   8
    Fixed Stop Percent                      0.10
    *****************************************************************/

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Highest High Trend System ");
        
    setShowTitleParameters(false);    
        
    setCursorLabelName("HH"0);
        
    setCursorLabelName("LL"1);
        
    setCursorLabelName("Stop"2);
        
    setDefaultBarThickness(20);
        
    setDefaultBarThickness(21);
        
    setDefaultBarThickness(22);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.blue1);
        
    setDefaultBarFgColor(Color.red2);
        
    setPlotType(PLOTTYPE_FLATLINES2);

        var 
    fp1 = new FunctionParameter("nTdays"FunctionParameter.NUMBER);
            
    fp1.setName("Number of days for Trend Entry");
            
    fp1.setLowerLimit(1);
            
    fp1.setDefault(20);
        var 
    fp2 = new FunctionParameter("nCTdays"FunctionParameter.NUMBER);
            
    fp2.setName("Number of days for Counter Trend Entry");
            
    fp2.setLowerLimit(1);
            
    fp2.setDefault(10);
        var 
    fp3 = new FunctionParameter("nTexit"FunctionParameter.NUMBER);
            
    fp3.setName("Number of days for Trend Exit");
            
    fp3.setLowerLimit(1);
            
    fp3.setDefault(20);    
        var 
    fp4 = new FunctionParameter("nCTexit"FunctionParameter.NUMBER);
            
    fp4.setName("Number of days for Counter Trend Exit");
            
    fp4.setLowerLimit(1);
            
    fp4.setDefault(8);    
        var 
    fp5 = new FunctionParameter("nStopPrct"FunctionParameter.NUMBER);
            
    fp5.setName("Fixed Stop Percent");
            
    fp5.setLowerLimit(0);
            
    fp5.setUpperLimit(1);
            
    fp5.setDefault(0.10);    
    }

    // Global Variables
    var bVersion  null;    // Version flag
    var bInit     false;   // Initialization flag

    var nCount 0;
    var 
    xHH_Trend null;
    var 
    xLL_CTrend null;
    var 
    vPosition 0;  // 0 = flat, 1 = Trend long, 2 = Counter Trend Long
    var nEntry null;  // entry price
    var nStop null;   // stop price
    var bExitTrade false;
    var 
    bBT true// back test flag

    function main(nTdaysnCTdaysnTexitnCTexitnStopPrct) {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;    

        var 
    nState getBarState();
        
        
    //Initialization
        
    if (bInit == false) {
            
    xHH_Trend upperDonchian(nTdayshigh());
            
    xLL_CTrend lowerDonchian(nCTdayslow());
            
    bInit true;
        }
        
        var 
    nH_0 high(0);
        var 
    nL_0 low(0);
        var 
    nC_1 close(-1);
        var 
    nOpen open(0);
        var 
    nHH xHH_Trend.getValue(0);
        var 
    nLL xLL_CTrend.getValue(0);
        var 
    nHH_1 xHH_Trend.getValue(-1);
        var 
    nLL_1 xLL_CTrend.getValue(-1);    
        if (
    nHH_1 == null || nLL_1 == null) return;

        
    // Record Keeping
        
    if (nState == BARSTATE_NEWBAR) {
            
    bExitTrade false;
            if (
    vPosition == 0) {
                
    nCount 0;
                
    nEntry null;
                
    nStop null;
            }
            if (
    getCurrentBarIndex() == 0bBT false;
        }
        
        
    // Exit Conditions
        
    if (vPosition != && nState == BARSTATE_NEWBAR) {
            var 
    sText "";
            
    /*var sText = "Unprofitable Close";
            if (nCount >= 1 && nC_1 < nEntry) {
                // not a profitable close
                // exit position
                vPosition = 0;
                bExitTrade = true;
            }*/
            
    nCount++;
            
    // Trend Exit
            
    if (vPosition == && nCount >= nTexit) {
                
    sText "Counter Trend Exit";
                
    bExitTrade true;
            }
            
    // Counter Trend Exit
            
    if (vPosition == && nCount >= nCTexit) {
                
    sText "Counter Trend Exit";
                
    bExitTrade true;
            }
            
            if (
    bExitTrade == true) {
                
    vPosition 0;
                
    drawShape(Shape.DIAMONDAboveBar1Color.red"xtop"+rawtime(0));
                
    drawShape(Shape.DIAMONDBelowBar1Color.red"xbot"+rawtime(0));
                
    Alert.playSound("train.wav");
                if (
    bBT) {
                    
    Strategy.doSell(sTextStrategy.MARKETStrategy.THISBAR);
                }
            }
        }
        
    // Fixed %Stop Exit
        
    if (bExitTrade == false && vPosition != 0) {
            if (
    nL_0 <= nStop) {
                
    vPosition 0;
                
    bExitTrade true;
                
    drawShape(Shape.DIAMONDAboveBar1Color.red"xtop"+rawtime(0));
                
    drawShape(Shape.DIAMONDBelowBar1Color.red"xbot"+rawtime(0));
                
    Alert.playSound("train.wav");
                if (
    bBT) {
                    
    Strategy.doSell("Stop Exit"Strategy.STOPStrategy.THISBAR
                        
    Strategy.DEFAULT, Math.min(nOpennStop));
                }
            }
        }   
        
        
        
        
    // Entry Conditions
        
    if (vPosition == && bExitTrade == false) {
            
    // Trend Entry
            
    if (nH_0 nHH_1) {
                
    vPosition 1;
                
    nEntry Math.max(nOpennHH_1);
                
    nStop nEntry * (nStopPrct);  // fixed stop
                
    drawShape(Shape.UPARROWAboveBar1Color.greenrawtime(0));
                
    Alert.playSound("ding.wav");
                if (
    bBT) {
                    
    Strategy.doLong("Trend Signal"Strategy.STOP
                        
    Strategy.THISBARStrategy.DEFAULT, nEntry);
                }
            } else if (
    nL_0 nLL_1) { // Counter Trend Entry
                
    vPosition 2;
                
    nEntry Math.min(nOpennLL_1);
                
    nStop nEntry * (nStopPrct);  // fixed stop
                
    drawShape(Shape.UPARROWAboveBar1Color.greenrawtime(0));
                
    Alert.playSound("ding.wav");
                if (
    bBT) {
                    
    Strategy.doLong("Counter Trend Signal"Strategy.LIMIT
                        
    Strategy.THISBARStrategy.DEFAULT, nEntry);
                }
            }
        }
        
        return new Array(
    nHHnLLnStop);
    }


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

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation
Working...
X