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

date time question

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

    date time question

    Hi,

    I'd like to try to get volume of the same bar of yesterday's session using this piece of code:

    TimeSpan oneday = new TimeSpan(24, 00, 00);

    Print("\n" + Time[0].ToString());
    int barsAgo1 = Bars.GetBar(Time[0].Subtract(oneday));
    Print(Time[barsAgo1].ToString() +" " + Volume[barsAgo1].ToString());


    the output, that gets produced puzzles me a bit. It's the volume of the bar, but two weeks ago.

    13/04/2020 18:35:00
    30/03/2020 18:35:00 11201

    13/04/2020 18:40:00
    30/03/2020 18:40:00 8834

    13/04/2020 18:45:00
    30/03/2020 18:45:00 6992

    Any ideas, what is wrong?

    Many thanks.

    Thomas


    #2
    My guess would be
    Code:
    int barsAgo1 = CurrentBar - Bars.GetBar(Time[0].Subtract(oneday));

    Comment


      #3
      Hello td_910,

      Thank you for your patience.

      MojoJojo is right on the money here, you need to subtract the bar index of the bar you want from the bar index of the current bar to get its BarsAgo value to be used in getting the time and volume.

      Here's how I'd do this rather than setting up a new TimeSpan, although that works as well:

      Code:
                  DateTime onedayago = Time[0].AddDays(-1);
                  Print("\n" + Time[0].ToString() + " " + Volume[0].ToString()); 
                  int barsAgo1 = CurrentBar - Bars.GetBar(onedayago);
                  Print(Time[barsAgo1].ToString() +" " + Volume[barsAgo1].ToString());
      Please let us know if we may be of further assistance to you.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        Thanks for that. I must have been blind

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by merc410, Today, 03:41 AM
        4 responses
        27 views
        0 likes
        Last Post merc410
        by merc410
         
        Started by Graci117, Yesterday, 11:40 PM
        2 responses
        15 views
        0 likes
        Last Post Graci117  
        Started by Taddypole, Today, 02:25 PM
        0 responses
        1 view
        0 likes
        Last Post Taddypole  
        Started by ETFVoyageur, 04-30-2024, 02:04 PM
        9 responses
        56 views
        0 likes
        Last Post ETFVoyageur  
        Started by Felix Reichert, 04-26-2024, 02:12 PM
        8 responses
        48 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X