Announcement

Collapse
No announcement yet.

2011 Apr: Identifying Cup Formations Early

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

  • 2011 Apr: Identifying Cup Formations Early

    File Name: SemiCup.efs, isSemiCup.efs

    Description:
    Identifying Cup Formation Early and Identifying Cup Formation Early For Grid Window

    Formula Parameters:
    SemiCup.efs
    Parameter: 1
    isSemiCup.efs
    Parameter: 1

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

    Download File:
    SemiCup.efs
    isSemiCup.efs

    SemiCup.efs


    isSemiCup.efs


    EFS Code: (SemiCup.efs)
    PHP Code:
    /*********************************
    Provided By:  
        Interactive Data Corporation (Copyright © 2010) 
        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:        
        Identifying Cup Formation Early
     
    Version:            1.0  11/02/2011

    Formula Parameters:                     Default:
        Parameter                              1
        
    Notes:
        The related article is copyrighted material. If you are not
        a subscriber of Stocks & Commodities, please visit 
    [url]www.traders.com.[/url]
    **********************************/

    var fpArray = new Array();
    var 
    bVersion null;
    function 
    preMain()
    {
        
    setPriceStudy(true);
        
    setShowCursorLabel(false);
        
        
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("gParam"FunctionParameter.NUMBER);
        
    with(fpArray[x++])
        {
        
    setName("Parameter");
        
    setLowerLimit(1);
            
    setUpperLimit(100);
            
    setDefault(1);
        }
        
    fpArray[x] = new FunctionParameter("gColorSC"FunctionParameter.COLOR);
        
    with(fpArray[x++])
        {
        
    setName("Semicup Color");
            
    setDefault(Color.lime);
        }
        
    fpArray[x] = new FunctionParameter("gColorNC"FunctionParameter.COLOR);
        
    with(fpArray[x++])
        {
        
    setName("No Cup Color");
            
    setDefault(Color.red);
        }
        
    fpArray[x] = new FunctionParameter("gGrid"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++])
        {
        
    setName("Show Grid");
            
    setDefault(true);
        }

    }

    var 
    bInit false;
    var 
    xCls null;
    var 
    xFilC null;
    var 
    eps 0.0000000001;
    var 
    vCls 0;
    var 
    nCupPeriod 0;

    var 
    pTop 0;
    var 
    pBot 0;
    var 
    b0 0
    var 
    b1 0
    var 
    b2 0
    var 
    b3 0
    var 
    b4 0
    var 
    b5 0
    var 
    L2 0
    var 
    L3 0

    var 
    L1 0
    var 
    L4 0;

    var 
    DSX1 0;
    var 
    DSX2 0;
    var 
    bIsSemiCup false;

    function 
    main(gParamgColorSCgColorNCgGrid)
    {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;   
        if (
    gParam == nullgParam 1;
        
        if (!
    bInit)
        {
                
    xCls close();
                
    xFilC efsInternal("calcFilC"xCls);
                
    bInit true
        }
        
        if( 
    getCurrentBarIndex() < ) return;
        var 
    nBarState getBarState();
        if ( 
    nBarState == BARSTATE_NEWBAR || isReplayMode())    
        {

            var 
    nBarCount getCurrentBarCount();

            var 
    vLast gParam*xCls.getValue(0);
            var 
    curBar ;
            var 
    curMax vLast;
            while (
    curBar nBarCount)
            {
                
    vCloseCur xCls.getValue(-curBar);
                if ( 
    vCloseCur >= vLast && vCloseCur >= curMax )
                { 
                    
    nCupPeriod curBar;
                    
    curMax vCloseCur;
                }
                
    curBar++;
            }
        
            
    pTop xFilC.getValue(0);
            
    pBot xFilC.getValue(0);
            
    iBot 0;
            
    iTop 0;
            for (
    = -nCupPeriodi<0i++)
            {
                if ( 
    pTop xFilC.getValue(i) ) pTop xFilC.getValue(i);  
                if ( 
    pBot xFilC.getValue(i) ) pBot xFilC.getValue(i);
            }
            
    bHeight Math.abs((pTop pBot)/5);
            
    bLength Math.max(Math.round(nCupPeriod/5),1);
            
    b0 = -nCupPeriod;
            
    b5 0;
            
    b1 Math.min(b0 bLengthb5);
            
    b2 Math.min(b1 bLengthb5);
            
    b3 Math.min(b2 bLengthb5);
            
    b4 Math.min(b3 bLengthb5);
            
    L2 pBot 2*bHeight;
            
    L3 pBot 3*bHeight;
          
            var 
    DSX1P 0;
            var 
    DSX1N 0;
            for (
    b0b2i++ )
            {
                
    DSX1P += Math.max(xFilC.getValue(i+1)-xFilC.getValue(i),0); 
                
    DSX1N += Math.max(xFilC.getValue(i)-xFilC.getValue(i+1),0); 
            }
            
    DSX1 100 Math.abs(DSX1P DSX1N)/( eps DSX1P DSX1N );    
        
            var 
    DSX2P 0;
            var 
    DSX2N 0;
            var 
    bInside1 false;
            var 
    bInside2 false;
            for (
    b2b5i++ )
            {
                
    DSX2P += Math.max(xFilC.getValue(i+1)-xFilC.getValue(i),0); 
                
    DSX2N += Math.max(xFilC.getValue(i)-xFilC.getValue(i+1),0); 
                if ( 
    xFilC.getValue(i)>L3 bInside1=true;
                if ( 
    >= b3 && xFilC.getValue(i)>L2 bInside2=true;
            }
            
    DSX2 100 Math.abs(DSX2P DSX2N)/( eps DSX2P DSX2N );    
        
            
    bIsSemiCup = (nCupPeriod >=20 && DSX1 25 && DSX2 25 && !bInside1 && !bInside2 ); 

            if (
    gGrid)
            {
                
    drawLineRelative(b0Math.exp(pTop),b0Math.exp(pBot), PS_DASH1Color.grey"b0");  
                
    drawLineRelative(b1Math.exp(pTop),b1Math.exp(pBot), PS_DASH1Color.grey"b1");  
                
    drawLineRelative(b2Math.exp(pTop),b2Math.exp(pBot), PS_DASH1Color.grey"b2");  
                
    drawLineRelative(b3Math.exp(pTop),b3Math.exp(pBot), PS_DASH1Color.grey"b3");  
                
    drawLineRelative(b4Math.exp(pTop),b4Math.exp(pBot), PS_DASH1Color.grey"b4");  
                
    drawLineRelative(b5Math.exp(pTop),b5Math.exp(pBot), PS_DASH1Color.grey"b5");  
                
    drawLineRelative(b0Math.exp(pTop),b5Math.exp(pTop), PS_DASH1Color.grey"l0");  
                
    drawLineRelative(b0Math.exp(pBot),b5Math.exp(pBot), PS_DASH1Color.grey"l5");  
                
    drawLineRelative(b2Math.exp(L3),b5Math.exp(L3), PS_DASH1Color.grey"l3");  
                
    drawLineRelative(b3Math.exp(L2),b5Math.exp(L2), PS_DASH1Color.grey"l2");  

            }
        }
        
        
        var 
    bRTCond true;
        if (
    nBarState == BARSTATE_CURRENTBARbRTCond = ( xFilC.getValue(0) < L2 );    

        
        var 
    strSemiCup "No Cup"
        var 
    retCol gColorNC;
        if ( 
    bIsSemiCup && bRTCond 
        {
                
    strSemiCup "Semicup";
                
    retCol gColorSC;
        }

        
        
    drawTextRelative(-nCupPeriodAboveBar3
         
    "Start"retColnullText.PRESET|Text.CENTER"Arial"12"beg1");     
        
    drawTextRelative(-nCupPeriodAboveBar2
         
    "semicup"retColnullText.PRESET|Text.CENTER"Arial"12"beg2");     
        
    drawShapeRelative(-nCupPeriodAboveBar1
         
    Shape.DOWNARROWnullretColShape.PRESET|Shape.CENTER"beg3" );     

        
        
    P1 = (Math.exp(pTop)-Math.exp(pBot))/Math.pow(nCupPeriod,10);
        
    P2 0.98 Math.exp(pBot);
        
    prevY close(-nCupPeriod);
        for (
    i=0i<nCupPeriodi++)
        {
            
    curY P1 Math.pow(nCupPeriod-i,10)+P2;
            
    drawLineRelative(i-nCupPeriodprevYi-nCupPeriod+1curYPS_SOLID2retColi);
            
    prevY curY;
        }

        
    drawTextAbsolute(015strSemiCupColor.whiteretCol,
        
    Text.BOLD|Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT"Arial"11"txt");  
        return 
    null;    
    }

    var 
    bFilCInit false;
    function 
    calcFilC(xSrc)
    {
            var 
    vSrc xSrc.getValue(0);
            
    vSrc Math.log(vSrc);
            return 
    vSrc;
    }

    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;

    EFS Code: (isSemiCup.efs)
    PHP Code:
    /*********************************
    Provided By:  
        Interactive Data Corporation (Copyright © 2010) 
        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:        
        Identifying Cup Formation Early For Grid Window
     
    Version:            1.0  11/02/2011

    Formula Parameters:                     Default:
        Parameter                              1
        
    Notes:
        The related article is copyrighted material. If you are not
        a subscriber of Stocks & Commodities, please visit 
    [url]www.traders.com.[/url]

    **********************************/
    var fpArray = new Array();
    var 
    bVersion null;
    function 
    preMain()
    {
        
    setPriceStudy(true);
        
    setCursorLabelName("isSemiCup",0);
        
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("gParam"FunctionParameter.INTEGER);
        
    with(fpArray[x++])
        {
        
    setName("Parameter");
        
    setLowerLimit(1);
            
    setUpperLimit(100);
            
    setDefault(1);
        }
        
    fpArray[x] = new FunctionParameter("gColorSC"FunctionParameter.COLOR);
        
    with(fpArray[x++])
        {
        
    setName("Semicup Color");
            
    setDefault(Color.lime);
        }
        
    fpArray[x] = new FunctionParameter("gColorNC"FunctionParameter.COLOR);
        
    with(fpArray[x++])
        {
        
    setName("No Cup Color");
            
    setDefault(Color.red);
        }
    }

    var 
    bInit false;
    var 
    xCls null;
    var 
    xFilC null;
    var 
    eps 0.0000000001;
    var 
    vCls 0;
    var 
    nCupPeriod 0;

    var 
    pTop 0;
    var 
    pBot 0;
    var 
    b0 0
    var 
    b1 0
    var 
    b2 0
    var 
    b3 0
    var 
    b4 0
    var 
    b5 0
    var 
    L2 0
    var 
    L3 0

    var 
    DSX1 0;
    var 
    DSX2 0;
    var 
    bIsSemiCup false;

    function 
    main(gParamgColorSCgColorNC)
    {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;   
        if (
    gParam == nullgParam 1;
       
        if (!
    bInit)
        {
                
    xCls close();
                
    xFilC efsInternal("calcFilC"xCls);
                
    bInit true
        }
        
        if( 
    getCurrentBarIndex() < ) return;

        var 
    nBarState getBarState();
        if ( 
    nBarState == BARSTATE_NEWBAR )    
        {
            var 
    nBarCount getCurrentBarCount();

            var 
    vLast gParam*xCls.getValue(0);
            var 
    curBar ;
            var 
    curMax vLast;
            while (
    curBar nBarCount)
            {
                var 
    vCloseCur xCls.getValue(-curBar);
                if ( 
    vCloseCur >= vLast && vCloseCur >= curMax )
                { 
                    
    nCupPeriod curBar;
                    
    curMax vCloseCur;
                }
                
    curBar++;
            }

            
    pTop xFilC.getValue(0);
            
    pBot xFilC.getValue(0);
            for (
    = -nCupPeriodi<0i++)
            {
                if ( 
    pTop xFilC.getValue(i) ) pTop xFilC.getValue(i);  
                if ( 
    pBot xFilC.getValue(i) ) pBot xFilC.getValue(i);
            }
            var 
    bHeight Math.abs((pTop pBot)/5);
            var 
    bLength Math.max(Math.round(nCupPeriod/5),1);
            
    b0 = -nCupPeriod;
            
    b5 0;
            
    b1 Math.min(b0 bLengthb5);
            
    b2 Math.min(b1 bLengthb5);
            
    b3 Math.min(b2 bLengthb5);
            
    b4 Math.min(b3 bLengthb5);
            
    L2 pBot 2*bHeight;
            
    L3 pBot 3*bHeight;
            
            var 
    DSX1P 0;
            var 
    DSX1N 0;
            for (
    b0b2i++ )
            {
                
    DSX1P += Math.max(xFilC.getValue(i+1)-xFilC.getValue(i),0); 
                
    DSX1N += Math.max(xFilC.getValue(i)-xFilC.getValue(i+1),0); 
            }
            
    DSX1 100 Math.abs(DSX1P DSX1N)/( eps DSX1P DSX1N );    

            var 
    DSX2P 0;
            var 
    DSX2N 0;
            var 
    bInside1 false;
            var 
    bInside2 false;
            for (
    b2b5i++ )
            {
                
    DSX2P += Math.max(xFilC.getValue(i+1)-xFilC.getValue(i),0); 
                
    DSX2N += Math.max(xFilC.getValue(i)-xFilC.getValue(i+1),0); 
                if ( 
    xFilC.getValue(i)>L3 bInside1=true;
                if ( 
    >= b3 && xFilC.getValue(i)>L2 bInside2=true;
            }
            
    DSX2 100 Math.abs(DSX2P DSX2N)/( eps DSX2P DSX2N );    
            
            
    bIsSemiCup = (nCupPeriod >=20 && DSX1 25 && DSX2 25 && !bInside1 && !bInside2 )  ; 
        }
        
        if (
    nBarState == BARSTATE_CURRENTBARbIsSemiCup = ( bIsSemiCup && xFilC.getValue(0) < L3 ); 
        
        var 
    strSemiCup "NO CUP"
        var 
    retColor gColorNC;
        if ( 
    bIsSemiCup 
        {
                
    strSemiCup "SEMICUP";
                
    retColor gColorSC;
        }

        
    setBarBgColor(retColor,0);
        
    setBarFgColor(Color.white,0);
        
        return 
    strSemiCup;    
        
    }

    var 
    bFilCInit false;
    function 
    calcFilC(xSrc)
    {
            var 
    vSrc xSrc.getValue(0);
            
    vSrc Math.log(vSrc);
            return 
    vSrc;
    }

    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;

    Last edited by eSignal; 03-14-2011, 06:40 AM.
Working...
X