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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        89 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X