Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Irrelevant results based on 1 trade only

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

    Irrelevant results based on 1 trade only

    Dear Support,

    I've playing quite intensively with the optimizer for the past few weeks and sometimes it returns very high results (99 PF factor or 100 % profitable or % win/loss) but the results are based on 1 trade only!

    The results are correct, strictly speaking, but they make little sense. Is there a way around this? Should there be a minimum # of trades to make it meaningful?

    Hope you can help,
    Kind regards,

    Chris

    #2
    Chris, yes that can happen and technically speaking correct. You could custom code an optimization objective that would incorporate the # of trades and the profit factor, but that's unfortunately nothing we can offer support on for the code creation / testing.

    I will forward your thoughts though to product management so it can be considered as area for enhancement in the future.

    Thanks,
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi again, it seems that some functions in the manual can count the number of trades. It is a good idea and I'll further explore that angle.
      Many thanks for the quick reply and good suggestion.
      Chris

      Comment


        #4
        something like that in a 3rd condition set (1st is buying signal, 2nd is selling)?

        // Condition set 3
        if (Performance.AllTrades.Count >= 10
        && Performance.AllTrades.TradesPerformance.ProfitFact or < 99)
        {

        }
        Last edited by ch9090; 10-25-2011, 09:35 AM.

        Comment


          #5
          Were would you be looking to insert this code Chris? To get different optimization results you would need to change the underlying profit objective stored as type (bin > custom > type folder), which would be something we could not assist on.

          Your initial though and very useful suggestion is now tracked by product management under #1349 - thanks for taking the time to share this with us and helping to further enhance our NinjaTrader platform.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            I was just thinking of adding it to my custom strategy as a separate condition set but I am not sure about the code as I saw man versions of the Performance.AllTrades.

            I'll try what you've suggested. Cheers. Chris

            Comment


              #7
              Dear Bertrand,

              I've tried as you suggested to create a new custom type but it doesn't like the code and won't compile it:

              /// <summary>
              /// </summary>
              [Gui.Design.DisplayName("max. profit factor +")]
              public class MaxProfitFactorPlus : OptimizationType
              {
              /// <summary>
              /// Return the performance value of a backtesting result.
              /// </summary>
              /// <param name="systemPerformance"></param>
              /// <returns></returns>
              public override double GetPerformanceValue(SystemPerformance systemPerformance)
              {
              return systemPerformance.AllTrades.TradesPerformance.Prof itFactor < 99 + systemPerformance.AllTrades.TradesCount <= 10;
              }

              Am I close?

              Thank you,
              Chris

              Comment


                #8
                ch9090,

                I am happy to assist you.

                What are you trying to do with this line :

                return systemPerformance.AllTrades.TradesPerformance.Prof itFactor < 99 + systemPerformance.AllTrades.TradesCount <= 10;

                As the two comparisons you are doing return a boolean, then you are trying to add them which isn't possible. Also, they aren't in parentheses though this doesn't matter because the + operator isn't defined for booleans. If you could describe to me in detail what you are trying to accomplish I would be happy to help.

                Please let me know if I may assist further.
                Last edited by NinjaTrader_AdamP; 10-28-2011, 11:53 AM.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Dear Adam,

                  I am trying to code a custom type optimizer that would optimizemaximize the PF for more than 10 trades. I put a PF < 99 because it tends to produce results based on 1 trade only and a PF of 99. Technically speaking it is correct but it does not makes sense for a strategy.

                  Many thanks for the help,
                  Chris

                  Comment


                    #10
                    ch9090,

                    Unfortunately this level of customization is not supported as its considered advanced programming.

                    What you were doing before was returning something like true + true, true + false, false + true, or false + false, which is not a ProfitFactor and in fact not even defined since the + operator adds numbers together, not true/false.

                    I will however give you some advice, this Return statement is returning the profit factor, so you need to define outside of the return statement what "Profit Factor" is for you. You can try to setup some profit factor for less than 10 trades and make it so it gets maximized when there are more than 10 trades.

                    For example in psuedo-code :

                    if(total_trades<10)
                    {
                    ProfitFactor = constant;
                    }
                    else if(total_trades >= 10)
                    {
                    //Calculate ProfitFactor however you see fit.
                    }

                    Return(ProfitFactor);

                    Just to be clear, It will require additional steps to calculate this outside of the return statement. Then, return your ProfitFactor however you define it. I cannot guarantee my solution above will work as you describe, but you can try to experiment with it and see if it gives results you prefer.

                    Please let me know if I can assist further.
                    Last edited by NinjaTrader_AdamP; 10-28-2011, 01:49 PM.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Dear Adam,

                      I took my cue from the @MaxNetProfit.cs in bin\custom\type but it is obvious I did not understood what I was doing there.

                      What I wanted to do is to keep optimizing the PF but, in order to avoid returning a PF of 99 based on 1 trade only (for the combined results only; since I optimize on "aggregated results"), I thought it would be possible to add a condition or two e.g. PF<99 and/or total # of trades >= 10.

                      The idea is to force the system to optimize the PF below the 99 irrelevant value.

                      If I understand your advice correctly; should it be something around those lines for the custom type:

                      {
                      /// <summary>
                      /// </summary>
                      [Gui.Design.DisplayName("max. profit factor +")]
                      public class MaxProfitFactorPlus : OptimizationType
                      {
                      /// <summary>
                      /// Return the performance value of a backtesting result.
                      /// </summary>
                      /// <param name="systemPerformance"></param>
                      /// <returns></returns>
                      public override double GetPerformanceValue(SystemPerformance systemPerformance)
                      {
                      if (systemPerformance.AllTrades.TradesCount <= 10)
                      return 0;
                      else
                      return (double) systemPerformance.AllTrades.TradesPerformance.Prof itFactor;
                      }
                      }
                      }

                      Many thanks for your help,
                      Chris

                      Comment


                        #12
                        Ch9090,

                        Just like you added a filter here :

                        if (systemPerformance.AllTrades.TradesCount <= 10)
                        return 0;

                        You could do the same for >= 99 PF

                        Please let me know if I may assist further.
                        Adam P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Adam,

                          Something as simple as that:
                          if (systemPerformance.AllTrades.TradesPerformance.Pro fitFactor < 99)
                          return 0;
                          else
                          return (double) systemPerformance.AllTrades.TradesPerformance.Prof itFactor;

                          would force to optimize the PF and avoid a PF = 99?

                          And in the same spirit:
                          if (systemPerformance.AllTrades.TradesCount < 10)
                          return 0;
                          else
                          return (double) systemPerformance.AllTrades.TradesPerformance.Prof itFactor;

                          Would force to optomize the PF on more than 10 trades?

                          Combining both:
                          if (systemPerformance.AllTrades.TradesPerformance.Pro fitFactor < 99 * systemPerformance.AllTrades.TradesCount < 10)
                          return 0;
                          else
                          return (double) systemPerformance.AllTrades.TradesPerformance.Prof itFactor;

                          i.e. PF is optimize on more than 10 trades and a PF < 99?

                          Looks nice on paper

                          Comment


                            #14
                            ch9090,

                            I believe this would work, but I cannot guarantee it as I have limited experience experimenting with these data types.

                            This would test if ProfitFactor is less than 99 and there are less than 10 trades. If there are, return 0.

                            Code:
                            if (systemPerformance.AllTrades.TradesPerformance.ProfitFactor < 99 && systemPerformance.AllTrades.TradesCount < 10)
                            {
                               return 0;
                            }
                            else
                            {
                                return ((double) systemPerformance.AllTrades.TradesPerformance.ProfitFactor);
                            }
                            Keep in mind this is unsupported so there may be unusual results and we will be unable to assist in all but what is supported.

                            Please let me know if I may assist further.
                            Adam P.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank you Adam for the quick reply. I'll run some test and post the results as it might help someone else. Cheers. Chris

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RubenCazorla, 08-30-2022, 06:36 AM
                              3 responses
                              77 views
                              0 likes
                              Last Post PaulMohn  
                              Started by f.saeidi, Yesterday, 12:14 PM
                              9 responses
                              23 views
                              0 likes
                              Last Post f.saeidi  
                              Started by Tim-c, Today, 03:54 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Tim-c
                              by Tim-c
                               
                              Started by FrancisMorro, Today, 03:24 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post FrancisMorro  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              10 responses
                              1,772 views
                              0 likes
                              Last Post Leafcutter  
                              Working...
                              X