Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SampleMACrossOver bug

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

    SampleMACrossOver bug

    I am running NT 7.1000.0.6 live with Ineteractive Brokers TWS 917.8. I have been running into a strange bug with the default SampleMACrossOver strategy. This reproduces itself consistently.

    The scenario: On day 1 I run SampleMACrossOver, it opens a position (say short), and closes it at the end of the day, because I have ExitOnClose = true set, and I exit 30 sec. before the close. Good so far.
    On day 2, I turn back on NT, start the strategy before the beginning of RTH, and it thinks my position never closed, so it thinks I am still short. When the next cross occurs during RTH, it will try to close the nonexistant position, and open a new long.

    What is strange is if I stop the strategy and restart it (ONLY after RTH has started - i.e., my chart in in RTH, so it is receiving current data), then the strategy realizes I am flat. If I stop/restart before RTH, it still thinks I am short.

    I am not syncing my account positions - and in fact cannot. The strategy should know that I MUST be flat after the close of the old day, and the beginning of a new day if ExitOnClose = true. In fact, when I look at the log output that starts the strategy, it is recognizing I have ExitOnClose = true. It is simply ignoring it for some unfathomable reason.

    Please help.

    #2
    Hello zstheorist,

    Thanks for the report. I was not able to reproduce this, using our market replay connection. Here's the steps to setup:
    1) Used ES and RTH session template.
    2) Downloaded replay data for 9/7/11 and 9/8/11
    3) Set the time for 3:00 AM on 9/7/11, before RTH start
    4) Applied the strategy to chart.

    I can see the historical ExitOnClose, so the strategy is flat, and then it takes the first entry signal of the 9/8/11 session. Please let me know if these are not the best steps to reproduce what you're seeing.

    It sounds like you are starting the strategy while it is in a historical position, which is very easy for the SampleMaCrossOver. This strategy has no exits except if using ExitOnClose, so is pretty much always in. When you run the strategy it should highlight yellow that it's in a waiting for flat state.

    Last edited by NinjaTrader_RyanM1; 09-09-2011, 08:46 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply. I only run this live on stocks, in particular GS, not futures. Perhaps the problem is confined to stocks? I am using GS with session template US Equities RTH.
      When run on historical data, it always exits as it should. I only see this problem in real time on live trading.
      The reason I think there is a bug is that the strategy should not ever be in a historical position when the market is closed, as I have ExitOnClose = true explicitly set under "Order Handling" in the chart window. After the market close, the position is correctly listed as flat. It is only the next morning, when I start it up again before RTH, NT thinks the position is still on. This is an impossible state to be in, as NT has been explicitly told that the position exited at the last close.
      I cannot think of a way for you to reproduce this over the weeked with the markets closed as it requires live data to trigger the problem. This has happened each of the last 6 times I've run the strategy on live data.

      Comment


        #4
        I made a suggestion regarding this, but in order to keep this thread clean, I opened a new thread: http://www.ninjatrader.com/support/f...762#post254762

        Comment


          #5
          Thanks, zstheorist. I'm setting up a test this evening to see if the same thing happens here.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            I did not encounter similar issues with this using a real time scenario and equities. I applied a strategy to MSFT chart prior to the RTH session start. The strategy was in a position the prior day, but closed due to ExitOnClose. Historical ExitOnClose for the last session does not trigger until first bar of new session, but it accepted the first entry signal of the day. Can you please upgrade NinjaTrader to the latest release 7 and let us know if you still see similar.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I will upgrade tonight. The strategy ran live on GS again today, so if this is still a problem with the newest version, I would expect it to show up tomorrow morning. I'll let you know how it went.

              Comment


                #8
                still not working

                OK, I checked both before and after upgrading to NT 7.xxx.7, and the problem is the same. In fact, it appears now any time after a trade has been been made.

                Today I traded GS long on SampleMACrossOver, and it exited before the close. The strategies window showed, that NT 7 indeed thought I was flat.
                Next, I stopped the strategy by clicking on the checkmark.
                Next, I restarted the strategy (now about 2 hours after close of RTH), and it thought I was long again.

                After upgrading, I get the same phenomenon.

                I saved the log file. It looks normal to me. Here is the line when starting this morning (when it was flat as it did not trade yesterday - note time is CST):
                9/13/2011 7:51:31 AM|1|128|Enabling NinjaScript strategy 'SampleMACrossOver/2780a5c458bc44beb0b9dc1ac520d799' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=DefaultQuantity ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes

                Result: I am flat. Later in the day I trade 300 shares. NT 7 closes me out flat 30 seconds before the close.

                When I restarted after the close:
                9/13/2011 7:40:20 PM|1|128|Enabling NinjaScript strategy 'SampleMACrossOver/2780a5c458bc44beb0b9dc1ac520d799' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=DefaultQuantity ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes

                Result: NT7 thinks I am still Long 300 shares.

                These lines look the same to me, and clearly indicate NT 7 _thinks_ I have ExitOnClose=true (which I do). Yet, when tomorrow's RTH starts up, it will not reset on the open. I have to start it AFTER the beginning of RTH for it to think I am flat.

                I will keep looking to see if there is anything else I can find, but I still cannot see how this should be logically possible.

                Comment


                  #9
                  Progress ?

                  OK, I can now reproduce this without actually trading... progress?

                  I opened a chart of B using RTH, and SampleMACrossOver with (20,200), ExitOnClose=true, and size 200 shares.
                  When I start it up (at 8:30 PM CST) it thinks I am long 200 shares even when run in the Sim 101 account. Indeed, when I look at the chart, it still has me in the trade, despite the fact RTH is over. It exited at the close on prior sessions, but not the last one.
                  So:
                  -This is independent of which account (my IB accout or Sim 101) I am running on.
                  -This does not require any actual trades to reproduce. I am just connected to my IB data feed (so I can start the strategy), and pick any stock that would have executed a trade in the prior RTH session, and when I start the strategy, NT 7 thinks I am still in the trade. i.e., it does not think it exited at the end of the last listed session.

                  I also checked on 6E 12-11 with the same settings, and exactly the same result. I tried both US Equities RTH and CME FX Futures RTH, same result.

                  NEW INFO: I checked if the result changed if I ended the chart on 9/12/11 instead of today 9/13/11. In that case it DID think I was flat.

                  Conclusion: If the current real time is after the last closed session, but before the next session open, the error occurs. There must be some other logic in NT that is skipping what happened in the last bar in this case. Could it be a 1-off error?

                  Anyway, this affects both live and simulated trading in at least NT 7.0.1000.7 and .6.

                  Now that I can reproduce this in the Sim 101 account, any suggestions?

                  Comment


                    #10
                    Hello,

                    Thanks for the forum post.

                    This is expected unfortunately since the strategy is running in historical on calculate on bar close = true we need to receive the next tick of the next bar to close the last bar out and simulate the exit on close order. Therefor this is expected, however I am checking with development to see if anything can be done in this specific case going forward and I will let you know.

                    Thanks you for checking into this.

                    Comment


                      #11
                      OK

                      Thanks for checking into it. I can understand needing another tick for it to recognize what is going on.

                      When they are checking it out, the real problem is that even when another tick comes in (i.e. the next trading session starts), that is not enough for NT to realize the trade is closed. Perhaps you've caught the issue: when the next session starts, the data is LIVE not HISTORICAL, so the next tick needed by NT to realize the historical trade is closed is not seen in the same context, and NT does not properly knit those two regimes together. That is at least a place to start.

                      Best of luck tracking this down.

                      Comment


                        #12
                        Hello,

                        I checked with development.

                        Unfortunately this is something that is simply architecturally unable to do in NinjaTrader therefor this will be expected currently.

                        Thanks for checking back in and I wish you happy trading!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by carnitron, 04-27-2024, 08:42 PM
                        1 response
                        15 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by WHICKED, 04-26-2024, 12:56 PM
                        3 responses
                        24 views
                        0 likes
                        Last Post WHICKED
                        by WHICKED
                         
                        Started by zstheorist, 04-26-2024, 07:52 PM
                        1 response
                        13 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by Touch-Ups, 04-27-2024, 10:36 AM
                        2 responses
                        21 views
                        0 likes
                        Last Post Touch-Ups  
                        Started by needsomehelp147, Today, 06:43 AM
                        0 responses
                        8 views
                        0 likes
                        Last Post needsomehelp147  
                        Working...
                        X