Announcement

Collapse
No announcement yet.

RefUsage.efs

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

  • RefUsage.efs

    File Name: RefUsage.efs

    Description:
    The function, ref(), is used to refer to previously returned values of a formula’s indicator. This example formula demonstrates the usage of ref() for formulas that return only one indicator to the chart.

    Formula Parameters:
    None.

    Notes:
    The formula uses a basic moving average study and outputs information to the Formula Output Window. To view the results, open the output window before applying the formula to a chart from the “Tools” menu.

    Download File:
    RefUsage.efs

    Image: N/A


    EFS Code:
    PHP Code:
    /*******************************
    Provided By : eSignal. (c) Copyright 2003
    *******************************/

    /***  syntax: ref(nRelativeOffset, nNumBars)   ***

        These examples are based on formulas that return a single value.  For example:
            return vValue;
            
        See RefUsage2.efs for examples of formulas that returns an array of values. For example:
            return new Array(vValue1, vValue2);
        
        var myRef = ref(-1)     Returns the previous bar's value.
        var myRef = ref(-3, 3)  Returns values of bars -3 to -1 bars ago.
        var myRef = ref(-1, -3) Returns values of bars -1 to -3 bars ago.
        
        Note:   VERY IMPORTANT!!
        
                When using ref() it is very important that you incorporate some logic into your
                code that will ensure that ref() returns a valid result.  See the "BarCntr" logic 
                below.  If you don't use the BarCntr logic or some other technique, you will get
                unfavorable results.

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

    var study1 = new MAStudy(100"Close"MAStudy.Simple);
     
    function 
    preMain() {
        
    setPriceStudy(true);
    }

    var 
    BarCntr 0;
    function 
    main() {
        var 
    vMA1 study1.getValue(MAStudy.MA);
        
        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    BarCntr += 1;
        }

    /***  BarCntr logic  ***/
        
    if (BarCntr 10) {     // We're using 10 because our MAStudy requires a minimum of 10 bars.
        
    var myRef ref(-1);
        if (
    myRef == null) return;
        
    //var myRef = ref(-3, 3);
        //var myRef = ref(-1, -3);
        
    }


        
    // Open the Formula Output Window from the tools menu to view the values of myRef.
        
    if (BarCntr 10) {
            
    debugPrintln("Bar Index: " getCurrentBarIndex() + "    myRef= " myRef);
        }
        
        return 
    vMA1;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation
Working...
X