Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    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!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        2 views
        0 likes
        Last Post Rapine Heihei  
        Started by Rapine Heihei, Today, 08:19 PM
        0 responses
        1 view
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        5 views
        0 likes
        Last Post Rapine Heihei  
        Started by frslvr, 04-11-2024, 07:26 AM
        5 responses
        96 views
        1 like
        Last Post caryc123  
        Working...
        X