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 make cals AFTER all Dataseries update on 5M bars

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

    How to make cals AFTER all Dataseries update on 5M bars

    I configured 7 DataSeries for forex pairs like EURUSD, GBPUSD etc. Bars are 5 minute time based. These DataSeries update price Closes[X][0] if (BarsInProgress == X). The series update in different sequences on starting real-time strategy. No problem i expected that. But calcs on those prices need to wait till AFTER all seven DataSeries update next bar (eg the 2:40 pm 5 min bar for example). When calcs run prior to GBPUSD updating, the calcs use price from last GBPUSD bar. I have calcs update if (BarsInProgress == 0). How can i update calcs AFTER all 7 DataSeries finish for a given timestamp? Any ideas? My code is attached & commented. Thanks ninjas
    Attached Files

    #2
    Hello Kicks.Spin,

    With different instruments there is not any expectation they should have updates at similar times so any way forward for this type of goal will heavily relate to how your calculation works. A rudimentary way to do that would be to use 7 variables and set each to true from the secondary series when it gets called. Once all 7 variables are true do the action and reset them to false from BIP 0.

    If you wanted to include time as a factor you could read each series Time[0] and check if that is before or after a stored time. The stored time would be controlled by the primary BIP as an example.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for your response Jesse. I implemented your suggestion to set up 7 variables & set them true from secondary series, then reset them to false from BIP 0. But it did not work. Problem is the variables remain true from previous bar. The BIP is called and only some Close values are current. The attached code is commented and has prints demonstrating what is happening. I used common futures instruments on a 1 min time frame so you can quickly see what is happening. I don't understand how to use Time[0] as per above. I'm looking for a clever way to ensure that the BIP 0 uses Close[X][0] from the same time. Thank you (and others ninjas here) for teaching me
      Attached Files

      Comment


        #4
        Hello Kicks.Spin,

        What you described would be how variables would work in that use case. Depending on the frequency on the primary and the other instruments you may see that it takes 1 or more bars until all variables are true. The reset would need to be changed in your script to only happen if all variables are true in BIP 0, otherwise in BIP 0 when all variables are not true you would just not do the action and wait for a future bar where all are true.



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I tried to hold off execution in BIP 0 using the following conditional. But BIP executes & delivers earlier Close[x][0] prices. What specifically could be done to delay till series update.
          if ( BarsInProgress == 0 && Bars.GetTime(CurrentBar) <= Bars.GetTime(CurrentBars[1]) && Bars.GetTime(CurrentBar) <= Bars.GetTime(CurrentBars[2]) && Bars.GetTime(CurrentBar) <= Bars.GetTime(CurrentBars[3]) && Bars.GetTime(CurrentBar) <= Bars.GetTime(CurrentBars[4])
          && Bars.GetTime(CurrentBar) <= Bars.GetTime(CurrentBars[5]) && Bars.GetTime(CurrentBar) <= Bars.GetTime(CurrentBars[6]) && Bars.GetTime(CurrentBar) <= Bars.GetTime(CurrentBars[7]) )
          Attached Files

          Comment


            #6
            Hello Kicks.Spin,

            Could you provide more context on what the end goal is? If you are using multiple instruments there is no concept of waiting for all of them to close, they are all independent. If you are trying to time something based on the primary you would need to just take the last observed values from each series instead of trying to wait for them to close.



            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              if you don't mind execute this file. the BIP0 doesn't ever execute. Maybe because the conditional is not true the moment BIP0 is called. Im lost. Seems there should be a way to identify a consistent set of close prices for Close prices for last two bars? multiseriesquestion.cs

              Comment


                #8
                Hello Kicks.Spin,

                If you are not seeing the BIP 0 condition become true then you would need to print out the values of the other items you are using in the condition when you run it to find out why. You could otherwise add a print to the top of OnBarUpdate to output the BIP:

                Code:
                protected override void OnBarUpdate()
                {
                Print(BarsInProgress)
                To get the last closed price for each series you would use the plural series name like Closes and specify the bars in progress:
                Closes[1][0]
                That's the second series, 0 BarsAgo.



                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse:

                  My end goal is to receive Closes[x][0] values for the same timestamp for EUR, GBP, AUD, NZD, CHF, CAD JPY at say 10:40 am, then at 10:41 am. Then subtract the 10:40 values from 10:41 values during BIP 0. The difference is the increase/decrease in "USD Strength" over all currencies during that minute. Interesting calculation eh?. We can't just subtract whatever the last two Closes[2][0] and Closes[2][1] values in BIP 0. They have to all be 10:40's and 10:41's. They are not. That is clear from running code and watching the prints. Per your advice I tried to check for all matching Bars.GetTime(CurrentBars[X]) to enter BIP 0 calcs. But they all print as 1/1/0001 12:00:00 AM. How can these timestamps be made "visible" in BIP 0 for conditional comparison. thank you. im struggling on this one! Simplified code attached
                  Attached Files

                  Comment


                    #10
                    Hello Kicks.Spin,

                    If you want to get a bar by a specific time you would need to use the BarsArray for that series, Bars represents the primary bars.

                    BarsArray[1].GetTime
                    Alternatively you can use GetValueAt with any of the series in a similar way, for example Times[x].GetValueAt(barIndex)
                    https://ninjatrader.com/support/help...sub=GetValueAt

                    That still assumes the instruments are very similar and have similar data to drive closing bars. If we assume all the series stay in sync then you can use GetTime with the last index from that series by using CurrentBars[x]. You would need to test that with the instruments you use, you could see if that works for the use case and results in similar times.

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Jesse:

                      Thank you for that idea. I tried that. But the series do not stay in sync. So I tried to Update BarsInProgress==0 every time another Bar updates.
                      if (BarsInProgress == 1) {Update(0, 0);} // force calcs in Bar0 to update
                      if (BarsInProgress == 2) {Update(0, 0);} // force calcs in Bar0 to update
                      .
                      .
                      if (BarsInProgress == 7) {Update(0, 0);} // foprce calcs in Bar0 to update
                      Is this updating BarsInProgress ==0 each time another Bar updates? We cant control the order in which Bars update. Recalculating after each Bar should render updated values regardless of order. All this updating gets the Darwin award for inefficiency i think though. I noticed the manual said this is an advanced method for only certain cases like updating past values. So i may be misusing this. What guidance would you offer? thanks

                      Comment


                        #12
                        Hello Kicks.Spin,

                        It is important to understand here that there is no expectations that the series are in sync between different instruments. They will have update events at different times which there should not be any expectation of them happening in a specific order in realtime. Some may close at similar times which may fall in sync and others may not.

                        Update is used for external scripts to update this script in their context, for example when a strategy calls an indicator it may need to have Update called from the strategy to update the indicator. it would not be used from OnBarUpdate in the way you have shown. Calling it in that way will likely degrade performance.

                        The only ways to calculate something for multiple series at once would be to do that from a specific BarsInProgress like BIP 0. That means some values may be the most recent and some may not because there is not a point where they will all close a bar at the same time realistically.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by abctrader, Today, 06:03 PM
                        1 response
                        20 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by Liquidfusion, Today, 06:16 PM
                        0 responses
                        15 views
                        0 likes
                        Last Post Liquidfusion  
                        Started by fscabrera03, Today, 04:58 PM
                        0 responses
                        19 views
                        0 likes
                        Last Post fscabrera03  
                        Started by patpat, Today, 03:56 PM
                        1 response
                        27 views
                        0 likes
                        Last Post NinjaTrader_ShawnB  
                        Started by joselube001, Yesterday, 07:40 PM
                        1 response
                        83 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X