Announcement

Collapse
No announcement yet.

2005 July: Targeting Your Pattern (msTwoBarPatterns.efs)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2005 July: Targeting Your Pattern (msTwoBarPatterns.efs)

    File Name: msTwoBarPatterns.efs

    Description:
    This study is based on the July 2005 article, Targeting Your Pattern, by Massimiliano Scorpio.

    Formula Parameters:
    Pattern Code 1: 3311
    Pattern Code 1 Color: red
    Pattern Code 2: none
    Pattern Code 2 Color: blue
    Pattern Code 3: none
    Pattern Code 3 Color: green
    Pattern Code 4: none
    Pattern Code 4 Color: aqua
    Pattern Code 5: none
    Pattern Code 5 Color: magenta
    Max number of labels per code: 100
    Font Size: 10

    Notes:
    The study has options to enter up to five different pattern codes for identification on the chart. Each code also has a color option that may be modified through the Edit Studies options. The study will draw a text label with the pattern color and corresponding number from the Edit Studies options. In the lower left corner of the chart a legend with the assigned color and corresponding patterns codes will appear. You can click on the legend to open a short cut to the Edit Studies options. There is also an option to limit the total number of images drawn per each pattern code to enhance performance. Simply increase that number to view a longer history of identified patterns. Lastly, you can also adjust the size of the text labels drawn above the price bars. To view the ShowMe statistics for a particular price bar you must first open the Formula Output Window (Tools-->EFS menu). Then double-click on the text label and you will see the statistics in the Formula Output Window. The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.

    Download File:
    msTwoBarPatterns.efs






    EFS Code:
    PHP Code:
    /***************************************
    Provided By : eSignal (c) Copyright 2005
    Description:  Two-Bar Patterns

    Version 1.0  5/10/2005

    Notes:
    July 2005 Issue - "Targeting Your Pattern" 
        by Massimiliano Scorpio
        
    This study uses EFS2 functionality available in eSignal
    version 7.9 or later.

    Formula Parameters:                 Defaults:
    Pattern Code 1                      3311
    Pattern Code 1 Color                red
    Pattern Code 2                      none
    Pattern Code 2 Color                blue
    Pattern Code 3                      none
    Pattern Code 3 Color                green
    Pattern Code 4                      none
    Pattern Code 4 Color                aqua
    Pattern Code 5                      none
    Pattern Code 5 Color                magenta
    Max number of labels per code.      100
    Font Size                           10

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

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("MS Two-Bar Patterns ");
        
    setShowTitleParameters(false);
        
    setCursorLabelName("msPattern Code"0);
        
    setDefaultBarFgColor(Color.brown0);
        
    setComputeOnClose();
        
        var 
    fp1 = new FunctionParameter("nPatt1"FunctionParameter.NUMBER);
            
    fp1.setName("Pattern Code 1");
            
    fp1.setLowerLimit(0);
            
    fp1.setDefault(3311);
        var 
    fp2 = new FunctionParameter("cPatt1"FunctionParameter.COLOR);
            
    fp2.setName("Pattern Code 1 Color");
            
    fp2.setDefault(Color.red);
        var 
    fp3 = new FunctionParameter("nPatt2"FunctionParameter.NUMBER);
            
    fp3.setName("Pattern Code 2");
            
    fp3.setLowerLimit(0);
        var 
    fp4 = new FunctionParameter("cPatt2"FunctionParameter.COLOR);
            
    fp4.setName("Pattern Code 2 Color");
            
    fp4.setDefault(Color.blue);
        var 
    fp5 = new FunctionParameter("nPatt3"FunctionParameter.NUMBER);
            
    fp5.setName("Pattern Code 3");
            
    fp5.setLowerLimit(0);
        var 
    fp6 = new FunctionParameter("cPatt3"FunctionParameter.COLOR);
            
    fp6.setName("Pattern Code 3 Color");
            
    fp6.setDefault(Color.green);
        var 
    fp7 = new FunctionParameter("nPatt4"FunctionParameter.NUMBER);
            
    fp7.setName("Pattern Code 4");
            
    fp7.setLowerLimit(0);
        var 
    fp8 = new FunctionParameter("cPatt4"FunctionParameter.COLOR);
            
    fp8.setName("Pattern Code 4 Color");
            
    fp8.setDefault(Color.aqua);
        var 
    fp9 = new FunctionParameter("nPatt5"FunctionParameter.NUMBER);
            
    fp9.setName("Pattern Code 5");
            
    fp9.setLowerLimit(0);
        var 
    fp10 = new FunctionParameter("cPatt5"FunctionParameter.COLOR);
            
    fp10.setName("Pattern Code 5 Color");
            
    fp10.setDefault(Color.magenta);

        var 
    fpz1 = new FunctionParameter("nImageLimit"FunctionParameter.NUMBER);
            
    fpz1.setName("Max number of labels per code.");
            
    fpz1.setDefault(100);
        var 
    fpz2 = new FunctionParameter("nFontSize"FunctionParameter.NUMBER);
            
    fpz2.setName("Font Size");
            
    fpz2.setDefault(10);
    }

    var 
    bVersion null;
    var 
    nCntr 0// image counter
    var aCodes = new Array();  // stores code for bars' with identified patterns
    var bInit true;
    var 
    nP1 null;
    var 
    nP2 null;
    var 
    nP3 null;
    var 
    nP4 null;
    var 
    nP5 null;

    function 
    main(nPatt1cPatt1nPatt2cPatt2nPatt3cPatt3
            
    nPatt4cPatt4nPatt5cPatt5nImageLimitnFontSize) {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;    
        
        var 
    nState getBarState();
        var 
    sCode getPattern();
        
    aCodes[getValue("rawtime")] = sCode;
        
        if (
    bInit == true) {
            if (
    nPatt1 0nP1 nPatt1;
            if (
    nPatt2 0nP2 nPatt2;
            if (
    nPatt3 0nP3 nPatt3;
            if (
    nPatt4 0nP4 nPatt4;
            if (
    nPatt5 0nP5 nPatt5;
            
    bInit false;
        }
        
        if (
    nState == BARSTATE_NEWBAR) {
            if (
    nCntr nImageLimitnCntr 0;
            else 
    nCntr++;
            for (var 
    1<= 5i++) {
                var 
    patt = eval("nPatt" i);
                if (!
    isNaN(patt) && patt != null) {
                    
    drawTextRelative(175 - (i*11), " Code " ": " patt " @URL=EFS:edit"Color.white
                        eval(
    "cPatt"+i), Text.BOLD|Text.LEFT|Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM
                        
    null10"legend" i);
                }
            }
        }

        
    // Identify selected pattern codes
        
    switch (eval(sCode)) {
            case (
    nPatt1):
                
    markPattern(1cPatt1nFontSize);
                break;
            case (
    nPatt2):
                
    markPattern(2cPatt2nFontSize);
                break;
            case (
    nPatt3): 
                
    markPattern(3cPatt3nFontSize);
                break;
            case (
    nPatt4): 
                
    markPattern(4cPatt4nFontSize);
                break;
            case (
    nPatt5): 
                
    markPattern(5cPatt5nFontSize);
                break;
        }
        
        return 
    sCode;
    }



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

    function getPattern() {
        var 
    "" getZ(open(0)) + getZ(high(0)) + getZ(low(0)) + getZ(close(0));
        
        return 
    s;
    }

    function 
    getZ(nPrice) {
        var 
    zNum 0;
        var 
    nATR atr(10);
        var 
    h1 high(-1);
        var 
    l1 low(-1);
        var 
    nMidpoint1 = (h1 l1) / 2;
        
        if (
    nPrice l1 && nPrice >= (l1 nATR) ) zNum 1;        // zone 1
        
    else if (nPrice >= l1 && nPrice nMidpoint1zNum 2;     // zone 2
        
    else if (nPrice >= nMidpoint1 && nPrice h1zNum 3;     // zone 3
        
    else if (nPrice >= h1 && nPrice < (h1 nATR) ) zNum 4;   // zone 4
        
    else if (nPrice >= (h1 nATR) ) zNum 5;                  // zone 5
        
        
    return zNum;
    }

    function 
    markPattern(numpattColorfontSize) {
        
    drawTextRelative(0AboveBar1num+"@URL=EFS:onLButtonDblClk"
            
    Color.whitepattColorText.BOLD|Text.PRESET|Text.CENTER
            
    null, eval(fontSize), "Patt" num nCntr);    return;
    }

    function 
    edit() {
        
    askForInput("MS Two-Bar Patterns ");
        return;
    }

    function 
    onLButtonDblClk(barIndexyValue) {
        if (
    barIndex == 1) return;
        var 
    barRef getValue("rawtime"barIndex);
        var 
    patt aCodes[barRef];
        var 
    pattCount null;
        var 
    pctTotal null;
        var 
    nEqual 0;
        var 
    nBelow 0;
        var 
    nAbove 0;
        var 
    pctEqual 0;
        var 
    pctBelow 0;
        var 
    pctAbove 0;
        
        var 
    nCount 0;
        var 
    nOldest getOldestBarIndex();
        var 
    nTot Math.absnOldest Math.abs(barIndex));
        var 
    barRef null;
        var 
    nCode null;
        
        for (var 
    nOldestbarIndexi++) {
            
    barRef getValue("rawtime"i);
            
    nCode aCodes[barRef];
            if (
    nCode == patt) {
                
    nCount++;
                if (
    close(i+1) == open(i+1)) nEqual++;
                if (
    close(i+1) <  open(i+1)) nBelow++;
                if (
    close(i+1) >  open(i+1)) nAbove++;
            }
        }
        
        
    pattCount nCount;
        
    pctTotal = ((nCount/nTot)*100).toFixed(2);
        if (
    nEqual 0pctEqual = ((nEqual/nCount)*100).toFixed(2);
        if (
    nBelow 0pctBelow = ((nBelow/nCount)*100).toFixed(2);
        if (
    nAbove 0pctAbove = ((nAbove/nCount)*100).toFixed(2);

        var 
    false;
        if (
    nP1 != null && patt == nP1true;
        if (
    nP2 != null && patt == nP2true;
        if (
    nP3 != null && patt == nP3true;
        if (
    nP4 != null && patt == nP4true;
        if (
    nP5 != null && patt == nP5true;
        if (
    == false) return;
        
        var 
    nATR atr(10barIndex);
        var 
    h1 high(barIndex-1);
        var 
    l1 low(barIndex-1);
        var 
    nMidpoint1 = (h1 l1) / 2;
        
        
    debugClear();
        
    Alert.playSound("Pairing.wav");
        
    debugPrintln("Close has been equal the open " nEqual " times " 
            
    pctEqual "% on Total Pattern");
        
    debugPrintln("Close has been below the open " nBelow " times " 
            
    pctBelow "% on Total Pattern");
        
    debugPrintln("Close has been above the open " nAbove " times " 
            
    pctAbove "% on Total Pattern");
        
    debugPrintln("In the next bar:");
        
    debugPrintln("Total Number of Patterns " patt ": (w/out present bar) " 
            
    pattCount " - " pctTotal "% on Total Bars.");
        
    debugPrintln("");
        
    debugPrintln("Close: is " getElementDesc(4patt));
        
    debugPrintln("Low: is " getElementDesc(3patt));
        
    debugPrintln("High: is " getElementDesc(2patt));
        
    debugPrintln("Open: is " getElementDesc(1patt));
        
    debugPrintln("");
        
    debugPrintln("Close: " formatPriceNumber(close(barIndex)));
        
    debugPrintln("Low:   " formatPriceNumber(low(barIndex)));
        
    debugPrintln("High:  " formatPriceNumber(high(barIndex)));
        
    debugPrintln("Open:  " formatPriceNumber(open(barIndex)));
        
    debugPrintln("");
        
    debugPrintln("Previous Low - 10 ATR:  " formatPriceNumber(l1 nATR) );
        
    debugPrintln("Previous Low:           " formatPriceNumber(l1) );
        
    debugPrintln("Previous Midpoint:      " formatPriceNumber(nMidpoint1) );
        
    debugPrintln("Previous High:          " formatPriceNumber(h1) );
        
    debugPrintln("Previous High + 10 ATR: " formatPriceNumber(h1 nATR) );
        
    debugPrintln("");
        
    debugPrintln("Description:");
        
    debugPrintln("");
        
    debugPrintln("A Pattern coded as " patt " has been identified at bar " barIndex "!");
        return;
    }

    function 
    getElementDesc(nPospattcode) {
        var 
    pattDesc0 "below previous (Low - ATR 10).";
        var 
    pattDesc1 "above (at) (previous Low - ATR 10) and below previous Low.";
        var 
    pattDesc2 "above (at) previous Low and below previous Midpoint.";
        var 
    pattDesc3 "above (at) previous Midpoint and below previous High.";
        var 
    pattDesc4 "above (at) previous High and below (High +ATR 10).";
        var 
    pattDesc5 "above (at) previous High + ATR 10.";
        
        if (
    pattcode == null) return "N/A.";
        if (
    pattcode.length 3) return "N/A.";
        var 
    DescNum pattcode.charAt(nPos-1);
        
        switch (
    DescNum) {
            case 
    "0" :
                
    DescNum "0";
                break;
            case 
    "1" :
                
    DescNum "1";
                break;
            case 
    "2" :
                
    DescNum "2";
                break;
            case 
    "3" :
                
    DescNum "3";
                break;
            case 
    "4" :
                
    DescNum "4";
                break;
            case 
    "5" :
                
    DescNum "5";
                break;
        }
        
        return eval(
    "pattDesc"+DescNum);
    }


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