Announcement

Collapse
No announcement yet.

2013 Feb: The Volatility (Regime) Switch Indicator by Ron McEwan

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

  • 2013 Feb: The Volatility (Regime) Switch Indicator by Ron McEwan

    File Name: VolatilitySwitch.efs

    Description:
    The Volatility (Regime) Switch Indicator by Ron McEwan

    Formula Parameters:

    VIX_TimingSystem.efs
    Volatility Days Period 21

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

    Download File:
    VolatilitySwitch.efs

    VolatilitySwitch.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:     
        The Volatility (Regime) Switch Indicator by Ron McEwan

    Version:            1.00  12/10/2012

    Formula Parameters:                         Default:
    Volatility Days Period                      21

    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("Volatility Switch");      
        
        var 
    0;
        
        
    fpArray[x] = new FunctionParameter("gDays"FunctionParameter.NUMBER);
        
    with(fpArray[x++])
        {
            
    setName("Volatility Days Period");
            
    setLowerLimit(1);        
            
    setDefault(21);
        }     
    }

    var 
    bInit false;
    var 
    bVersion null;

    var 
    xClose null;

    function 
    main(gDays)
    {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;    
        
        if(!
    bInit)
        {
            
    xClose close();                
            
    bInit true;
        } 

        if (
    xClose.getValue(-gDays*2) == null) return;
        
    addBand(0.5,PS_DASH,1,Color.red,0);
        
        var 
    vDailyRet_0 0;
        var 
    vDailyRet_1 0;    
        var 
    nDailyRet 0;
        
        var 
    nSumDailyRet 0//for average
        
    var nSumDeviation 0//for deviation
        
        
    var 0;
        var 
    0;
        
        var 
    nCnt 0;
        var 
    nAvg 0;
        var 
    nVol 0;
        var 
    nVol0 0;
        
        for (
    j=0j>-gDaysj--)
        {
            
    //daily return and its average
            
    nSumDailyRet=0;
            for (
    i=ji>j-gDaysi--)
            {
                
    vDailyRet_0 xClose.getValue(i);
                
    vDailyRet_1 xClose.getValue(i-1);
                
    nDailyRet = (vDailyRet_0-vDailyRet_1)/((vDailyRet_0+vDailyRet_1)/2);        
                
                
    nSumDailyRet +=  nDailyRet;
            }            
            
    nAvg nSumDailyRet/gDays;       
            
            
    //21nd hist Volatility (standart deviation)
            
    nSumDeviation 0nVol=0;
            for (
    i=ji>j-gDaysi--)
            {
                
    vDailyRet_0 xClose.getValue(i);
                
    vDailyRet_1 xClose.getValue(i-1);
                
    nDailyRet = (vDailyRet_0-vDailyRet_1)/((vDailyRet_0+vDailyRet_1)/2);
                
                
    nSumDeviation += (nAvg nDailyRet)*(nAvg nDailyRet);
            }    
            
    nVol=Math.sqrt(nSumDeviation/gDays);

            
    //remember 21nd hist Volatility for current bar
            
    if (j==0nVol0=nVol;
            
    //compare 21nd hist Volatility for current and previous bars
            
    if (nVol<=nVol0nCnt++;            
        }    
            
        var 
    nVolSwitch nCnt/gDays;
        return 
    nVolSwitch;
    }

    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