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

multi time-frame getting time from one bar to another

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

    multi time-frame getting time from one bar to another

    Suppose I have a multi timeframe indicator based on 30 second (1st) and 5 min intervals (2nd) . I can use BarsInProgress == 0 or BarsInProgress == 1 within OnBarUpdate() to decide what do when the bars complete.

    Let's say, for the 30 second interval time-frame, I want to act only when a 30-second bar occurs at 4:30 min of the current on-going 5 min bar (i,e, 9th 30-second bars since the last 5 min bar).

    More specifically:

    if (BarInProgress == 0) {
    if (CurrentBar of the 30 second = 9th 30-second Bars since the last 5 min bar's close) {
    }
    }

    Any recommendations on how I can implement this: "CurrentBar of the 30 second = 9th 30-second Bars since the last 5 min bar's close" ?

    #2
    Hello uday12,

    Thank you for writing in.

    You can use a counter to keep track of how many bars have elapsed. Once the counter reaches the amount of bars you wanted to wait to close before doing other logic, you can enter into that logic.

    For example:
    Code:
    private int counter = 0;
    
    protected override void OnBarUpdate()
    {
         if (BarsInProgress == 0)
         {
              counter++;
              // check if 9 bars have elapsed
              if (counter == 9)
              {
                   // do stuff and reset counter
                   counter = 0;
              }
         }
    }
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Zachary,

      Thanks for the reply. This is exactly what I wanted.

      Best regards

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,605 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      8 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      13 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X