Announcement

Collapse
No announcement yet.

2013 Apr: Low-Frequency Trading, by Ron McEwan

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

  • 2013 Apr: Low-Frequency Trading, by Ron McEwan

    File Name: OneYear_CumAdvDecMA.efs

    Description:
    Low-Frequency Trading, by Ron McEwan

    Formula Parameters:

    OneYear_CumAdvDecMA.efs
    SMA Length 253
    Long Position Color lime
    Short Position Color red

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

    Download File:
    OneYear_CumAdvDecMA.efs

    OneYear_CumAdvDecMA.efs


    EFS Code:
    PHP Code:
    /*********************************
    Provided By:  
    eSignal (Copyright c eSignal), a division of Interactive Data 
    Corporation. 2012. All rights reserved. This sample eSignal 
    Formula Script (EFS) is for educational purposes only and may be 
    modified and saved under a new file name.  eSignal is not responsible
    for the functionality once modified.  eSignal reserves the right 
    to modify and overwrite this EFS file with each new release.

    Description:     
        Low-Frequency Trading, by Ron McEwan

    Version:            1.00  02/08/2013

    Formula Parameters:                         Default:
    SMA Length                                  253
    Long Position Color                         lime
    Short Position Color                        red

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

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

    var fpArray = new Array();

    function 
    preMain()
    {       
        
    setStudyTitle("OneYear_CumAdvDecMA");    
        
    setIntervalsBackfill(true);
        
        
    setCursorLabelName("*** AD Line",0);    
        
    setCursorLabelName("MA",1);
        
        
    setDefaultBarFgColor(Color.blue0); 
        
    setDefaultBarFgColor(Color.purple1); 
        
        var 
    0;
        
        
    fpArray[x] = new FunctionParameter("gLength"FunctionParameter.NUMBER);
        
    with(fpArray[x++])
        {
            
    setName("SMA Length");        
            
    setLowerLimit(1);
            
    setDefault(253); 
        }     

        
    fpArray[x] = new FunctionParameter("gBuyColor"FunctionParameter.COLOR);
        
    with(fpArray[x++])
        {
            
    setName("Long Position Color");    
            
    setDefault(Color.lime);
        } 
        
        
    fpArray[x] = new FunctionParameter("gSellColor"FunctionParameter.COLOR);
        
    with(fpArray[x++])
        {
            
    setName("Short Position Color");    
            
    setDefault(Color.red);
        } 

    }

    var 
    bInit false;
    var 
    bVersion null;

    var 
    xCumAd null;
    var 
    xSMA null;

    function 
    main(gLength,gBuyColor,gSellColor)
    {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return; 
      
        if (!
    bInit)
        {        
            
    xCumAd=efsInternal("getCumAd");
            
    xSMA sma(gLength,xCumAd);
        }  

        var 
    nCumAd xCumAd.getValue(0);
        var 
    nSMA xSMA.getValue(0);

        if (
    nCumAd == null || nSMA == null) return;
        
        
        if (
    getCurrentBarIndex() != 0
        {       
                var 
    bLStrategy Strategy.isLong();            
                
                if (!
    bLStrategy)
                {
                    if (
    nCumAd>nSMA)
                    {
                       
    Strategy.doLong("Enter Long"Strategy.CLOSEStrategy.THISBAR);                                                    
                       
    drawShapeRelative(0BottomRow3,Shape.DIAMOND,nullgBuyColorShape.PRESET);
                    }           
                }            
                else
                {
                    if (
    nCumAd<nSMA)
                    {
                        
    Strategy.doSell("Close Long"Strategy.CLOSEStrategy.THISBAR);                      
                        
    drawShapeRelative(0TopRow3,Shape.DIAMOND,nullgSellColorShape.PRESET);
                    }        
                }     
        }
        
        return new Array(
    nCumAd,nSMA);        
    }

    var 
    bCumAd false;

    var 
    xAdv null;
    var 
    xDecl null;

    var 
    cumAd 0;

    function 
    getCumAd()
    {
        if (
    getBarState() == BARSTATE_ALLBARS)
        {
            
    bCumAd false;
        }

         if(!
    bCumAd)
        {
            
    xAdv close(sym("$ADV,D"));
            
    xDecl close(sym("$DECL,D"));    
            
    cumAd 0;
            
            
    bCumAd true;
        }

        var 
    nAdv xAdv.getValue(0);
        var 
    nDecl xDecl.getValue(0);

        if (
    nAdv == null || nDecl == null || (nAdv+nDecl)==0) return;
        
        var 
    pctChg = (nAdv-nDecl)/(nAdv+nDecl)*1000;
        
        var 
    ret ref(-1);
        
        
    cumAd ret pctChg
        
        return 
    cumAd;
    }

    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;

Working...
X