Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reload of Bars - Strategy Missed a Trade

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

    Reload of Bars - Strategy Missed a Trade

    I have a strategy that fires every 5 or 15 minute bars. Today, an indicator I wrote was showing on the chart, but the strategy, which buys/sells based on that indicator, did not fire a trade. It wasn't until I disabled the strategy and re-enabled that it saw the trade.

    The strategy had been running since last night. This has occurred a few times before. My concern is why at times, does the strategy not take action, but does AFTER I re-enable it?

    Is there a way that I can reload the Bars[0] array from the database every BarUpdate before I process the strategy in the OnBarUpdate method?

    I'm at a loss as to how to handle this and to trust that the strategy is taking the trades it should. This was a large profitable trade it missed today.

    Thanks
    John

    #2
    Hi John,

    This could be due to expected differences when running a strategy historically versus live:


    Reloading a strategy means bars that were previously real time are now historical, and leads to different behavior and possibly different sequences. You just can't compare historical and real time strategies.

    What you'll need to do is debug your strategy thoroughly in a live environment so you can be confident of its mechanics. Market replay is good to simulate how your strategy performs live. If you have the data available, run your strategy against today's market replay. This gives you another opportunity to check all values and confirm expected behavior of your strategy in a (simulated) live environment.

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan,

      I downloaded the replay data for today. It took the trades as it should have. So, replay got it. A restart of the strategy got it. Strategy Analyzer got it. Why didn't live get it?

      I have extremely detailed trace files that we use to monitor the action of the strategy. If you would like to compare these results, you will notice that the one trace didn't get the indicator to take the trade, while all the other trace files did.

      Again, how can I be certain Ninja is reading the bars correctly? Why is it that after restarting the strategy, it then tries to synchronize the strategy? Is there a way to reload the internal bar array so that the strategy will pass that bar array to my indicators properly? Its not happening all the time, but puts doubts of whether this strategy can be run reliably, even if I'm sitting here watching it.

      Comment


        #4
        Same strategy - same situation AGAIN. Another trade not taken while running live...but was there AFTER I restarted the strategy.

        I'm going back to version .6 to see if it helps.

        Comment


          #5
          The only way to track what your strategy is doing live is debug it with Print() statements and TraceOrders output. The existing output you have will be good to look at if there is any information related to order submission. It will show if an order is ignored, cancelled, rejected. If the strategy never got to order submission, then trace output won't show why a signal wasn't taken.

          Again, how can I be certain Ninja is reading the bars correctly? Why is it that after restarting the strategy, it then tries to synchronize the strategy? Is there a way to reload the internal bar array so that the strategy will pass that bar array to my indicators properly?
          All the indicator loading and bar reading is transparent to you. You access indicator values in your strategy script and it makes the calculations using available bars. You can check values of the indicators used in your conditions by printing and checking output in Tools > Output Window. The details for strategy syncing depend on interaction of a couple settings and are described here:


          If it's possible to isolate this to a reproducible scenario, we can see what's happening here and correct any issue. We appreciate any efforts you can make so that we are able to see evidence of an issue here.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Ryan,

            The running Strategy is NOT executing the trade because I am not getting a valid result from an indicator. I pass the Bars[0] to another indicator and if that indicator there is a buy or sell flag, then it continues to execute the trade. However, my trace does NOT show that the indicator returned with a valid buy/sell signal. The only reason it wouldn't do that is because it didn't see the setup based on that indicator code. That leads me to believe that the live data is not getting updated properly or something else.

            Which comes back again as to why does it work AFTER I re-enable the strategy - even a few minutes later? Wouldn't that suggest there is something going on with the data bars?

            What would you like from me? I can email you our detail trace files (what you call Print statements) and I will show you where it takes it after the re-enabling of the strategy.

            Comment


              #7
              Scripts function differently on real time compared to historical data. Because these are two different environments, it is not necessarily unusual to see different results here. In one instance it's running real time and in another it's historical. These are different environments, so can't expect same results. In addition to expected differences here with script mechanics, it could point to improper coding with your indicator / strategy where it runs fine historically but not real time.

              It's great that you pinpointed the issue to an incorrect real time value by the indicator, as you now have something you can debug and fix. Unfortunately it's not possible for us to know what exactly is happening with your scripts. You will need to simplify and debug until everything works as you expect. If you get to a point where you just can't follow the strategies behavior, please post a simplified script and steps so that we can see the same thing here.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Ryan,

                You are missing the point here. There is nothing wrong with my code. If there was a problem, I would see inconsistent results between Strategy Analyzer, Replay, and RESTARTING the strategy. All those are consistent - that they take the trade when they are supposed to. Why is that *sometimes* running live, its not?

                What do you mean "Because these are two different environments, it is not necessarily unusual to see different results here"? I expect that when I load the strategy, it loads the Bars[0] data from historical data and current live feed data. Then, the strategy is running and adding live data to the Bars[0] array,right? We have our strategy running on BarClose=True - which means, it runs at the close of that bar, not intra-bar - on 5 or 15min bars.

                Now, 5 minutes later, I stop the strategy, I restart it, the previous bar that was a live feed bar is historical. Please explain how those two environments are different? Shouldn't the bar values be the same? Shouldn't that Bars[0] array be injected into my indicator produce the same result?

                Which goes back to my original point - how do I know if the Bars[0] value is correct? Do I have to trace out the last 20 bar highs and lows so I can compare it when it doesn't work?

                It would be helpful to know what exactly you guys do internally to populate the Bars[0] array. Why is that I can't ask to have it reloaded from historical data in code - when the only time it appears you touch it is IF I restart the strategy OR perhaps when a connection is lost/re-established? Or is it?

                I have to trust that the strategy running live will match my strategy analyzer results, market replay, and when I restart a strategy - otherwise, what's the point of using your software? That means I can't rely on your test results in a live environment.

                Its just frustrating as we continue to struggle with this issue. This has to be our second or third posting about this over the last 6 months and according to the history in the forum, this has been an issue since 2008.

                We have tried all your other requests. We have tested this problem on CQG, Zen, using Kenetick real-time data. We have all our charts open for the same time periods we trade so that the data feeds are refreshing properly.

                Just to give you an idea, our strategy and indicator code is nearing 10K lines of code.

                Please help us find a solution. What can I provide you to help us resolve this problem? Could you assign this to a developer so I can work with them directly?

                Comment


                  #9
                  Just FYI:

                  1) I am back on 64bit, 7.0.1000.6
                  2) I am tracing now in my file the following in the OnBarUpdate routine.

                  Strategy - 0: 8/25/2011 5:30:00 PM [1.0444]: Bar Data: Low:1.0444; High:1.0454; Open:1.045; Close:1.0444

                  Comment


                    #10
                    This is how I understand your issue:

                    You run a strategy live and do not see a trade take place. You then reapply the same strategy to historical data for the same period and this time you see a trade. Please let me know if there is not accurate.

                    Which goes back to my original point - how do I know if the Bars[0] value is correct?
                    Do I have to trace out the last 20 bar highs and lows so I can compare it when it doesn't work?
                    Sorry, I'm not sure from your description here what you are actually doing in code. There isn't much we can offer here until we are able to see exactly what is taking place. We cannot offer guesses at the situation.

                    I have to trust that the strategy running live will match my strategy analyzer results, market replay, and when I restart a strategy
                    You should not expect this and is why I have emphasized several times that these are different environments. We have a dedicated help guide article for why you can see discrepancies in your strategy real time compared to a backtest. Consider backtest = historical or what happens after you reload a strategy that was previously running real time. We cannot advance this issue further if your only claim is that real time should equal historical.

                    If there is an issue with NinjaTrader here, we will need it broken down to a simplified script and reproducible steps so that we can see what you're facing here.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Ryan,

                      When I'm monitoring this, sometimes I will see the setup on the chart. I will look at the running strategy and see that it didn't take the trade. I could run the strategy analyzer and see it real-time take the trade after the bar is complete. If I uncheck Enabled on the strategy, then click it again, then I get my virtual trade and real stop orders.

                      I would expect that my fill price would be different, but I don't expect that if I have a strategy, that takes a trade in analyzer, replay, and re-enabling the strategy, but doesn't work live?

                      Looking at your discrepancies document, I agree:
                      1) Fill order would be different - meaning, the actual fill price could be different than backtest, that makes sense.
                      2) I'm am using a 5 minute or 15 minute bar. Shouldn't the OHLC be the same if its live or historical? Or are you saying that CQG's historical data is different than the data feed they send me live?
                      3) The strategy is running based on Minute bars not tick. Its also running at the close of that bar.

                      Is it possible for you to explain how/when you load the bar data internally? When does it get refreshed, if at all? What happens if I reload a chart historical data, does the strategy see it immediately, or, do I have to start/stop the strategy for it to see the new historical data? If not, what was the point of having the chart open all the time?

                      Also, if you are telling me that the historical data will always be different than live - then why don't we have the option, in OnBarUpdate, to reload historical data BEFORE I process code? That way, it would match my backtesting results.

                      Comment


                        #12
                        Independent of the data values, the mechanics of strategies and scripts are different real time compared to historically. This difference is amplified if running your strategy with CalculateOnBarClose = false. This still doesn't mean that a real time COBC = true strategy will produce identical results when run historically.

                        Shouldn't the OHLC be the same if its live or historical? Or are you saying that CQG's historical data is different than the data feed they send me live?
                        Data can be different after a reload. Please see here and then the section Understanding why a chart can look different after reloading historical data from the server


                        Is it possible for you to explain how/when you load the bar data internally? When does it get refreshed, if at all?
                        Yes, see here and then the section When does NinjaTrader load historical data?


                        What happens if I reload a chart historical data, does the strategy see it immediately, or, do I have to start/stop the strategy for it to see the new historical data?
                        Your strategy is reloaded completely, and is run against all available historical data. It creates an entirely new strategy instance and there is a warning of this before you reload data while a strategy is applied.

                        Also, if you are telling me that the historical data will always be different than live - then why don't we have the option, in OnBarUpdate, to reload historical data BEFORE I process code?
                        When you run the strategy, it's run against all available historical data. Making data requests and running a strategy are two independent functions in the software. If you want to reload historical data just prior to starting the strategy, you can do this, but is not supported through code.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Here is the crux of what I need to know based on your quote.

                          Originally posted by NinjaTrader_RyanM View Post
                          Your strategy is reloaded completely, and is run against all available historical data. It creates an entirely new strategy instance and there is a warning of this before you reload data while a strategy is applied.
                          .
                          You state the running strategy under the Strategies tab is completely reloaded IF I right-click over a chart and select Reload All Historical Data?

                          If so, a few questions:

                          1) I've only seen it ask me maybe once that I have a running strategy and to be aware of the reload. But, right now, I can reload the same period charts (with the strategy on the chart or not) - and it doesn't warn me.

                          2) What exactly is reloaded? Reason I ask is when I look at my trace files, I don't see the trace showing that it re-ran through all the historical bars again - otherwise, I would see "Print" statements for all my debug code showing that it had been reloaded. Again, what is reloaded?

                          Comment


                            #14
                            Hello,

                            You must be running your strategy on the chart and have the strategy to be enabled for it to give you the warning. In this case I don't think the strategy was running in the chart when you reloaded or you did not have it enabled for it did not rerun.

                            Otherwise you would get the warning and if you have any Print() or tracing you output would show up as the strategy re runs on historical.

                            If you start the strategy on the strategies tab it would not affect this strategy when you reload historical data on the chart.

                            Let me know if I can be of further assistance.

                            Comment


                              #15
                              Originally posted by NinjaTrader_Brett View Post
                              Hello,

                              You must be running your strategy on the chart and have the strategy to be enabled for it to give you the warning. In this case I don't think the strategy was running in the chart when you reloaded or you did not have it enabled for it did not rerun.

                              Otherwise you would get the warning and if you have any Print() or tracing you output would show up as the strategy re runs on historical.

                              If you start the strategy on the strategies tab it would not affect this strategy when you reload historical data on the chart.

                              Let me know if I can be of further assistance.
                              Ok, I may have had this confused.

                              1) If I just run the strategy by adding it myself to the strategies tab, will it keep up with the live data feed? I know it does most of the time.

                              2) Is it better to run the strategy from a chart or adding manually to the strategy tab? Which is recommended?

                              I have been running this directly from the strategy AND keeping a chart open for each time period. But, like I have been trying to resolve, how do the internal bars get updated? If it is better to run from a chart and not directly from the strategies tab, that may explain some of the odd behavior.

                              Can you clarify that? I really need to know how this is supposed to behave.

                              Thanks Brett.

                              J

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, 02-11-2023, 05:43 PM
                              3 responses
                              234 views
                              0 likes
                              Last Post rhubear
                              by rhubear
                               
                              Started by frslvr, 04-11-2024, 07:26 AM
                              8 responses
                              112 views
                              1 like
                              Last Post NinjaTrader_BrandonH  
                              Started by stafe, 04-15-2024, 08:34 PM
                              10 responses
                              44 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by rocketman7, Today, 09:41 AM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by traderqz, Today, 09:44 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X