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 corman, Today, 02:02 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Uregon, Today, 12:12 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by kerplunk1899, Today, 10:03 AM
      1 response
      18 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by rexsole, Today, 10:20 AM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_RyanS  
      Started by pjsmith, Today, 03:01 AM
      6 responses
      17 views
      0 likes
      Last Post bltdavid  
      Working...
      X