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

Strategy Fills at Wrong Price for Market Replay

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

    Strategy Fills at Wrong Price for Market Replay

    We were having trouble with fills when running a strategy with market replay.

    The fills were happening at prices which were outside the limits of the bar that they allegedly occurred on (i.e., an order filled at a price above the High or below the Low of the bar.)

    I tried running market replay with SampleMACrossover and found that the problem occurs there, too. I added the strategy to a 150-tick timeframe chart, and here's an example of where it fails:



    I tried this on two different computer systems and it happens on both of them.

    I also wondered if maybe there was a problem with running the market replay at 500X speed, so I tried it at 1X and it still messes up (in fact the above screen-shot was done after running SampleMACrossover at 1X.)

    Note that both the stop-loss order to close a trade and the immediately subsequent buy order to open a new position both filled 2-ticks below the Low of the bar.

    I notice the uncanny resemblance to a bug that I reported in Ninja 6.0 back in Oct 2007 (see: http://www.ninjatrader.com/support/f...86&postcount=4) but that problem was related to backtesting (and seems to remain nicely fixed) whereas this one is with the market analyzer (and sadly is stopping me from having any fun right now.)
    Attached Files

    #2
    KBJ, is the chart you're using based on the last? If so you see the fills at the bid / ask which can lie outside of the bars based on the 'last' price.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Guys,

      My fills are exactly the same as KBJs...the entries are based on firsttickofbar and exits high/lo triggers.

      Regards

      Kay Wai

      Comment


        #4
        Kay Wai, KBJ, when running a strategy on Market Replay, orders are filled at the bid or ask. The chart says 150T, which is based off close data. Thus, your orders are being filled at a more realistic price than if you were just running a backtest on it - the buys are hitting the ask and the sells are hitting the bid.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Austin View Post
          Kay Wai, KBJ, when running a strategy on Market Replay, orders are filled at the bid or ask. The chart says 150T, which is based off close data. Thus, your orders are being filled at a more realistic price than if you were just running a backtest on it - the buys are hitting the ask and the sells are hitting the bid.
          Austin...

          We've done lots of live trading (Sim or with a cash account) and one of our traders does several-hours of replay trading a week on the SuperDOM.. We've have never seen this type of behavior on either Sim/Live$/Replay trading on the SuperDOM. So are you saying that the fills for NinjaScript strategies are always based off of bid/ask quotes? I guess that would explain what we're seeing.

          There is a bug with loading a strategy on a chart here, however ... it seems to gratuitously change the data series period for me.

          Here's the data series before I load the strategy on the chart...



          And here's what happens right after I add the SampleMACrossover strategy to the chart:



          Here's what the chart looks like -- you can see where I added the strategy as the bars go from 150-tick to 1-second right on the screen...


          Note that it says "Second" on the top line of the chart (in spite of the fact that it says "150 Tick" just below that. And you can see that the character of the chart changes after the middle of the chart, so it looks more like a 1-Second chart than a 150-Tick chart.
          Attached Files
          Last edited by KBJ; 07-05-2011, 12:02 PM.

          Comment


            #6
            You can see executions misplaced from bars if there are multiple bars with the same time stamp. Since there are many bars with the same timestamp, NinjaTrader can only plot the trade execution on the first bar with the same timestamp of the execution since the executions are not tied to specific bars, but tied to specific timestamps. This can appear as if the trade execution occurred with an invalid fill price, but in reality the execution did occur on a valid price, just on a later bar with the same timestamp.


            I would look into why you are seeing that effect, with seconds listed on the title bar, but not the chart toolbar. Do you happen to use a script called connection monitor? This was reported by a couple of users as changing intervals. It's not possible to do this with supported code, but Initialize() is called for all scripts and this one was changing interval even when it wasn't actively used. It may be worthwhile creating a new chart completely and isolating other scripts you may have installed.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_RyanM View Post
              Do you happen to use a script called connection monitor? This was reported by a couple of users as changing intervals. It's not possible to do this with supported code, but Initialize() is called for all scripts and this one was changing interval even when it wasn't actively used.
              Ryan, thanks ... turns out I had downloaded a strategy called ConnectionMonitor and as you mentioned it had code In Initialize() that was setting "BarsPeriod.Value = 1" and "BarsPeriod.Id = PeriodType.Second". When I commented out both of these lines (with "//") and recompiled, the problem went away.

              A design idea...

              So how about asking development to do something about this "feature" of the Initialize method, so that these items in un-invoked indicators and strategies cannot affect the running of the software until they're explicitly loaded (and/or enabled for strategies)?

              By the way, I really liked that the OnStartUp method was created, and what I'm suggesting is a bit "more of the same"... i.e., if there are things that must be done for all indicators/strategies regardless of whether loaded/enabled or not, then how about defining a new method where they could live (my suggested name would be OnLoading or something like that) and then only call Initialize if an indicator/strategy actually is being selected/loaded/enabled?

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              3 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Working...
              X