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

How to Calculate TimeSpan... For Higher Time Frame Bars CurrentBars[1] ...?

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

    How to Calculate TimeSpan... For Higher Time Frame Bars CurrentBars[1] ...?

    Hi,

    I'm trying to Create a BAR TIMER for NT7 for Higher Time Frame Bars, Add(PeriodType.Custom5, period_HTF), Unirenko Bar Type.

    I have tried the Following, to calculate the TimeSpan, to no avail, using Both CQG and Simulated Data Feeds:

    TimeSpan dynamicTimerElapsedTimeTS_HTF = DateTime.Now - Bars.GetTime(CurrentBars[1] -1);

    TimeSpan dynamicTimerElapsedTimeTS_HTF = BarsArray[1].GetBar(Times[1][1]) - BarsArray[1].GetBar(Times[0][0]);

    TimeSpan dynamicTimerElapsedTimeTS_HTF = Bars.GetTime(BarsArray[1].GetBar(Times[1][1])) - Bars.GetTime(BarsArray[1].GetBar(Times[0][0]));

    Could you please help me figure this part out?

    Thank You in Advance...

    Joe

    P.S. This works for a Lower Chart Time Frame TIMER:

    TimeSpan dynamicTimerElapsedTimeTS_LTF = DateTime.Now - Bars.GetTime(CurrentBar -1);

    #2
    Hello jmca2000,

    Thanks for your post.

    To be able to add UniRenko bars you have to specify 3 parameters in one such as Add(PeriodType.Custom5, 004012004); Where 004 = Tick Trend, 012 = Tick Reversal, 004 = open offset (for a Unirenko bar of T4R12O4.

    Does your parameter period_HTF provide that type of value?



    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      Thank You for your response...

      I Know You Need to add "Add(PeriodType.Custom5, 004012004)"

      I USE: private int period_HTF = 010060001; and Add(PeriodType.Custom5, period_HTF);

      And

      [Description("HTF Chart Period, If PERIOD IS 7 DIGITS LONG (Example TRRROOO → 6012001 → 6-Trend, 12-Reversal, 1-Offset), " +
      "If PERIOD IS 8 DIGITS LONG (Example TTRRROOO → 12048001 → 12-Trend, 48-Reversal, 1-Offset)")]
      [Category("1) HTF - Bar Marker Settings")]
      [Gui.Design.DisplayName ("002. HTF Period → → → → → → → → → →")]
      public int Period_HTF
      {
      get { return period_HTF; }
      set { period_HTF = Math.Max(1, value); }
      }

      It WORKs Fine...

      --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      That's NOT my Question...

      I can Not figure out how to determine what the TIME DIFFERENCE is Between 2 Higher Time Frame Bars Using: NinjaTrader7?
      Example: BarsArray[1][0] & BarsArray[1][1] ...??? or DateTime.Now & BarsArray[1][1] ...???


      The Lower TimeFrame Bar # is 10915 ( BarsArray[0][0] ).

      The Higher TimeFrame Bar # is 1862 ( BarsArray[1][1] ).

      The Higher TimeFrame Bar # is 1863 ( BarsArray[1][0] ).



      TimeSpan elapsedTime = DateTime.Now - BarsArray[1][1].Time; <---- Does NOT Work, *** (See Original Post code I tried)

      TimeSpan elapsedTime = DateTime.Now - ?????? <---- What is the Correct Code that I should Use...???????????????


      and/or


      TimeSpan elapsedTime = BarsArray[1][0].Time - BarsArray[1][1].Time; <---- Does NOT Work, *** (See Original Post )

      TimeSpan elapsedTime = ?????? - ??????; <---- What is the Correct Code that I should Use...??????????????????????



      Please Help...
      Thank You...
      Joe
      Last edited by jmca2000; 04-15-2020, 08:51 PM.

      Comment


        #4
        If you're using Times[1][0] or Times[1][1] -- that should be enough.

        I mean, don't use BarsArray, it is not needed.

        Are you wanting the total time the bar took to build?
        Code:
        TimeSpan elapsedTime = Time[0] - Time[1];
        This tells you how long the current HTF bar has been alive,
        Code:
        TimeSpan elaspedTime = Time[0] - Times[1][1];
        Remember, Times[1][1] is the time of when the previous HTF bar closed,
        but it is also the start time of the next HTF bar after it.

        Comment


          #5
          THANK YOU bltdavid...!!!

          Just the information that I needed, Excellent Explanations and Code Examples...

          Thanks Again Joe...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by arvidvanstaey, Today, 02:19 PM
          0 responses
          3 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by mmckinnm, Today, 01:34 PM
          3 responses
          5 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by f.saeidi, Today, 01:32 PM
          2 responses
          6 views
          0 likes
          Last Post f.saeidi  
          Started by alifarahani, 04-19-2024, 09:40 AM
          9 responses
          55 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Conceptzx, 10-11-2022, 06:38 AM
          3 responses
          60 views
          0 likes
          Last Post NinjaTrader_SeanH  
          Working...
          X