Announcement

Collapse
No announcement yet.

2004 Oct: Fibonacci And Gann Projections (SwingPrediction.efs)

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

  • 2004 Oct: Fibonacci And Gann Projections (SwingPrediction.efs)

    File Name: SwingPrediction.efs

    Description:
    This formula is based on Fibonacci And Gann Projections by Dennis Peterson, which appeared in the October 2004 issue of Stocks & Commodities.


    Formula Parameters:
    * Swing # of Bars - 1
    This is the minimum number of bars required to define a swing point. This number is for both sides of the swing point (i.e. 5 bars on the left and right of the swing bar).

    * Swing Wave Type - % Change in Price
    (% Retracement, % Change in Price)

    * Swing Wave Percentage - 5
    The number 5 will be treated as 5.0%. The number 0.05 will be treated as 0.0005%.

    * Swing High Price Source - Close
    * Swing Low Price Source - Close
    * Line Thickness - 2
    * Confirmed Swing Line Color - Blue
    * Developing Swing Line Color - Yellow
    * Number of Swings for Gann - 1
    The number of previous swings points to be included in the Gann projections

    * Gann Increment - 0.25
    The +/- increment for Gann calculation above and below the base calculation for Gann.

    * Number of Gann Increments - 2
    The number of Gann increments to be calculated above and below the Gann basis calculation. 2 will draw one above and one low
    the basis.

    * Fibonacci: DR 1 - 0.382
    * Fibonacci: DR 2 - 1.618
    * Fibonacci: A1 1 - 0.5
    * Fibonacci: A1 2 - 1.732
    * Fibonacci: A2 1 - 0.618
    * Fibonacci: A2 2 - 2.0
    * Fibonacci: C 1 - 0.707
    * Fibonacci: C 2 - 2.618
    * Fibonacci: DC 1 - 1.0
    * Fibonacci: DC 2 - 3.0

    Notes:
    The current version has one added modification since the formula went into publication. Per Dennis Peterson's request, a third label has been added to show a second percent retracement figure. The top %Rtmt label is the percent retracement of the developing swing (green Sept peak) to the second previous confirmed swing (blue June peak). The second %Rtmt label is the percent retracement of the right-most developing swing line (current bar) to the previous confirmed swing (Aug valley). The last %Chg label is the percent change in price of the righ-most developing swing line (current bar) from the developing swing (green Sept peak). The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.

    Download File:
    SwingPrediction.efs



    EFS Code:
    PHP Code:
    /*****************************************************************
    Provided By : eSignal. (c) Copyright 2004
    Study:        Swing Prediction
    Version:      1.0

    Formula Parameters:                 Default:
        * Swing: # of Bars              1
            This is the minimum number of bars required to define a 
            swing point.  This number is for both sides of the swing 
            point (i.e. 5 bars on the left and right of the swing bar).
        * Swing: Wave Type              % Change in Price
            (% Retracement, % Change in Price)
        * Swing: Wave Percentage        5
            The number 5 will be treated as 5.0%.  The number 0.05 will 
            be treated as 0.0005%.
        * Swing High Price Source       Close
        * Swing Low Price Source        Close
        * Line Thickness                2
        * Confirmed Swing Line Color    Blue
        * Developing Swing Line Color   Yellow
        * Number of Swings for Gann     1
            The number of previous swings points to be included in the
            Gann projections
        * Gann Increment                0.25
            The +/- increment for Gann calculation above and below the base
            calculation for Gann.
        * Number of Gann Increments     2
            The number of Gann increments to be calculated above and below
            the Gann basis calculation.  2 will draw one above and one below
            the basis.
        * Fibonacci: DR 1               0.382
        * Fibonacci: DR 2               1.618
        * Fibonacci: A1 1               0.5
        * Fibonacci: A1 2               1.732
        * Fibonacci: A2 1               0.618
        * Fibonacci: A2 2               2.0
        * Fibonacci: C 1                0.707
        * Fibonacci: C 2                2.618
        * Fibonacci: DC 1               1.0
        * Fibonacci: DC 2               3.0

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

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Swing Prediction ");
        
    setShowCursorLabel(false);
        
    setShowTitleParameters(false);
        
        var 
    fp1 = new FunctionParameter("nNum"FunctionParameter.NUMBER);
        
    fp1.setName("Swing: # of Bars");
        
    fp1.setLowerLimit(1);
        
    fp1.setDefault(1);
        
        var 
    fp2a = new FunctionParameter("sWaveType"FunctionParameter.STRING);
        
    fp2a.setName("Swing: Wave Type");
        
    fp2a.addOption("% Retracement");
        
    fp2a.addOption("% Change in Price");
        
    fp2a.setDefault("% Change in Price");
        
        var 
    fp2 = new FunctionParameter("nRet"FunctionParameter.NUMBER);
        
    fp2.setName("Swing: Wave Percentage");
        
    fp2.setLowerLimit(0);
        
    fp2.setDefault(5);

        var 
    fp3 = new FunctionParameter("sHighSource"FunctionParameter.STRING);
        
    fp3.setName("Swing High Price Source");
        
    fp3.addOption("Open");
        
    fp3.addOption("High");
        
    fp3.addOption("Low");
        
    fp3.addOption("Close");
        
    fp3.setDefault("Close");

        var 
    fp4 = new FunctionParameter("sLowSource"FunctionParameter.STRING);
        
    fp4.setName("Swing Low Price Source");
        
    fp4.addOption("Open");
        
    fp4.addOption("High");
        
    fp4.addOption("Low");
        
    fp4.addOption("Close");
        
    fp4.setDefault("Close");

        var 
    fp5 = new FunctionParameter("nThickness"FunctionParameter.NUMBER);
        
    fp5.setName("Line Thickness");
        
    fp5.setLowerLimit(1);
        
    fp5.setDefault(2);

        var 
    fp6 = new FunctionParameter("cColor1"FunctionParameter.COLOR);
        
    fp6.setName("Confirmed Swing Line Color");
        
    fp6.setDefault(Color.blue);

        var 
    fp7 = new FunctionParameter("cColor2"FunctionParameter.COLOR);
        
    fp7.setName("Developing Swing Line Color");
        
    fp7.setDefault(Color.yellow);
        
        var 
    fp19 = new FunctionParameter("nGann"FunctionParameter.NUMBER);
        
    fp19.setName("Number of Swings for Gann");
        
    fp19.setLowerLimit(1);
        
    fp19.setUpperLimit(6);
        
    fp19.setDefault(1);
        
        var 
    fp19b = new FunctionParameter("nGannInc"FunctionParameter.NUMBER);
        
    fp19b.setName("Gann Increment");
        
    fp19b.setLowerLimit(0);
        
    fp19b.setDefault(0.25);

        var 
    fp19c = new FunctionParameter("nGannNum"FunctionParameter.NUMBER);
        
    fp19c.setName("Number of Gann Increments");
        
    fp19c.setLowerLimit(0);
        
    fp19c.setDefault(2);

        var 
    fp20 = new FunctionParameter("fib0"FunctionParameter.NUMBER);
        
    fp20.setName("Fibonacci: DR 1");
        
    fp20.setLowerLimit(0);
        
    fp20.setDefault(0.382);

        var 
    fp21 = new FunctionParameter("fib1"FunctionParameter.NUMBER);
        
    fp21.setName("Fibonacci: DR 2");
        
    fp21.setLowerLimit(0);
        
    fp21.setDefault(1.618);

        var 
    fp22 = new FunctionParameter("fib2"FunctionParameter.NUMBER);
        
    fp22.setName("Fibonacci: A1 1");
        
    fp22.setLowerLimit(0);
        
    fp22.setDefault(0.5);

        var 
    fp23 = new FunctionParameter("fib3"FunctionParameter.NUMBER);
        
    fp23.setName("Fibonacci: A1 2");
        
    fp23.setLowerLimit(0);
        
    fp23.setDefault(1.732);

        var 
    fp24 = new FunctionParameter("fib4"FunctionParameter.NUMBER);
        
    fp24.setName("Fibonacci: A2 1");
        
    fp24.setLowerLimit(0);
        
    fp24.setDefault(0.618);

        var 
    fp25 = new FunctionParameter("fib5"FunctionParameter.NUMBER);
        
    fp25.setName("Fibonacci: A2 2");
        
    fp25.setLowerLimit(0);
        
    fp25.setDefault(2);

        var 
    fp26 = new FunctionParameter("fib6"FunctionParameter.NUMBER);
        
    fp26.setName("Fibonacci: C 1");
        
    fp26.setLowerLimit(0);
        
    fp26.setDefault(0.707);

        var 
    fp27 = new FunctionParameter("fib7"FunctionParameter.NUMBER);
        
    fp27.setName("Fibonacci: C 2");
        
    fp27.setLowerLimit(0);
        
    fp27.setDefault(2.618);

        var 
    fp28 = new FunctionParameter("fib8"FunctionParameter.NUMBER);
        
    fp28.setName("Fibonacci: DC 1");
        
    fp28.setLowerLimit(0);
        
    fp28.setDefault(1.0);

        var 
    fp29 = new FunctionParameter("fib9"FunctionParameter.NUMBER);
        
    fp29.setName("Fibonacci: DC 2");
        
    fp29.setLowerLimit(0);
        
    fp29.setDefault(3.0);
    }

    var 
    bEdit true;       // tracks change of user inputs
    var cntr 0;           // image counter for swing lines
    var bInit false;      // initialization routine completion
    var nNumBars null;    // number of bars for defining swings
    var sWaveTypeG null;  // wave type for confirming swings
    var nRetpcnt null;    // percent retracement for defining swings
    var nThicknessG null// line thickness
    var cColorCon null;   // confirmed swing color
    var cColorDev null;   // developing swing color
    var nGannG 1;         // number of swings for Gann calculations
    var nGannIncG null;   // increment value for Gann calculations
    var nGannNumG null;   // number of increments for Gann calculations
    var sHSource null;    // price source for high swings
    var sLSource null;    // price source for low swings
    var x1a null;         // x-coordinate for point a of developing line 1
    var x1b null;         // x-coordinate for point b of developing line 1
    var x2a null;         // x-coordinate for point a of developing line 2
    var x2b null;         // x-coordinate for point b of developing line 2
    var y1a null;         // y-coordinate for point a of developing line 1
    var y1b null;         // y-coordinate for point b of developing line 1
    var y2a null;         // y-coordinate for point a of developing line 2
    var y2b null;         // y-coordinate for point b of developing line 2
    var aY2A = new Array(7);// array of current 7 swing prices 
    var vLastSwing null;  // tracking swing type of last confirmed swing
    var nScntr 0;         // bar counter for swing confirmation
    var aSwingsIndex = new Array(7); // tracks current swings for DR, C, DC, A1, A2 periods
    var aSwingsPrice = new Array(7); // tracks current swing prices for Gann projections
    var aFibs = new Array(10);       // Fibonacci numbers for Swing Predictions
    var bProjCon false;
    var 
    bProjDev false;

    var 
    tCntr 0;

    function 
    main(nNumsWaveTypenRetsHighSourcesLowSourcenThicknesscColor1cColor2,
                  
    nGannnGannIncnGannNumfib0fib1fib2fib3fib4fib5fib6fib7fib8fib9) {
        var 
    nState getBarState();
        var 
    nIndex getCurrentBarIndex();
        var 
    getValue(sHighSource);
        var 
    getValue(sLowSource);
        var 
    close();
        var 
    0;

        
    // record keeping
        
    if (nState == BARSTATE_NEWBAR) {
            if (
    cntr 100cntr 0;
            if (
    x1a != nullx1a -= 1;
            if (
    x1b != nullx1b -= 1;
            if (
    x2a != nullx2a -= 1;
            if (
    x2b != nullx2b -= 1;
            
    0;
            for (
    07; ++i) {
                if (
    aSwingsIndex[i] != nullaSwingsIndex[i] -= 1;
            }
        }

        
    //Initialization
        
    if (bEdit == true) {
            if (
    nNumBars == nullnNumBars nNum;
            if (
    sWaveTypeG == nullsWaveTypeG sWaveType;
            if (
    nRetpcnt == nullnRetpcnt nRet/100;
            if (
    nThicknessG == nullnThicknessG nThickness;
            if (
    cColorCon == nullcColorCon cColor1;
            if (
    cColorDev == nullcColorDev cColor2;
            if (
    nGann != nullnGannG nGann;
            if (
    nGannIncG == nullnGannIncG nGannInc;
            if (
    nGannNumG == nullnGannNumG Math.round(nGannNum);
            if (
    sHSource == nullsHSource sHighSource;
            if (
    sLSource == nullsLSource sLowSource;
            if (
    x1a == nullx1a 0;
            if (
    y1a == nully1a c;
            
    0;
            for (
    010; ++i) {
                
    aFibs[i] = eval("fib"+i);
            }
            
    bEdit false;
        }
        if (
    bInit == false) {
            
    bInit Init(h,l,c);
        }

        
    // Swings
        
    if (nState == BARSTATE_NEWBAR) {
            
    nScntr += 1;
            
    // confirmed Swings
            
    if (nScntr nNumBars) {
                
    confirmSwings();
                if (
    bInit == true) {
                    
    doLine("dev1");
                    
    doLine("dev2");
                }
            }
        }
        
    checkSwings(hl);

        if (
    bProjCon == true) {
            
    bProjCon false;
            
    doProjections("con");
        }
        if (
    bProjDev == true) {
            
    bProjDev false;
            
    doProjections("dev1");
        }

        if (
    nIndex >= -1) {
            var 
    nWaveRet = (Math.abs(aSwingsPrice[0]-aSwingsPrice[1]) / Math.abs(aSwingsPrice[1]-aSwingsPrice[2]))*100;
            var 
    sWaveRetText " \%Rtmt: " nWaveRet.toFixed(2) + " ";
            var 
    nWaveRet2 = (Math.abs(y2b-aSwingsPrice[0]) / Math.abs(aSwingsPrice[0]-aSwingsPrice[1]))*100;
            var 
    sWaveRetText2 " \%Rtmt: " nWaveRet2.toFixed(2) + " ";
            var 
    nWaveChg = (Math.abs(y2a-y2b) / y1b)*100;
            var 
    sWaveChgText " \%Chg: " +  nWaveChg.toFixed(2) + " ";
            
    drawTextRelative(245sWaveRetTextcColor1Color.lightgrey,
                
    Text.BOLD|Text.LEFT|Text.VCENTER|Text.FRAME|Text.RELATIVETOBOTTOM
                
    null12"Ret");   // Developing peak/valley %Ret of previous confirmed peak/valley
            
    drawTextRelative(225sWaveRetText2cColor2Color.lightgrey,
                
    Text.BOLD|Text.LEFT|Text.VCENTER|Text.FRAME|Text.RELATIVETOBOTTOM
                
    null12"Ret2");  // Current bar %Ret of current developing peak/valley
            
    drawTextRelative(25sWaveChgTextcColor2Color.lightgrey,
                
    Text.BOLD|Text.LEFT|Text.VCENTER|Text.FRAME|Text.RELATIVETOBOTTOM
                
    null12"Chg");  // %Change in price of current bar from current developing peak/valley
        
    }

        return;
    }



    /***********************/
    /******  Functions *****/
    /***********************/

    // The entire formula is too large to display in this forum post.
    // To see the code for the support functions, open the formula in
    // the EFS editor. 
    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