Announcement

Collapse
No announcement yet.

barDate = getValue("time"); how to use it for Day Of Week table

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

  • barDate = getValue("time"); how to use it for Day Of Week table

    I like to use a very small chart to display a very small table of data. I use the time frame of 390 minutes since this works well for the Dow futures to get the Hi Low Range during regular market hours, 09:30 to 16:00. I simply display the change from the previous close and the range ... and I like the day of week to be shown too ( M T W Th F ).

    I have worked with


    barDate = getValue("time");
    dayOfWeek = barDate.getDay();

    that I had found in another post. No suprise here, I have not been able to get it to do what I want.

    Instead of having to update this part of the code each day, manually incrementing the T to W , M to T, and so on

    if(getBarState()==BARSTATE_NEWBAR) {


    drawTextRelative( x1, y1, " T" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 112);
    drawTextRelative( x1, y2, " M" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 113);
    drawTextRelative( x1, y3, " F" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 114);
    drawTextRelative( x1, y4, " Th" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 115);
    drawTextRelative( x1, y5, " W" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 116);
    drawTextRelative( x1, y6, " T" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 117);
    drawTextRelative( x1, y7, " M" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 118);
    drawTextRelative( x1, y8, " F" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 119);
    drawTextRelative( x1, y9, " Th" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 120);
    drawTextRelative( x1, y10," W" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 121);
    drawTextRelative( x1, y11," T" , Color.yellow,null,Text.BOLD|Text.VCENTER|Text.RELA TIVETOTOP|Text.RELATIVETOLEFT, "Courier New", 12, 122);
    }

    Is there a way that some one who is adept at coding ( not me : ) would have the program do this automatically ?

    Thanks,
    Glenn

  • #2
    Hello Glenn,

    One approach would be to use the following


    PHP Code:

    function main()
    {

        
    // getValue("time") --> Fri Nov 25 2016 13:00:00 GMT+1100 (AUS Eastern Daylight Time)
        //                      0123456789012345678901234567890123456789012345678901234567890
        //                                1         2         3         4         5         6


        
    var FullDateTime "" getValue("time")
        var 
    thisTime FullDateTime.substr(16,5);
        var 
    thisDateTime FullDateTime.substr(0,21);
        var 
    thisDay FullDateTime.substr(0,3);

        var 
    thisBI getCurrentBarIndex()
        var 
    intBI parseInt(thisBI);

        if(
    intBI == 0)
        {
            
    debugPrintln("thisDay: " thisDay "\tthisDateTime: " thisDateTime);

            switch(
    thisDay)
                {
                    case 
    "Mon":

                        
    debugPrintln("Day = MONDAY");

                        break;

                    case 
    "Tue":

                        
    debugPrintln("Day = TUESDAY");

                        break;
                    case 
    "Wed":

                        
    debugPrintln("Day = WEDNESDAY");

                        break;
                    case 
    "Thu":

                        
    debugPrintln("Day = THURSDAY");

                        break;
                    case 
    "Fri":

                        
    debugPrintln("Day = FRIDAY");

                        break;

                    default:

                        
    debugPrintln("Day = either SATURDAY or SUNDAY");

                }
        }          

        return 
    null;


    I tried using if(getBarState() == BARSTATE_ALLBARS) but this acts on the last bar in the chart (i.e. the earliest bar)
    BARSTATE_CURRENTBAR and BARSTATE_NEWBAR did not seem to work, hence the reason I used the BarIndex.

    HTH
    Mark

    Comment

    Working...
    X