Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Missing trades with multiple strategy instances in Market Replay

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

    Missing trades with multiple strategy instances in Market Replay

    I am having difficulty running multiple strategies in Market Replay mode. Each strategy instance is identical except that it is run on a different (and only one) instrument. Each strategy runs on one minute bars.

    My strategies do not hit the entry and exit conditions consistently. It seems that (rerunning the same day over and over again), some strategies place entry and exit orders when run alone, but fail to do so when running simultaneously with as few as three other strategy instances (instruments).

    It appears that when I run multiple strategies, perhaps some of the ticks in the data stream do not get processed by OnBarUpdate(). Does that sound plausible? Is there a way to find out whether that is happening in real time?

    I initially suspected that it might be a matter of the ticks arriving faster than the computer could process them, so that some of them are just ignored. But, I ran a set of four stocks (strategy instances) for a day of Market Replay data at both 500X and 50X speed and I got exactly the same results at both speeds. However, both of those times, the results were missing entries and exits for two of the stocks. If I run those two stocks together (without the other two) at 500X speed, the previously missing entries and exits are executed correctly.

    Is this likely to happen in real-time trading? If so, how many strategies could I likely run simultaneously?

    Do you have any suggestions?

    I would greatly appreciate any help you can give me.

    #2
    rmt81,

    In could likely be an issue with BarsInProgress. By default, the primary data series will be called OnBarUpdate unless you specify to check that the BarsInProgress are another data series. Using BarsInProgress = 0 would specify to check the primary series, BIP = 1 would be the 2nd data series and so on.

    Please review our Help Guide article on 'True Event Driven OnBarUpdate() Method' for more information:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Missing trades with multiple strategy instances in Market Replay

      I must not have explained the situation clearly enough.

      There is only one instrument per strategy instance. This is not a multi-instrument strategy. As I understand it, each of these strategy instances is independent, so BarsInProgress should not be an issue. I am getting executions of up to three different instruments, each running in a different strategy instance.

      I have read the help on multi-instrument strategies multiple times. That approach has it’s own set of complicating factors. NT makes it unnecessarily complicated to load an instrument list. Perhaps changing to a multi-instrument strategy would solve my problem, but my suspicion is that if I am having trouble with this simpler implementation, the multi-instrument strategy will just be a nightmare.

      Originally posted by NinjaTrader_Matthew View Post
      rmt81,

      In could likely be an issue with BarsInProgress. By default, the primary data series will be called OnBarUpdate unless you specify to check that the BarsInProgress are another data series. Using BarsInProgress = 0 would specify to check the primary series, BIP = 1 would be the 2nd data series and so on.

      Please review our Help Guide article on 'True Event Driven OnBarUpdate() Method' for more information:

      http://www.ninjatrader.com/support/h...nstruments.htm

      Comment


        #4
        Hello,

        Thanks for the clarification - you're correct that BIP wouldn't count here.

        Just so we're on the same page, you are saying you can run Strategy A against symbol Y and it works as expected, however if you run Strategy A against symbol X, Y and Z at the same time, it doesn't behave the same?

        Was this replay data recorded from a live connection or downloaded from our replay servers?
        MatthewNinjaTrader Product Management

        Comment


          #5
          Missing trades with multiple strategy instances in Market Replay

          Matthew:

          You are correct. The more strategy instances I have running simultaneously, the lower the percentage of trades that are executed. If I run 500 simultaneously, I enter positions, but never exit them (perhaps because only of low percentage of the total data is processed).

          The replay data was recorded from a live connection to TDA.


          Originally posted by NinjaTrader_Matthew View Post
          Hello,

          Thanks for the clarification - you're correct that BIP wouldn't count here.

          Just so we're on the same page, you are saying you can run Strategy A against symbol Y and it works as expected, however if you run Strategy A against symbol X, Y and Z at the same time, it doesn't behave the same?

          Was this replay data recorded from a live connection or downloaded from our replay servers?

          Comment


            #6
            rmt81,

            If you're running 500 instruments, it may be due to perfromance issues. This is a lot of information to be pulled from your hard drive at one time. This would be in line with your original question on whether or not it was not processing all the ticks. I'm not sure exactly where the bottle neck would be in regards to replay, but you may want to try exponentially reducing the number of instruments at a time to see if you can gauge a benchmark for your PC.

            Have you tried running these live? In a live enviornment, the ticks are going to come in from your internet connection and processed by your CPU only for the strategies. There would be no direct reading from the disk and I wouldn't suspect you would see the same issues.
            MatthewNinjaTrader Product Management

            Comment


              #7
              Matthew:

              Yes, I have reduced the number of instruments running simultaneously.

              As indicated in my original post, when I reduce it to two instruments, as far as I know, I am getting all the data and I get three trades entered and exited. But, if I increase it to four instruments, then only one of the previously described three trade pairs execute, although one enter/exit trade pair executes for each of the two additonal instruments.

              So, the problem clearly occurs running what seems to me to be a very small number of instruments.

              The reference to running 500 instruments (which seems to me a minimum number for a real practical application) was simply to illustrate that the problem gets worse with many more instruments. In that case, positions were entered, but never exited, suggesting that with so many stocks to choose from, there was almost always one with conditions available to go in, but that when the conditions were right to exit, the probability was too low for the data being there for the particular stock that I was long in.

              If I tried running it live, how would I ever know whether I was missing data and/or trades or not? I am not confident that the data recorder would catch all the ticks if my strategy is too busy to catch all of them.

              Also, as I mentioned in my original post, I lose exactly the same trades whether I playback at 500X or 50X; this suggests it is not just a performance bottleneck.

              I am running the strategy on 1 minute bars, but if I understand correctly, the data is still coming in tick by tick. Is there a way I could instruct a strategy to request live data only as 1 minute bars to reduce the bandwith per instrument?

              Thanks

              Originally posted by NinjaTrader_Matthew View Post
              rmt81,

              If you're running 500 instruments, it may be due to perfromance issues. This is a lot of information to be pulled from your hard drive at one time. This would be in line with your original question on whether or not it was not processing all the ticks. I'm not sure exactly where the bottle neck would be in regards to replay, but you may want to try exponentially reducing the number of instruments at a time to see if you can gauge a benchmark for your PC.

              Have you tried running these live? In a live enviornment, the ticks are going to come in from your internet connection and processed by your CPU only for the strategies. There would be no direct reading from the disk and I wouldn't suspect you would see the same issues.

              Comment


                #8
                Originally posted by rmt81 View Post
                Matthew:

                I am running the strategy on 1 minute bars, but if I understand correctly, the data is still coming in tick by tick. Is there a way I could instruct a strategy to request live data only as 1 minute bars to reduce the bandwith per instrument?

                Thanks
                You can use CalulateOnBarClose = true which will prevent OnBarUpdate from being called until the 1 minute bar has closed.

                You can also program the strategy to only update when needed:
                Strategy: Separating logic to either calculate once on bar close or on every tick -


                I'd like to look into this a bit further however - does this only happen on the custom strategy you have developed? I've been running tests on replay for a basket of futures instruments and the SampleMACrossOver strategy and do not see any discrepancies. As a test, would you be able to run your replay data against this default strategy to see if you can reproduce?
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Matthew:

                  I have not yet had time to run the test you suggested.

                  However, I was running with CalulateOnBarClose = true, both in the new strategy dialog and in Initialize().

                  Am I correct that if CalulateOnBarClose in Initialize() is set, it overrides the setting from the dialog?

                  Thanks for your help. I will let you know when I run the test.



                  Originally posted by NinjaTrader_Matthew View Post
                  You can use CalulateOnBarClose = true which will prevent OnBarUpdate from being called until the 1 minute bar has closed.

                  You can also program the strategy to only update when needed:
                  Strategy: Separating logic to either calculate once on bar close or on every tick -


                  I'd like to look into this a bit further however - does this only happen on the custom strategy you have developed? I've been running tests on replay for a basket of futures instruments and the SampleMACrossOver strategy and do not see any discrepancies. As a test, would you be able to run your replay data against this default strategy to see if you can reproduce?

                  Comment


                    #10
                    Originally posted by rmt81 View Post
                    Matthew:
                    Am I correct that if CalulateOnBarClose in Initialize() is set, it overrides the setting from the dialog?
                    Actually, the Dialog will over ride the Initialize property.

                    If the Initialize() was set to false, but the dialog was set to true, the script would be working COBC True.
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      So what is the point of setting it in the code, if the dialog will always set it anyway?


                      Originally posted by NinjaTrader_Matthew View Post
                      Actually, the Dialog will over ride the Initialize property.

                      If the Initialize() was set to false, but the dialog was set to true, the script would be working COBC True.

                      Comment


                        #12
                        Hello rmt81,

                        Setting by code will set the initial value loaded, so mainly for convenience.
                        Ryan M.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by judysamnt7, 03-13-2023, 09:11 AM
                        4 responses
                        59 views
                        0 likes
                        Last Post DynamicTest  
                        Started by ScottWalsh, Today, 06:52 PM
                        4 responses
                        36 views
                        0 likes
                        Last Post ScottWalsh  
                        Started by olisav57, Today, 07:39 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post olisav57  
                        Started by trilliantrader, Today, 03:01 PM
                        2 responses
                        21 views
                        0 likes
                        Last Post helpwanted  
                        Started by cre8able, Today, 07:24 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post cre8able  
                        Working...
                        X