Announcement

Collapse
No announcement yet.

getValueAbsolute question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • getValueAbsolute question

    I'm looking to use the getValueAbsolute function, but I think my understanding of the function itself needs a little help.

    In the EFS function reference the funtion is listed as follows: getValueAbsolute( barType [, nOffset] [, nNumBars] [,Symbol] )

    However, in many of the formulas that I have seen written the funtion is used as follows: vH = getValueAbsolute("High", vIndex, vSymbol); with vIndex as follows vIndex = getFirstBarIndexOfDay(vAbsTime, vSymbol);

    In the above usage it is clear that the bartype matches up to the "high", but the vIndex variable and the vSymbol dont seem to clearly match up. The symbol would appear to match the vSymbol variable, but I'm missing the connection between the offset / numbars portion of the formula and the vIndex variable. I would like to use this function and need help bridging the gap in my understanding. Thank you in advance for any help.

  • #2
    Hello gregoryhong,

    First, let's start with the simple explanation, then I'll explain how it's being used in the formula example you mentioned.

    The difference between getValue() and getValueAbsolute() is that getValue retrieves the price that is relative to the current bar index being processed by the formula. getValueAbsolute doesn't care what the current bar index is. It gets the price from the absolute bar index that is specified. Take a look at the code snippet below. When you run this it prints two prices to the formula output window. This occurs when the formula is loading and processes bar -10.

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("getValueAbsolute ");
        
    setCursorLabelName("price");
    }

    var 
    bFlag false;
    debugClear();

    function 
    main(bar) {
        if (
    bar == nullbar = -10;
        var 
    nIndex getCurrentBarIndex();
        
        if (
    nIndex == bar && bFlag == false) {
            var 
    vValue getValue("close", -11);
            
    vValue[0] = vValue[0].toFixed(2)*1;
            
    debugPrintln("at bar " bar " getValue = " vValue);
            
            var 
    vValueAbs getValueAbsolute("close", -11);
            
    vValueAbs[0] = vValueAbs[0].toFixed(2)*1;
            
    debugPrintln("at bar " bar " getValueAbsolute = " vValueAbs);
            
    bFlag true;
        }
        
        return;

    At bar -10 on a daily chart of IBM, we get



    The offset parameter of -1 when used with getValue retreives the close from 1 bar prior to bar -10, which is bar -11. The offset parameter of -1 with getValueAbsolute retreives the close from the absolute index of -1, which is yesterday's bar or bar -1 on the daily chart.


    Now, in the formula example you mentioned, which is a typical routine for displaying daily pivot points on intra-day charts, we need to include a few more details. Fist, take a look at the code below, which is from \Formulas\Pivots\PivotPoint.efs

    PHP Code:
    var vLastRawTime null;
    var 
    vLastValue null;
    var 
    vSymbol null;
    var 
    vInterval null;


    function 
    main() {
        var 
    vH;
        var 
    vL;
        var 
    vC;
        var 
    vRawTime;
        var 
    vBarTime;
        var 
    vAbsTime;
        var 
    vIndex;

        var 
    nState getBarState();
        if(
    nState == BARSTATE_ALLBARS) {
            
    vLastRawTime null;
            
    vLastValue null;
            
    vInterval getInterval();
            
    vSymbol getSymbol();
            
    vSymbol += ",D";
        }

        
    vRawTime getValue("rawtime");
        if(
    vRawTime == null)
            return;

        
    vRawTime Math.floor(vRawTime RawTime.DAY);

        
    // Start of Performance addition
        
    if(vRawTime != null && vLastRawTime != null) {
            if(
    vRawTime == vLastRawTime) {
                return 
    vLastValue;
            }
        }


        if(
    vInterval == null)
            return 
    null;

        if(
    vInterval == "D")
            return 
    null;

        
    vBarTime getValue("time");
        if(
    vBarTime != null) {
            
    vAbsTime getPreviousTradingDay(vBarTimevSymbol);
            if(
    vAbsTime == null)
                return;

            
    vIndex getFirstBarIndexOfDay(vAbsTimevSymbol);
            if(
    vIndex != null) {
                
    vH getValueAbsolute("High"vIndexvSymbol);
                
    vL getValueAbsolute("Low",  vIndexvSymbol);
                
    vC getValueAbsolute("Close"vIndexvSymbol);
                                                                      
                if(
    vH != null && vL != null && vC != null) {
                    
    vLastValue = (vH vL vC) / 3;
                    
    vLastRawTime vRawTime;
                    return 
    vLastValue;
                }
            }
        }

        return 
    null;


    For getValueAbsolue("High", vIndex, vSymbol), vSymbol in this example is set to a string representing the chart's symbol + ",D" so that the call to getValueAbsolute will look at the daily interval chart for the current symbol. If this is ran on a 5-minute chart of IBM, vSymbol would be "IBM,D" . vIndex is getting set to the bar index from the daily chart for the previous trading day of the current bar being processed in the intra-day chart.

    At the line where vBarTime = getValue("time"), vBarTime gets set to the date of the bar being processed. The following vAbsTime variable then gets set to the date of the previous trading day of vBarTime with the function getPreviousTradingDay(date, symbol). Now that we have the date of the previous trading day for the bar being process, we need to get the bar index for that day from the daily chart. That's what vIndex = getFirstBarIndexOfDay(date, symbol) does for us. Since the symbol we're passing to this function is "IBM,D" it will give us the bar index from the daily interval based on the date we passed to it, or vAbsTime.
    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

    Comment


    • #3
      thanks for the help Jason ,

      Your info and example definately helped in my understanding, but
      I guess the point Im missing is why the pivot point formula does not take on the form "getValueAbsolute( barType [, nOffset] [, nNumBars] [,Symbol] )".
      I was hoping to use the function to get an array of the first ten or so bars of the day on a one minute tick and then to find the maximum and minimum of that array and then plot those levels as a price study on the chart.

      THanks for again for the help.

      Comment


      • #4
        Jason,

        That was a great overview on getValueAbsolute().

        gregoryhong,

        What you are missing I think is that the parameters in [] are optional. If they are provided they are used, but if not then the system uses its own defaults:

        ie:
        Symbol = current chart symbol
        Interval = current chart interval
        Offset = 0
        NumBar = 1

        clearly in the case of OffSet and NumBar the system may get confused if you only do NumBar, because it assumes that if only one number is provided it will be OffSet. But other than that, feel free to leave out anything in [] that isn't different from the defaults.

        Garth
        Garth

        Comment


        • #5
          Thanks Garth.

          One thing to add to the explanation of nNumBars is that this parameter tells the function how many prices to get starting from the specified offset. If you pass nothing or 1, you will get a single value. If you pass a positive number, such as 2 for nNumBars, you get an array of data where,

          vValue[0] = price at offset
          vValue[1] = price at offset +1 (the next bar)

          If you pass -2 for nNumBars, you get an array where,

          vValue[0] = price at offset
          vValue[1] = price at offset -1 (previous bar)

          The [0] element will always be the specified offset. The sign of the nNumBars parameter tells it what direction to go from that bar to fill the other elements of the array. Use the first code example from my previous post and change the 1 to 2 or -2.
          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

          Comment

          Working...
          X