Announcement

Collapse
No announcement yet.

2012 Dec: Using VIX To Forecast The S&P 500 by Trent Gardner

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

  • 2012 Dec: Using VIX To Forecast The S&P 500 by Trent Gardner

    File Name: VIX_TimingSystem.efs

    Description:
    Using VIX To Forecast The S&P 500 by Trent Gardner

    Formula Parameters:

    VIX_TimingSystem.efs
    Long Position Color lime
    Short Position Color red
    SMA Period 50
    Days Limit 11

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

    Download File:
    VIX_TimingSystem.efs

    VIX_TimingSystem.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:        
    Using VIX To Forecast The S&P 500 by Trent Gardner

    Version:            1.00  12/10/2012

    Formula Parameters:                     Default:
    Long Position Color                     lime
    Short Position Color                    red
    SMA Period                              50
    Days Limit                              11

    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("VIX_TimingSystem");
        
    setIntervalsBackfill(true);    
        
    setPriceStudy(true);

        var 
    x=0;
        
        
    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);
        } 

        
    fpArray[x] = new FunctionParameter("gSMAPeriod"FunctionParameter.NUMBER);
        
    with(fpArray[x++])
        {
            
    setName("SMA Period");    
            
    setLowerLimit(1);
            
    setDefault(50);
        } 

        
    fpArray[x] = new FunctionParameter("gDaysLimit"FunctionParameter.NUMBER);
        
    with(fpArray[x++])
        {
            
    setName("Days Limit");    
            
    setLowerLimit(1);
            
    setDefault(11);
        } 
    }

    var 
    bInit false;
    var 
    bVersion null;

    var 
    xLow null;
    var 
    xSMA null;
    var 
    xSMA50 null;

    function 
    main(gBuyColor,gSellColor,gSMAPeriod,gDaysLimit)
    {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return; 
        
        if(!
    bInit)
        {
            
    xLow low(sym("$VIX"));        
            
    xSMA sma(gSMAPeriod,xLow);     
            
            
    xSMA50 sma(gSMAPeriod);             
            
            
    bInit true;
        }
        
        var 
    vLow   xLow.getValue(-gDaysLimit);
        var 
    vSMA   xSMA.getValue(-gDaysLimit);   
        var 
    vSMA50 xSMA50.getValue(-gDaysLimit);  
        
        if ((
    vLow == null) || (vSMA == null) || (vSMA50 == null)) 
            return;
        
        var 
    cntUp 0;
        var 
    cntDown 0;
        
        for (
    i=-gDaysLimiti<0i++)
        {
            if (
    xLow.getValue(i)>xSMA.getValue(i)) cntUp++;
            if (
    xLow.getValue(i)<xSMA.getValue(i)) cntDown++;
        }
        

        
    // Back Testing formulas are not for real time analysis.
        // Therefore, prevent processing and exit at bar 0.
        
    if (getCurrentBarIndex() != 0
        {       
                var 
    bLStrategy Strategy.isLong();            
                
                if (!
    bLStrategy)
                {
                    if (
    cntDown>=gDaysLimit)
                    {
                       
    Strategy.doLong("Enter Long"Strategy.MARKETStrategy.THISBAR);        
                       
    drawTextRelative(0BelowBar1"Long"Color.blackgBuyColorText.PRESETnullnull);                                   
                    }           
                }            
                else
                {
                    if (
    cntUp>=gDaysLimit)
                    {
                        
    Strategy.doShort("Enter Short"Strategy.MARKETStrategy.THISBAR);  
                        
    drawTextRelative(0AboveBar1"Short"Color.blackgSellColorText.PRESETnullnull);       
                    }        
                }     
        }
       
        return 
    xSMA50.getValue(0);        
    }

    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 [email protected]=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