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

Questions about the Strategy Analyzer Optimizations to better understand the process

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

    Questions about the Strategy Analyzer Optimizations to better understand the process

    Hello

    I have some questions about the Optimization process in the Strategy Analyzer that I will be posting here in order to better understand what I consider to be some crucial parts in the Optimization process and to know how accurate are the values it gives comparing it to having been in a continuous day-by-day trading process:

    1. When you select 1 year ago in the time range period for the optimization for example using the ES 12-21 contract, does the Strategy Analyzer work with the specific ES 12-21 contract for that past year of data in order to do the optimization? Or instead of that, the Strategy Analyzer does what is more logic that is to work with the “continuous contract” auto-selecting the “current” contract depending on what range of date it is working in each moment of the optimization process?
    For example if you do an optimization for the 365 past days now in in mid-October 2021:
    • The process starts with the ES 12-20 contract
    • then after its rolling date it changes its current contract for the ES 03-21 contract,
    • then after its rolling date it changes its current contract for the ES 06-21 contract,
    • then after its rolling date it changes its current contract for the ES 09-21 contract,
    • and finally after its rolling date it changes its current contract for the ES 12-21 contract.
    I think this simplified example would be the correct way to do an optimization because in this way it works with that current contract for each range of date what is the most common way you would trade in Live and not just simply using the ES 12-21 contract since 1 year to its expiration. However I would like to clarify this part please, because if what the Strategy Analyzer does by default is to work with the last up-to-date present date contract then I would like to know how I can select a way to work with the continuous contract



    2. Why when you select ‘Order fill resolution = High’ (in seconds) and you select more than 1 year ago in the range of date, for example from June 2020, then the Strategy Analyzer starts to take trades only from 365 days ago ignoring the rest of dates? What about if you want to optimize in that way from 18 months or from 5 years ago?


    In the answers, please try to respond each point separately to keep the order.

    Thank you!

    #2
    Hello futurenow,

    Thanks for your post.

    1. When running an Optimization on a strategy in the Strategy Analyzer on 1 year of data, the Strategy Analyzer uses the Merge Policy option in order to merge the contracts together.

    With MergeBackAdjusted (default setting) the chart will be continuous, stitched together by expiry month from the rollover date of the expiry month to the rollover date of the previous expiry month, and adjusted by an offset to prevent gaps between contract months (which trade at different prices) for a smooth chart.

    With MergeNonBackAdjusted the chart with be continuous (stitched together by expiry month from the rollover date of the expiry month to the rollover date of the previous expiry month) but will not be adjusted and there will be gaps in price from one contract to the next.

    See post #2 in this forum thread for detailed information about Merge Policy options and backtesting/optimizing: https://ninjatrader.com/support/foru...nth#post782986

    Also, see this help guide page for more information about Merge Policy options: https://ninjatrader.com/support/help...20English.html

    2. If High Order Fill Resolution is used in seconds this data would be comprised of tick bars. The amount of historical tick data you would be able to backtest/optimize on in the Strategy Analyzer would depend on the data feed provider you have. If you see that you are only able to backtest/optimize strategies on 365 days of data, this is likely the limitation of historical tick data that your data provider will supply.

    Let us know if we may assist further.

    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      1. When running an Optimization on a strategy in the Strategy Analyzer on 1 year of data, the Strategy Analyzer uses the Merge Policy option in order to merge the contracts together.

      With MergeBackAdjusted (default setting) the chart will be continuous, stitched together by expiry month from the rollover date of the expiry month to the rollover date of the previous expiry month, and adjusted by an offset to prevent gaps between contract months (which trade at different prices) for a smooth chart.

      With MergeNonBackAdjusted the chart with be continuous (stitched together by expiry month from the rollover date of the expiry month to the rollover date of the previous expiry month) but will not be adjusted and there will be gaps in price from one contract to the next.

      See post #2 in this forum thread for detailed information about Merge Policy options and backtesting/optimizing: https://ninjatrader.com/support/foru...nth#post782986

      Also, see this help guide page for more information about Merge Policy options: https://ninjatrader.com/support/help...20English.html

      Thank you for your reply Brandon

      I think the link you wanted to provide about Merge Policy options is the next instead the one you attached above:
      https://ninjatrader.com/support/help...rge_policy.htm

      My question now would be, in order to have more accurate results based on what really happens in "real live" with the contracts in the roll, that is not a non-gap chart, then is it not more accurate to choose the option "MergeNonBackAdjusted" for the chart/instrument when you want to do Backtests/Optimizations and when you are running automatic strategies? And in that way to treat the past historical data as if it would be in live?


      And, other question I have is at this moment I was running an optimization and after start I noticed the connection was not in green connected status, it was in yellow connecting status (see attached picture) but NT8 is still giving optimizations results in that connection status that is Not-Connected, so does it mean the Backtest/Optimization process in NT8 runs with direct NinjaTrader server historical data? Or how it is? because as test I run another optimization with another instrument and NT8 is still giving results, and I don't know if the results are accurate and based in real historical data, but NT8 is giving them and seems to work. Could you please let me know if what happen is that is not necessary to have a live data-feed connection in order to run Backtest/Optimizations?


      Thank you


      Click image for larger version  Name:	NT8 - Running Optimization but no datafeed connected.png Views:	0 Size:	8.2 KB ID:	1176475
      Last edited by futurenow; 10-27-2021, 11:19 AM.

      Comment


        #4
        Hello futurenow,

        Thanks for your note.

        MergeBackAdjusted is essentially for if we have been trading the current front month, but going back as many expiries as we are testing (the data is merged to align with the prices of the front month)

        MergeNonBackAdjusted will leave the data unmerged, so there will be gaps in data, but the data from each expiry is the same as it was.

        Handling what to do with a rollover in the Strategy Analyzer would involve making the same decisions the strategy makes when it would trade live.

        For example, close the position and reopen on next contract month if there is an expiry. You could use MergeNonBackAdjusted along with that and it would be truer to what would transpire live.

        To improve the accuracy of a backtest so submitted orders are closer to real order fills, you would need to submit orders to an added single tick series. You may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.

        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. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

        High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

        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

        In regards to being able to run a backtest/optimization when not connected to a data feed, since the historical data is already downloaded to use for backtesting, you would not necessarily need to be connected to a live data feed. The backtest/optimization will use the historical data that has been downloaded and saved to run the backtest/optimization.

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

        Comment


          #5
          Thank you for your explanations, they help to going understanding better the process

          Well, in the other side at this moment I have the next situation I also previously had in the past when doing the next:
          Ok, the situation is I need to go to past months for Market Replay and then go to the present for live data, I continuously switch from a mode to the other, and when I have a chart with multiple instruments in multiple panels, I specify the contract month for the Market Replay in each of the instruments (let’s say the contract 09-20 for all them), but, but when I come to the present, for example, I duplicate the chart to have it with the current contract month (12-21) and the problem is NT8 does not automatically updating the contract month for this duplicated chart I need it be with the current contracts.

          When I manually update the “main” contract specifying it in the “search box” in the chart (top-left), what I just noticed is NT8 updates only that main first instrument contract you specified when created the chart for first time, but NT8 doesn’t update the rest of instruments contract month and I can’t see a way to do it in a simple way like going to the Data Series and go instrument by instrument and changing/selecting the current month contract.

          I suppose if I use the auto-Rollover feature of course it will update all the contract month, but doing it for every single chart/DOM etc. in NT8, and I have a separated chart that I need it be ready to use when I go to Market Replay (in this example ready with the 09-20 contract), so using the auto-Rollover I think I will have the same problem when come to Market Replay because I would need to specify again those past contract month instrument by instrument.

          All this I describe to you could not be a problem if we talk about a chart with 2 instruments in a plain “standard” way and done, but in this case we are talking about multiple instruments each one with its own plot settings and the main is there are multiple scripts that have specified what exact instrument and settings to use.
          • One of my questions would be, is there not a simple way to do this what I need in the chart to specify the contract month I need and specify if I want to update all the instruments in that current chart? Or if instead of that I want to update one by one? Maybe a way where I have the 2 charts, each one with its own contract month but that if want to change for example to the contract 03-21 then that I have and quick way to do it, something that take 2-3 seconds.
          • Other question would be, is there not a way to simply specify and load the charts with the continuous contracts? Just like others platforms do as alternative way to plot the charts, and in that way to avoid to do this process forward and backward.


          Thank you

          Comment


            #6
            Hello futurenow,

            Thanks for your note.

            To clarify, are you asking about changing a chart's data series from within a script?

            If so, there is no documented or supported way to accomplish this. However, the instrument could be changed by sending keys using unsupported code.

            See this Rollover Indications script from the User App Share center: https://ninjatraderecosystem.com/use...indications-2/

            "I think I will have the same problem when come to Market Replay because I would need to specify again those past contract month instrument by instrument"

            This would not be the case. All instruments in all open workspaces and all instruments in instrument lists would be rolled over. You would not have to change the instruments one by one

            If you use instrument linking, you could manually change an instrument and have other charts also change.

            See this help guide for more information about window linking: https://ninjatrader.com/support/help...ng_windows.htm

            The MergeNonBackAdjusted merge policy could be used to load a continuous chart of an instrument with NO offset value applied. Note that significant price gaps in the chart may be present due to changes in contract values that were NOT Offset.

            See this help guide page for more information and examples about Merge Policy options: https://ninjatrader.com/support/help...rge_policy.htm

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kevinenergy, 02-17-2023, 12:42 PM
            115 responses
            2,698 views
            1 like
            Last Post kevinenergy  
            Started by prdecast, Today, 06:07 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by Christopher_R, Today, 12:29 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by chartchart, 05-19-2021, 04:14 PM
            3 responses
            577 views
            1 like
            Last Post NinjaTrader_Gaby  
            Started by bsbisme, Yesterday, 02:08 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X