Announcement

Collapse
No announcement yet.

Display getPreviousTradingDay() before Market open

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

  • Display getPreviousTradingDay() before Market open

    How do I get the function "getPreviousTradingDay()" and close("inv("D")) to display Previous Trading Day date/time before the market open, 9:30am EST?

    / Example:
    If today is Wednesday and time is 9:00am, getPreviousTradingDay() will display Monday.

    If today is Wednesday and time is 9:31am, getPreviousTradingDay() will display Tuesday.

    I would like it to display 'Tuesday" at 9:00am.

    Code:
    nTime = getValue("rawtime");
    if (nTime != null) {
    var nPreviousDay = getPreviousTradingDay(nTime);
    debugPrintln("nPreviousDay:" + nPreviousDay);

    xPrevClose = close(inv("D"));
    var vPrevClose = xPrevClose.getValue(-1);
    debugPrintln("vPrevClose:" + vPrevClose);
    }

  • #2
    Re: Display getPreviousTradingDay() before Market open

    syeh
    A relatively simple way to accomplish this is shown in the code snippet enclosed below that also includes some comments
    PHP Code:
    //your main function
        
    var DateObjectRawtimeTimeBarIndex;
        
    //using system time if for example plotting daily bars
        
    DateObject = new Date();
        
    Time = (DateObject.getHours()*100)+DateObject.getMinutes();
        
    //alternatively using bar time if for example plotting pre-market intraday bars
        //Time = (hour(0)*100)+minute(0);
        
    if(Time 930){//set here the time at which the switch should occur
            
    RawTime rawtime(0)+86400;//this in effect modifies rawtime to the next day's equivalent
            
    BarIndex 0;
        } else {
            
    RawTime rawtime(0);
            
    BarIndex = -1;
        }
        
    debugPrintln(getPreviousTradingDay(RawTime)+" "+close(BarIndexinv("d")));
    //rest of your code 
    Note that this is just a basic example to illustrate the logic. You can then modify it as necessary depending on how you intend to use it
    Alex


    Originally posted by syeh
    How do I get the function "getPreviousTradingDay()" and close("inv("D")) to display Previous Trading Day date/time before the market open, 9:30am EST?

    / Example:
    If today is Wednesday and time is 9:00am, getPreviousTradingDay() will display Monday.

    If today is Wednesday and time is 9:31am, getPreviousTradingDay() will display Tuesday.

    I would like it to display 'Tuesday" at 9:00am.

    Code:
    nTime = getValue("rawtime");
    if (nTime != null) {
    var nPreviousDay = getPreviousTradingDay(nTime);
    debugPrintln("nPreviousDay:" + nPreviousDay);

    xPrevClose = close(inv("D"));
    var vPrevClose = xPrevClose.getValue(-1);
    debugPrintln("vPrevClose:" + vPrevClose);
    }

    Comment

    Working...
    X