Announcement

Collapse
No announcement yet.

Possible Date function bug?

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

  • Possible Date function bug?

    I created a formula so I could show a graph with all green bars or red bars from one date to another. It works fine except for a few dates when I want to switch the bar colors on the beginning of some months. It doesn't happen for every month. I've included my code and removed most of the dates so it's easier to debug. In this formula, I want the green bars to start on April 1st, 2009 but instead it starts on March 31st, 2009. I do the same thing for July 1st but it works fine in July, the green bars start on July 1st. The same problem occurs on Sept 1st, 2009, the green bars start on Aug 31st. Maybe I'm not doing something correctly in the formula. In my original code ( not included here ) I have about 50 dates and it works for all of them except on some months where it's the first day of the month.

    thanks, Todd


    var arrLongDates = new Array ( new Date(1994, 12, 22 ), new Date( 2009, 4, 1 ), new Date(2009,7,1), new Date(2009, 9, 1));

    var arrShortDates = new Array( new Date(1995,10,4), new Date( 2009, 4, 20), new Date(2009,7,20), new Date(2010, 7, 30));

    function preMain() {
    setPriceStudy(true);
    setShowCursorLabel(false);
    setColorPriceBars(true);
    setDefaultPriceBarColor( Color.blue);
    debugClear();
    }

    function main() {

    var nDay = getDay();
    var nYear = getYear();
    var nMonth = getMonth();

    var dDate = new Date( nYear, nMonth, nDay, 0, 0, 0);

    var bLong = new Boolean(false);
    var bShort = new Boolean(false);
    var lDate;
    var sDate;

    for (var i=0;i< arrLongDates.length;i++ && (bLong==false)) {
    lDate = arrLongDates[i];
    sDate = arrShortDates[i];

    if (( dDate >= lDate ) && ( dDate < sDate ))
    {
    bLong = true;
    }
    }

    if( bLong == true )
    {
    setPriceBarColor(Color.RGB(0,178,0));
    }
    else{
    setPriceBarColor(Color.red);
    }

    return;
    }

  • #2
    Re: Possible Date function bug?

    Todd
    As I see it you are passing the months incorrectly to the Date Objects (you should be able to easily verify this by running some debug statements on the elements of your arrays).
    See my reply in this thread regarding how months are numbered in the JavaScript Date Object
    Alex


    Originally posted by reedtc
    I created a formula so I could show a graph with all green bars or red bars from one date to another. It works fine except for a few dates when I want to switch the bar colors on the beginning of some months. It doesn't happen for every month. I've included my code and removed most of the dates so it's easier to debug. In this formula, I want the green bars to start on April 1st, 2009 but instead it starts on March 31st, 2009. I do the same thing for July 1st but it works fine in July, the green bars start on July 1st. The same problem occurs on Sept 1st, 2009, the green bars start on Aug 31st. Maybe I'm not doing something correctly in the formula. In my original code ( not included here ) I have about 50 dates and it works for all of them except on some months where it's the first day of the month.

    thanks, Todd


    var arrLongDates = new Array ( new Date(1994, 12, 22 ), new Date( 2009, 4, 1 ), new Date(2009,7,1), new Date(2009, 9, 1));

    var arrShortDates = new Array( new Date(1995,10,4), new Date( 2009, 4, 20), new Date(2009,7,20), new Date(2010, 7, 30));

    function preMain() {
    setPriceStudy(true);
    setShowCursorLabel(false);
    setColorPriceBars(true);
    setDefaultPriceBarColor( Color.blue);
    debugClear();
    }

    function main() {

    var nDay = getDay();
    var nYear = getYear();
    var nMonth = getMonth();

    var dDate = new Date( nYear, nMonth, nDay, 0, 0, 0);

    var bLong = new Boolean(false);
    var bShort = new Boolean(false);
    var lDate;
    var sDate;

    for (var i=0;i< arrLongDates.length;i++ && (bLong==false)) {
    lDate = arrLongDates[i];
    sDate = arrShortDates[i];

    if (( dDate >= lDate ) && ( dDate < sDate ))
    {
    bLong = true;
    }
    }

    if( bLong == true )
    {
    setPriceBarColor(Color.RGB(0,178,0));
    }
    else{
    setPriceBarColor(Color.red);
    }

    return;
    }

    Comment

    Working...
    X