Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy works in Backtest & Optimizer, but not with Multi-Objective Optimization

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

    Strategy works in Backtest & Optimizer, but not with Multi-Objective Optimization

    Hi,
    I have a strategy that adds to a winner twice with increasing position size:
    1. enter long 1 contract
    2. If long 1 contract, add 2 more 15 points above average position price
    3. If long 3 contracts, add 3 more 15 points above average position price

    This works as I expect it on a chart, showing the historical trades. It also works in Strategy Analyzer with the backtest or optimization. But as soon as I run it in Multi-Objective Optimization, the Analyzer doesn't execute the strategy as planned. Instead it only adds 1 contract after the first one instead of 2 like supposed to. This then leads to the situation that the position sums up to 2 contracts and it never reaches the point of long 3 and just exits with the trailing stop.

    Why does this work for Backtest, Optimizer, but not for Multi-Objective Optimization?

    Optimization, long1, add 2, add 3:
    Click image for larger version

Name:	image.png
Views:	45
Size:	133.4 KB
ID:	1288881

    ​Multi-Objective Optimization, long 1, adds only 1 instead of 2
    Click image for larger version

Name:	image.png
Views:	46
Size:	150.7 KB
ID:	1288882
    Attached Files

    #2
    Hello philmg,

    Thanks for your post.

    There is nothing specific about multi-objective optimizations that is different besides how it combines the results based on the optimization fitnesses. It might be that when using multi-objective it found better results while using those quantities based on the multiple factors instead of the single factor.

    I see in the screenshot you shared that the strategy parameters do not match and the dates you are testing over also do not match between the two tests.

    Also, I see that you are comparing trades that are happening on different bars between the two tests. If you compare the same bars, do you see the same trades being placed when using the same strategy parameters and the same start/end dates?

    As a test, you should run an optimization and a multi-objective optimization using the same strategy parameters and same start/end dates and compare the generated trades on the same bars to see how the strategy is behaving.

    Further, debugging prints would have to be added to the script to understand exactly how your strategy's logic is evaluating and how the strategy is submitting orders.

    To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Also, print out the order object in OnOrderUpdate() to see how the orders are behaving.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    ​Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm

    If there are a large number of prints happening in the Output window, you could write information to a file using a StreamWriter and review the information in the file.

    StreamWriter: https://ninjatrader.com/support/help...o_write_to.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      The differences is parameters have no impact. I get the same odd phenomenon when running the same parameters.
      Works fine as intended on Optmizer, but isn't able to add 2 contracts and then 3 in Multi-Objective Optimization.

      Below you can see the two runs with the same set of parameters, 4 range chart, time frame etc. The chart shows the same snapshot of the market action, but different outcome. When running Multi-Objective Optimization for some reason the engine cannot add 2, so only adds 1 contract.

      That can not be dependent on my strategy logic, since it is the exact same strategy and the outcome of both runs also has the same parameter combination, which I intentionally now limited to only 3 different possible combination to demonstrate this odd behavior.
      Click image for larger version

Name:	image.png
Views:	43
Size:	151.7 KB
ID:	1288912Click image for larger version

Name:	image.png
Views:	38
Size:	155.7 KB
ID:	1288913

      Comment


        #4
        Hello philmg,

        Thanks for your notes.

        The only difference between Optimizations and Multi Objective Optimizations is that a Multi Objective Optimization will optimize the strategy based on multiple optimization fitnesses whereas a regular Optimization will optimize the strategy based on a single optimization fitness.

        It might just be that when using Multi Objective Optimization it found better results while using those quantities based on the multiple factors instead of the single factor.

        Ultimately, you would need to add prints if your logic is not working as expected when running the Multi Objective Optimization to understand exactly how the logic is evaluating and how the strategy is handling trades. Without debugging the script we would have no information regarding how the strategy logic is behaving differently.

        ​Below is a link to a forum post that demonstrates how to use prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          I have checked it with prints
          ​The first add after long entry should buy 2 contracts at market as shown here. The Input "DoubleContracts"=2, which I have verified with the print. Yet, the strategy submits an order with the quantity 1 in the Multi-Objective Optimization instead of quantity 2, like it correctly does in the Backtest & Optimization.
          Click image for larger version

Name:	image.png
Views:	39
Size:	42.4 KB
ID:	1288918Click image for larger version

Name:	image.png
Views:	39
Size:	309.1 KB
ID:	1288919​I am puzzled​
          Attached Files

          Comment


            #6
            Multi Objective Optimization cannot have found better results, since the parameter settings shown above in both results are the same. The trades should be exactly the same on Optimizer and Multi Objective Optimization

            Comment


              #7
              I have tested this with another very simple strat, just try it for yourself with a sample strat.
              When long 1 contract and you want to add 2 contracts long some point above the market, Multi Objective Optimization cannot do it, can only add 1 contract long, while it shows correctly in Optimization & Backtest.

              Comment


                #8
                Hello philmg,

                Thanks for your notes.

                Please write in to support[at]ninjatrader[dot]com and send us a simple reduced strategy with prints that demonstrate the behavior you are reporting along with a screenshot of the exact steps and settings you are using to reproduce the behavior with the test script.

                Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed.

                To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.​

                To export the reduced test script with prints, go to Tools > Export > NinjaScript AddOn.

                Also, send us your Log and Trace files in your email by following the steps below so we may look into this matter further.

                Follow the steps below to manually attach your log and trace files to your email.
                • Open your NinjaTrader folder under, "Documents" (sometimes called, "My Documents")
                • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
                • Send the 2 compressed folders as attachments to this email.
                • Once complete, you can delete these compressed folders.
                In the subject of your email include ATTN: Brandon H and in the body of the email include a link to this forum post.

                We look forward to assisting further.
                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Karado58, 11-26-2012, 02:57 PM
                8 responses
                14,828 views
                0 likes
                Last Post Option Whisperer  
                Started by Option Whisperer, Today, 09:05 AM
                0 responses
                1 view
                0 likes
                Last Post Option Whisperer  
                Started by cre8able, Yesterday, 01:16 PM
                3 responses
                11 views
                0 likes
                Last Post cre8able  
                Started by Harry, 05-02-2018, 01:54 PM
                10 responses
                3,204 views
                0 likes
                Last Post tharton3  
                Started by ChartTourist, Today, 08:22 AM
                0 responses
                6 views
                0 likes
                Last Post ChartTourist  
                Working...
                X