Announcement

Collapse
No announcement yet.

VIDYA (StdDev)

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

  • VIDYA (StdDev)

    File Name: VIDYA.efs

    Description:
    Indicator - VIDYA (StdDev)

    Formula Parameters:
    Length: 21
    Price: Close
    Alpha: 0.02


    Notes:
    This indicator plots volatility adjusted length exponential MA based
    on standard deviation of prices as a measure of volatility. It is dynamic,
    not static indicator: a variable-length moving average, which adapts to the
    volatility in question by exponentially smoothing data based on standard deviation.


    Download File:
    VIDYA.efs



    EFS Code:
    PHP Code:
    /*********************************
    Provided By:  
        eSignal (Copyright c eSignal), a division of Interactive Data 
        Corporation. 2008. 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:        
       Indicator - VIDYA (StdDev) 

    Version:            1.0  09/26/2008

    Notes:
        This indicator plots volatility adjusted length exponential MA based
        on standard deviation of prices as a measure of volatility. It is dynamic,
        not static indicator: a variable-length moving average, which adapts to the
        volatility in question by exponentially smoothing data based on standard deviation. 
        
    Formula Parameters:                     Default:
        Length                                21
        Price                                Close
        Alpha                                0.02

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

    var fpArray = new Array();
    var 
    bInit false;

    function 
    preMain()
    {
        
    setPriceStudy(true);
        
    setStudyTitle("VIDYA (StdDev)");
        
    setCursorLabelName("VIDYA");
        
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(20);
        }

        
    fpArray[x] = new FunctionParameter("Price"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setName("Price Data To Use");
            
    addOption("open"); 
            
    addOption("high");
            
    addOption("low");
            
    addOption("close");
            
    addOption("hl2");
            
    addOption("hlc3");
            
    addOption("ohlc4"); 
            
    setDefault("close"); 
        }


        
    fpArray[x] = new FunctionParameter("Alpha"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(0.01);        
            
    setDefault(0.2);
        }
        
        
    }

    var 
    xMyPrice null;
    var 
    xStdDev null;
    var 
    xStdDevAvg null;

    function 
    main(AlphaPriceLength) {
    var 
    nState getBarState();
    var 
    nRef ref(-1);
    var 
    nStdDevVidya 0;
    var 
    nStdDev 0;
    var 
    nStdDevAvg 0;
    var 
    nPrice 0;
    var 
    nResult 0;
    var 
    nBarCount getCurrentBarCount();


        if (
    nState == BARSTATE_ALLBARS) {
            if (
    Alpha == nullAlpha 0.2;
            if (
    Price == nullPrice "close";
            if (
    Length == nullLength 20;
        }    


        if ( 
    bInit == false ) { 
            
    xMyPrice = eval(Price)();
            
    xStdDev efsInternal("StdDev"xMyPriceLength); 
            
    xStdDevAvg sma(LengthxStdDev);
            
    bInit true
        } 


        if (
    nRef == nullnRef 1;

        
    nStdDev xStdDev.getValue(0);
        
    nStdDevAvg xStdDevAvg.getValue(0);
        
    nPrice xMyPrice.getValue(0);


        if(
    nBarCount>Length)
            
    nStdDevVidya = (Alpha * (nStdDev nStdDevAvg) * nPrice) +
                ((
    - (Alpha * (nStdDev nStdDevAvg))) * nRef);
        else if (
    nBarCount==LengthnStdDevVidya nPrice;
            else return;

        return 
    nStdDevVidya;
    }



    function 
    StdDev(DataArray ,Period) {
    var 
    sum 0;
    var 
    avg 0;
    var 
    res 0;
      
        if (
    getCurrentBarCount() < Period) return DataArray.getValue(0);
     
        for (var 
    barsBack Period-1barsBack >= 0barsBack--) {
            
    sum += DataArray.getValue(barsBack*(-1));
        }

        
    avg sum Period;
        
    sum 0;

        for (var 
    barsBack Period 1barsBack >= 0barsBack--) {
            
    sum += (DataArray.getValue(barsBack*(-1))-avg)*(DataArray.getValue(barsBack*(-1))-avg);
        }

        
    res Math.sqrt(sum Period);

     
        return 
    res

Working...
X