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 bmartz, 03-12-2024, 06:12 AM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by Aviram Y, Today, 05:29 AM
        2 responses
        7 views
        0 likes
        Last Post Aviram Y  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by TradeForge, Today, 02:09 AM
        1 response
        23 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X