Announcement

Collapse
No announcement yet.

2006 Apr: The Average Peak Excursion by Chris Young

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

  • 2006 Apr: The Average Peak Excursion by Chris Young

    File Name: APE.efs

    Description:
    These studies are based on the April 2006 article, The Average Peak Excursion, by Chris Young.

    Formula Parameters:
    APE.efs
    n-Day Avg Peak Excursion: 20

    APE_alpha.efs
    n-Day Avg Peak Excursion: 20

    Notes:
    The APE.efs study plots the n-period APE, n-period Peaks and the 1-period APE series as a non-price study. The APE_alpha.efs study is also a non-price study that plots the APE alpha as described in the article. Please note that the APE_alpha.efs formula directly calls APE.efs to perform its calculations. Therefore, both formulas need to be saved to the same folder. The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.


    Download File:
    APE.efs
    APE_alpha.efs



    EFS Code:

    APE.efs
    PHP Code:
    /***************************************
    Provided By : eSignal (c) Copyright 2006
    Description:  The Average Peak Excursion - by Chris Young

    Version 1.0  02/06/2006

    Notes:
    * Apr 2006 Issue of Stocks and Commodities Magazine
    * Study requires version 7.9.1 or higher.


    Formula Parameters:                 Defaults:
    n-Day Avg Peak Excursion            20
    ***************************************/


    function preMain() {
        
    setStudyTitle("Average Peak Excursion");
        
    setCursorLabelName("1-Day APE"0);
        
    setCursorLabelName("Peak"1);
        
    setCursorLabelName("APE"2);
        
    setDefaultBarThickness(20);
        
    setDefaultBarThickness(31);
        
    setDefaultBarThickness(22);
        
    setPlotType(PLOTTYPE_LINE0);
        
    setPlotType(PLOTTYPE_HISTOGRAM1);
        
    setDefaultBarFgColor(Color.navy0);
        
    setDefaultBarFgColor(Color.red1);
        
    setDefaultBarFgColor(Color.green2);
        
        var 
    fp1 = new FunctionParameter("nDayAPE"FunctionParameter.NUMBER);
            
    fp1.setName("n-Day Avg Peak Excursion");
            
    fp1.setLowerLimit(1);
            
    fp1.setDefault(20);
    }

    var 
    bVersion null;
    var 
    bInit false;

    var 
    xAPE null;    // APE series
    var xAPEMA null;
    var 
    xA0 null;     // 1-Day Peak series

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

        if (
    bInit == false) {
            
    xAPE efsInternal("calcPeak"nDayAPE);
            
    xAPEMA sma(nDayAPE,xAPE);
            
    xA0 efsInternal("calcPeak"1);
            
    xA0MA sma(nDayAPE,xA0);
            
    setCursorLabelName(nDayAPE "-Day Peak"1);
            
    setCursorLabelName(nDayAPE "-Day APE"2);
            
    bInit true;
        }
        
        return new Array(
    xA0MA.getValue(0), xAPE.getValue(0), xAPEMA.getValue(0));
    }

    var 
    xHighest null;
    var 
    xLowest null;

    function 
    calcPeak(nDay) {
        if(
    xHighest==nullxHighest highest(nDayhigh());
        if(
    xLowest==nullxLowest lowest(nDaylow());
        var 
    nO open(-nDay+1);
        if (
    nO == null) return null;
        
        var 
    nH Math.abs((xHighest.getValue(0) - nO) / nO)*100;
        var 
    nL Math.abs((xLowest.getValue(0)  - nO) / nO)*100;
        
        return 
    Math.max(nHnL);
    }


    function 
    verify() {
        var 
    false;
        if (
    getBuildNumber() < 730) {
            
    drawTextAbsolute(535"This study requires version 7.9.1 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;


    APE_alpha.efs
    PHP Code:
    /***************************************
    Provided By : eSignal (c) Copyright 2006
    Description:  The Average Peak Excursion Alpha - by Chris Young

    Version 1.0  02/06/2006

    Notes:
    * Apr 2006 Issue of Stocks and Commodities Magazine
    * This study must reside in the same folder as APE.efs.
        Or add the path information to APE.efs within the efsExternal()
        functions if APE.efs is to be located in another folder.
    * Study requires version 7.9.1 or higher.


    Formula Parameters:                 Defaults:
    n-Day Avg Peak Excursion            20
    ***************************************/


    function preMain() {
        
    setStudyTitle("Average Peak Excursion Alpha");
        
    setCursorLabelName("APE Alpha"0);
        
    setDefaultBarThickness(20);
        
        var 
    fp1 = new FunctionParameter("nDayAPE"FunctionParameter.NUMBER);
            
    fp1.setName("n-Day Avg Peak Excursion");
            
    fp1.setLowerLimit(1);
            
    fp1.setDefault(20);
    }

    var 
    bVersion null;
    var 
    bInit false;
    var 
    xAPE_n null;


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

        var 
    nAlpha null;
        
        if (
    bInit == false) {
            if (
    xAPE_n == nullxAPE_n efsExternal("APE.efs"nDayAPE);
            
    bInit true;
        }

        var 
    nAPE1 getSeries(xAPE_n0);
        var 
    nAPEn getSeries(xAPE_n2);
        
        if (
    nAPEn == null || nAPE1 == null) return;

        
    nAlpha Math.log( (nAPEn/nAPE1) ) / Math.log(nDayAPE);
        
        return 
    nAlpha;
    }


    /***** Support Functions *****/

    function verify() {
        var 
    false;
        if (
    getBuildNumber() < 730) {
            
    drawTextAbsolute(535"This study requires version 7.9.1 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