Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time[0] returns price?

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

    Time[0] returns price?

    huh?

    Code:
    Print(CurrentBar.ToString() + ": " + Time[0].ToString());
    returns:

    ...
    4: 11826
    5: 11833
    6: 11828
    ...

    in addition, this generates errors in the ninjascript editor:

    Code:
    int time = ToTime(Time[1]);
    cf. http://www.ninjatrader.com/support/h...nt7/totime.htm

    i'm using NT7 release 4.

    please advise how to get the timestamp of a bar. my current task is to identify the duration of a candle (when using a non-time-based bar type such as a Range bar).

    cheers,
    -e

    #2
    Hello,

    Thanks for the forum post.

    This can occur when there is no data inside of Time[0]. The close price is simply substituted.

    Can you provide full script of how your getting this so I can see where you have the Print Statement. As it needs to be inside of OnBarUpdate() etc.

    I look forward to assisting you further.
    BrettNinjaTrader Product Management

    Comment


      #3
      thanks for the quick reply.

      found my mistake; ended up setting local variables which did the trick. here is the working code:
      Code:
              protected override void OnBarUpdate()
              {
                  if (CurrentBar >= 2)
                  {
                      int time1 = ToTime(Time[1]);
                      int time2 = ToTime(Time[2]);
                      int duration = time1 - time2;
                      Duration.Set(duration);
                  }
              }
      cheers,
      -e

      Comment


        #4
        Hello,

        Thanks for posting the resolution.

        Have a great rest of the day!
        BrettNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X