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

OnMarketData and OnBarUpdate values mismatch while backtesting

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

    OnMarketData and OnBarUpdate values mismatch while backtesting

    Hi.

    Don't know what happened but after removing some new code that was added we suddenly were getting different results from previous backtests while using same parameterss.
    Have checked multiple times and there was none of the original code that got removed. Also didn't do anything with the historical data that was already there. (Did do a marketdata download for a playback but that was unsuccessful, forced closed it).

    We have a strategy that has Calculate.OnBarClose and AddDataSeries(Tick, 1). The strategy uses values from indicator that uses OnEachTick, AddDataSeries(Tick, 1).
    DataSeries is FDAX / Last / Minute / 1.
    TickReplay is on.
    TimeFrame is May 24, 2020 to June 6, 2020 / Use instrument settings / Break at EOD = true

    Based on the logs, there seems to be a problem with the added Tick series. On snipped below where BIP=1 (tick series), the barUpdate values is different from marketDataUpdate values and the BIP=0.

    Attached a longer version. Also attached a strategy with just the essentials to reproduce what's in the log.

    Code:
    25/05/2020 14:10:38.147000 marketDataUpdate.Price: 11196.5
    25/05/2020 14:10:38.147000 marketDataUpdate.Price: 11196.5
    25/05/2020 14:10:49.973000 marketDataUpdate.Price: 11197
    25/05/2020 14:10:49.973000 marketDataUpdate.Price: 11197
    25/05/2020 14:10:53.467000 marketDataUpdate.Price: 11199
    25/05/2020 14:10:53.467000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:00.000000 barUpdate: BIP=0, CurBar=10, O=11200, H=11200, L=11193, C=11199
    25/05/2020 14:11:04.039000 marketDataUpdate.Price: 11197
    25/05/2020 14:10:53.467000 barUpdate: BIP=1, CurBar=703, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:04.039000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:04.159000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:04.039000 barUpdate: BIP=1, CurBar=704, O=11177, H=11177, L=11177, C=11177
    25/05/2020 14:11:04.159000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:08.416000 marketDataUpdate.Price: 11195.5
    25/05/2020 14:11:04.159000 barUpdate: BIP=1, CurBar=705, O=11177, H=11177, L=11177, C=11177
    25/05/2020 14:11:08.416000 marketDataUpdate.Price: 11195.5
    25/05/2020 14:11:13.539000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:08.416000 barUpdate: BIP=1, CurBar=706, O=11175, H=11175, L=11175, C=11175
    25/05/2020 14:11:13.539000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:16.829000 marketDataUpdate.Price: 11198
    25/05/2020 14:11:16.829000 marketDataUpdate.Price: 11198
    25/05/2020 14:11:13.539000 barUpdate: BIP=1, CurBar=707, O=11177, H=11177, L=11177, C=11177
    25/05/2020 14:11:16.829000 marketDataUpdate.Price: 11198
    25/05/2020 14:11:16.829000 barUpdate: BIP=1, CurBar=708, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:16.829000 marketDataUpdate.Price: 11198
    25/05/2020 14:11:26.405000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:16.829000 barUpdate: BIP=1, CurBar=709, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:26.405000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:31.248000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:26.405000 barUpdate: BIP=1, CurBar=710, O=11177, H=11177, L=11177, C=11177
    25/05/2020 14:11:31.248000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:31.490000 marketDataUpdate.Price: 11198
    25/05/2020 14:11:31.248000 barUpdate: BIP=1, CurBar=711, O=11177, H=11177, L=11177, C=11177
    25/05/2020 14:11:31.490000 marketDataUpdate.Price: 11198
    25/05/2020 14:11:34.058000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:31.490000 barUpdate: BIP=1, CurBar=712, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:34.058000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:38.750000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:34.058000 barUpdate: BIP=1, CurBar=713, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:38.750000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:42.172000 marketDataUpdate.Price: 11196
    25/05/2020 14:11:38.750000 barUpdate: BIP=1, CurBar=714, O=11177, H=11177, L=11177, C=11177
    25/05/2020 14:11:42.172000 marketDataUpdate.Price: 11196
    25/05/2020 14:11:43.442000 marketDataUpdate.Price: 11195.5
    25/05/2020 14:11:43.442000 marketDataUpdate.Price: 11196
    25/05/2020 14:11:42.172000 barUpdate: BIP=1, CurBar=715, O=11176, H=11176, L=11176, C=11176
    25/05/2020 14:11:43.442000 marketDataUpdate.Price: 11195.5
    25/05/2020 14:11:43.442000 barUpdate: BIP=1, CurBar=716, O=11176, H=11176, L=11176, C=11176
    25/05/2020 14:11:43.442000 marketDataUpdate.Price: 11196
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11195.5
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11196
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11196
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11195.5
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11195
    25/05/2020 14:11:43.442000 barUpdate: BIP=1, CurBar=717, O=11176, H=11176, L=11176, C=11176
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11195.5
    25/05/2020 14:11:43.443000 barUpdate: BIP=1, CurBar=718, O=11176, H=11176, L=11176, C=11176
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11196
    25/05/2020 14:11:43.443000 barUpdate: BIP=1, CurBar=719, O=11176, H=11176, L=11176, C=11176
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11196
    25/05/2020 14:11:43.443000 barUpdate: BIP=1, CurBar=720, O=11176, H=11176, L=11176, C=11176
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11195.5
    25/05/2020 14:11:43.443000 barUpdate: BIP=1, CurBar=721, O=11176, H=11176, L=11176, C=11176
    25/05/2020 14:11:43.443000 marketDataUpdate.Price: 11195
    25/05/2020 14:11:43.546000 marketDataUpdate.Price: 11196.5
    25/05/2020 14:11:43.443000 barUpdate: BIP=1, CurBar=722, O=11176, H=11176, L=11176, C=11176
    25/05/2020 14:11:43.546000 marketDataUpdate.Price: 11196.5
    25/05/2020 14:11:46.708000 marketDataUpdate.Price: 11196.5
    25/05/2020 14:11:43.546000 barUpdate: BIP=1, CurBar=723, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:46.708000 marketDataUpdate.Price: 11196.5
    25/05/2020 14:11:49.601000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:49.601000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:46.708000 barUpdate: BIP=1, CurBar=724, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:49.601000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:49.601000 barUpdate: BIP=1, CurBar=725, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:49.601000 marketDataUpdate.Price: 11197
    25/05/2020 14:11:49.684000 marketDataUpdate.Price: 11197.5
    25/05/2020 14:11:49.601000 barUpdate: BIP=1, CurBar=726, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:49.684000 marketDataUpdate.Price: 11197.5
    25/05/2020 14:11:49.945000 marketDataUpdate.Price: 11198
    25/05/2020 14:11:49.684000 barUpdate: BIP=1, CurBar=727, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:49.945000 marketDataUpdate.Price: 11198
    25/05/2020 14:11:50.701000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:49.945000 barUpdate: BIP=1, CurBar=728, O=11178, H=11178, L=11178, C=11178
    25/05/2020 14:11:50.701000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.702000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.701000 barUpdate: BIP=1, CurBar=729, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.702000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.713000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.713000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.713000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.702000 barUpdate: BIP=1, CurBar=730, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.713000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.713000 barUpdate: BIP=1, CurBar=731, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.713000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.713000 barUpdate: BIP=1, CurBar=732, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.713000 marketDataUpdate.Price: 11199
    25/05/2020 14:11:50.959000 marketDataUpdate.Price: 11199.5
    25/05/2020 14:11:50.959000 marketDataUpdate.Price: 11200
    25/05/2020 14:11:50.713000 barUpdate: BIP=1, CurBar=733, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.959000 marketDataUpdate.Price: 11199.5
    25/05/2020 14:11:50.959000 barUpdate: BIP=1, CurBar=734, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.959000 marketDataUpdate.Price: 11200
    25/05/2020 14:11:50.960000 marketDataUpdate.Price: 11200
    25/05/2020 14:11:50.959000 barUpdate: BIP=1, CurBar=735, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.960000 marketDataUpdate.Price: 11200
    25/05/2020 14:11:50.988000 marketDataUpdate.Price: 11200.5
    25/05/2020 14:11:50.988000 marketDataUpdate.Price: 11200.5
    25/05/2020 14:11:50.960000 barUpdate: BIP=1, CurBar=736, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.988000 marketDataUpdate.Price: 11200.5
    25/05/2020 14:11:50.988000 barUpdate: BIP=1, CurBar=737, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.988000 marketDataUpdate.Price: 11200.5
    25/05/2020 14:11:50.989000 marketDataUpdate.Price: 11201
    25/05/2020 14:11:50.989000 marketDataUpdate.Price: 11201.5
    25/05/2020 14:11:50.988000 barUpdate: BIP=1, CurBar=738, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.989000 marketDataUpdate.Price: 11201
    25/05/2020 14:11:50.989000 barUpdate: BIP=1, CurBar=739, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.989000 marketDataUpdate.Price: 11201.5
    25/05/2020 14:11:50.996000 marketDataUpdate.Price: 11200
    25/05/2020 14:11:50.989000 barUpdate: BIP=1, CurBar=740, O=11179, H=11179, L=11179, C=11179
    25/05/2020 14:11:50.996000 marketDataUpdate.Price: 11200
    25/05/2020 14:12:00.000000 barUpdate: BIP=0, CurBar=11, O=11198, H=11202, L=11196, C=11201
    Attached Files

    #2
    Hello cmarkb,

    What is the actual issue? It is expected there will be way more market updates than last trade ticks.

    OnMarketUpdate is run when there are changes to the level 1 ask or bid.

    OnBarUpdate runs when there is a tick.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChealseaB,

      In that snippet, shouldn't the values in BarsInProgress=1 / tick series have the open / high/ low / close values of the later BarsInProgress=0 value?

      In this BIP=0 barupdate, OHLC is at >= 11190

      25/05/2020 14:12:00.000000 barUpdate: BIP=0, CurBar=11, O=11198, H=11202, L=11196, C=11201

      while the BIP=1 barupdates, values are at 1117x.

      Also, found this weird stop that it did.

      Click image for larger version

Name:	weird-stop.JPG
Views:	146
Size:	133.3 KB
ID:	1134409
      Attached Files
      Last edited by cmarkb; 12-30-2020, 02:40 AM.

      Comment


        #4
        Hello cmarkb,

        I am not able to reproduce this behavior.

        Below is a link to the test.


        You may need to reload all of the tick data.

        Open a 1 tick chart to the same instrument and load the same number of days, then right-click the chart and select Reload All Historical Data.

        Go back to the original chart with the strategy and reload this chart as well.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi ChelseaB,

          Tried that Reload All Historical Data and it didn't work. Still getting those stops at weird positions.

          Click image for larger version

Name:	202101010215-weird-stops.JPG
Views:	150
Size:	144.6 KB
ID:	1134613

          Have also tried deleting from Tools > Historical Data then importing from an earlier export months before this issue happened. And same result.

          Comment


            #6
            Hello cmarkb,

            This is definitely an issue with data.

            I am not able to reproduce.

            Attached is a reduced test script. Does this also experience the same behavior?
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi ChealseB,

              Okay looks like deleting from Tools > Historical Data then importing / loading from chart does remove the weirdly placed stops. The backtest results (Gross Profit,etc) though is still different from previous results. Will check my code again. Thanks for the help.

              Comment


                #8
                FDAX TickSize changing from 0.5 to 1 was the main culprit.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Irukandji, Today, 04:58 AM
                0 responses
                2 views
                0 likes
                Last Post Irukandji  
                Started by fitspressoburnfat, Today, 04:25 AM
                0 responses
                2 views
                0 likes
                Last Post fitspressoburnfat  
                Started by Skifree, Today, 03:41 AM
                1 response
                4 views
                0 likes
                Last Post Skifree
                by Skifree
                 
                Started by usazencort, Today, 01:16 AM
                0 responses
                1 view
                0 likes
                Last Post usazencort  
                Started by kaywai, 09-01-2023, 08:44 PM
                5 responses
                604 views
                0 likes
                Last Post NinjaTrader_Jason  
                Working...
                X