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

Finding the End of a secondary series WHILE on primary?

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

    Finding the End of a secondary series WHILE on primary?

    Hello.

    I have a question about MTF programming in general. And that is how to go about knowing when a secondary bar is ending, WHILE THE PRIMARY BAR that ends at the same time is still being processed?

    For example, if you have a 5 min chart as the only series, and you are using a specific template, you can use the following to find the FIRST and LAST Bars on a session respectively.
    Code:
    			if (Bars.FirstBarOfSession)	//Primary Open	
    			{
    				DrawVerticalLine("Open"+CurrentBars[0],0,Color.Orange); //Draw Open
    			}
    
    			if (Bars.LastBarOfSession)	//Primary Close	
    			{
    				DrawVerticalLine("Close"+CurrentBars[0],0,Color.Red); //Draw Open
    			}
    Now if you do MTF, you can have whatever TF/Template you want represented. So I have been doing it a somewhat roundabout way for a while. Which is to set a flag on the ending of the secondary series, so that tells me the very next bar on the primary is the open bar, after getting that point, I then clear that flag. For the end of that secondary, at the end of my onBarUpdate, I check for the closing of the secondary series. I can then reference the primary series FROM the secondary via indexing into the primary series.

    This works, but requires me to split my script up and is cumbersome.

    The way NT process the seperate series, is that it processes the primary, THEN the secondary, which occur at the same ending time. Is there a way to know that the current primary bar is the end of the secondary series? As the script technically doesn't know it's the end of the secondary, until the secondary end is processed, which happens after processing the primary?

    I have attached a simple script that shows a basic example along with an illustration.
    Attached Files

    #2
    Hello forrestang,

    Thank you for your post.

    As the primary is processing there is no function or method to find out if the secondary that has not been processed in OnBarUpdate() is the close of the session.

    You could check the timestamp of the next secondary series bar if it is a time based bar such as a 1 Minute bar. For example:
    Code:
    if (Times[1][-1] == Times[0][0])
    If it is not a time based bar and is based on ticks then the close time would not be known ahead of time.

    Comment


      #3
      Thanks so much Patrick for that solution. That is about what I was looking for.

      However for the way I am sequencing, I am using the CURRENT Secondary Close which lines up at the time that I want. So I modified your snippet and am using the following:
      Code:
      if (Times[1][0] == Times[0][0])
      I don't know why I didn't think of it at first

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ETFVoyageur, Today, 04:00 PM
      1 response
      7 views
      0 likes
      Last Post ETFVoyageur  
      Started by AaronKTradingForum, Today, 03:44 PM
      1 response
      8 views
      0 likes
      Last Post AaronKTradingForum  
      Started by Felix Reichert, 04-26-2024, 02:12 PM
      11 responses
      77 views
      0 likes
      Last Post Felix Reichert  
      Started by junkone, 04-28-2024, 02:19 PM
      7 responses
      83 views
      1 like
      Last Post junkone
      by junkone
       
      Started by pechtri, 06-22-2023, 02:31 AM
      11 responses
      139 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Working...
      X