Announcement

Collapse
No announcement yet.

Time issue - playback and actual

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

  • Time issue - playback and actual

    G'day Folks,

    I'm trying to do something quite simple and it seems i'm missing something somewhere. The following bit of script gets me the day ( 0 to 6 ) of the week.

    var vTime = new Date();
    var gBarDay;
    var txtFlags = Text.ONTOP | Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM;

    function preMain(){
    setPriceStudy(true);
    setShowTitleParameters(false);
    setShowCursorLabel(false);
    }
    function main(){

    vTime = getValue("Time",0)
    gBarDay = vTime.getDay();
    drawTextAbsolute(5, 520, "gBarDay " + gBarDay + ", vTime is " + vTime, Color.blue, null, txtFlags, null, 22, ("test"));
    }

    This works and returns a value for gBarDay of 1 on Monday (lower image). Now I wish to do something (print the line for example) in particular given that the day returned is 5 as in the following....

    if(gBarDay == 5) drawTextAbsolute(5, 520, "gBarDay " + gBarDay + ", vTime is " + vTime, Color.blue, null, txtFlags, null, 22, ("test"));


    and as you can see in the upper image, it merely changes the returned values and prints anyways, even though, in reality - this is done on Day 1 or Monday.

    Any ideas ?

    Chris
    Attached Files

  • #2
    Hi Chris,

    This is because you are getting what you are asking for.

    Outside main(), you are setting var vTime = new Date(); to today's date object. Then you turn around and inside main(), you assign the global variable to be equal to a date object created from bar data. There is nothing wrong there... vTime = getValue("Time",0); (there was no need to assign it to your PC's date object outside main(), it could have just as easily been assigned any value, like a number, a null, a string, or none at all. All you were really doing in this example was creating a 'global container' and assigning it a date object).

    I believe what you are 'missing' is that you are outputting to the chart every bar with a different day in your first example. Since the 'id' is the same, it overwrites the previous bar's date with the most current. In the second example, you are doing the same thing, except you are overwriting the output every 'day 5'.

    Comment

    Working...
    X