Announcement

Collapse
No announcement yet.

Why does this code for getting yesterdays close not work?

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

  • Why does this code for getting yesterdays close not work?

    I have the following in my preMain:

    setPriceStudy(false);
    setPlotType(PLOTTYPE_LINE);
    setCursorLabelName("Close");

    Then in my main, I have the following:

    //get the rawtime value for the current bar
    var nTime = getValue( "rawtime", 0 );

    if (nTime != null)
    {
    //get the date value for the prior trading day, if any
    var nPriorDay = getPreviousTradingDay(nTime);

    if (nPriorDay != null)
    {
    //get the bar index to the first bar of the day in nTime.
    var nFirstBarIndex = getFirstBarIndexOfDay(nTime);

    debugPrintln("nFirstBarIndex = " + nFirstBarIndex);

    //get the close value for the bar prior to the first bar of the day.
    var yesterdaysClose = close(nFirstBarIndex - 1);

    debugPrintln("yesterdays close = " + yesterdaysClose);
    }
    }

    When I print out the debug info., the most recent closed bar produces the correct value for yesterday's close but all other's are close but not the same. They are all slightly different and don't seem to correspond with any value on the chart.

    I have fixed this algorithm by getting the close value from a daily chart but I would still like to know why this does not work.

    Thanks.

  • #2
    Hello crazytiger,

    The process you've posted describes the pre-EFS2 method for retrieving the prior day's daily values while on an intraday chart interval. This process isn't necessary with EFS2. All you need to do is create a series based on the daily interval and reference the prior day from this series by referencing bar -1.

    PHP Code:
    function main() {
        return 
    close(-1inv("D"));

    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