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

backtest with OnMarketData

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

    backtest with OnMarketData

    Hi, how can I backtest strategies that based on OnMarketData event ?
    Is there any other way than with market replay ?
    If not, how can i speed up the market replay, it is a matter of CPU, Memory ? Cores ?

    Thanks
    Yan

    #2
    Hello yaniv,

    Thanks for your post.

    As stated in the OnMarketData help guide page, this is a real-time data stream and can be CPU intensive if your program code is compute-intensive.

    By default, this method is not called on historical data (backtesting), however, it can be called historically by using TickReplay.

    If used with TickReplay, please keep in mind Tick Replay ONLY replays the Last market data event, and only stores the best inside bid/ask price at the time of the last trade event. You can think of this as the equivalent of the bid/ask price at the time a trade was reported. As such, historical bid/ask market data events (i..e, bid/ask volume) DO NOT work with Tick Replay. To obtain those values, you need to use a historical bid/ask series separately from TickReplay through OnBarUpdate().


    More information can be found under Developing for Tick Replay.

    Please see this help guide page for more information about OnMarketData() - https://ninjatrader.com/support/help...marketdata.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Dear Mr. Brandon,
      Thanks for your answer, however I am not sure I understand,
      I have two questions:
      1. When using market replay, I am using the max speed playback, but the memory consumption is about 300M and the CPU is only 25%, how can I speed the market replay up ? what is the bottleneck ?
      2. I have a strategy that base OnEachTick data, there are some differences between running with market replay and with backtest with Tick Replay, why is that ?
      you can see in the attached image that at the right side (using market replay), on the 21:20 bar that the price goes up after the trade has opened, touch the stop loss price and exit the trade and in the left side (using backtest with tick replay) the trade opened almost at the same place but does not exit at 4348.75 but at the profit target few bars later, why is that ?
      Click image for larger version

Name:	Capture.JPG
Views:	237
Size:	343.5 KB
ID:	1164168
      Thanks

      Comment


        #4
        Hello yaniv,

        Thanks for your note.

        1. When using market replay, I am using the max speed playback, but the memory consumption is about 300M and the CPU is only 25%, how can I speed the market replay up ?

        There would be no way to increase the speed of Market Replay/Playback to go faster than the Max speed. Max speed for the Playback/Market Replay connection does not mean that 100% of the CPU or memory utilization will be used. Max speed simply means that there is no cap for the speed that Market Replay/Playback is running.


        2. I have a strategy that base OnEachTick data, there are some differences between running with market replay and with backtest with Tick Replay, why is that ?

        Tick Replay does not fill orders intra-bar, it only runs Calculate mode based on each tick. By default when backtesting no intra-bar granularity is added. An added 1-tick series is necessary to increase fill accuracy to within 1 tick.

        Further, TickReplay is necessary for intra-bar values to update and recalculate for on each tick or on price change Calculate setting.

        Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

        SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

        TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

        Developing for Tick Replay -
        https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

        Also, see this forum thread for more information: https://ninjatrader.com/support/foru...nce#post100192

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hi,
          What do you mean by "Tick Replay does not fill orders intra-bar", as you can see at the image above, there were trades inside the bars before the bar of 21:20

          Thanks

          Comment


            #6
            Hello yaniv,

            Thanks for your note.

            Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills.

            Tick Replay would need to be used along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar. Enabling TickReplay without adding a 1-tick series and submitting orders to that 1-tick series only allows the strategy to calculate on each tick. To have orders fill intra-bar, a 1-tick series would need to be added using AddDataSeries() and then orders would need to be submitted to that added 1-tick series. See the SampleIntraBarBacktest example script linked in my previous post.

            As far as there being differences, this could be differences between the historical tick data and the recorded market replay data. Note that market replay data will be more accurate than historical tick data.

            See the forum thread linked in my previous reply for more information.

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            12 views
            0 likes
            Last Post DanielSanMartin  
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            11 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            7 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Working...
            X