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

How to get % of profitable months

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

    How to get % of profitable months

    Hi there, is there a way (either via the GUI, or via NinjaScript) to get the % of profitable months for a strategy?

    I am currently doing this manually by doing Analysis by Month in the strategy analyzer and then exporting the monthly grid to Excel, but I'd like to find a simpler (more automated) way of doing this.

    Thanks

    #2
    Hello sdd80,

    Thanks for your post.

    You can create and add a custom performance metric that will be added to the strategy analyzer.

    Your platform includes an example performance metric called SampleCumProfit that you can refer to.

    In addition, there is a link to the related Help Guide section: https://ninjatrader.com/support/help...ce_metrics.htm

    Custom performance metrics are added to the analyzer through Tools>Options>general - "Custom performance metric(s)".

    If you would like something created for you, we can provide a link to 3rd party programmers in the NinjaTrader Ecosystem.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi there, I'm trying to create a custom peformance metric for this now but I need a bit of help.

      Specifically, is there a way to access SystemPerformance from PerformanceMetric?

      Inside a Strategy class, I accomplish this in a very simple way like below. This gives me the total number of profitable months of the strategy and i execute this code in OnStateChange when State == State.Terminated

      foreach (KeyValuePair<object, TradeCollection> entry in SystemPerformance.AllTrades.ByMonth)
      if(entry.Value.TradesPerformance.NetProfit > 0)
      intPositiveMonth++;

      If not, do you have a suggestion on how to track the # of profitable months inside a PerformanceMetric?

      Thanks

      Comment


        #4
        Hello sdd80,

        Thanks for your note.

        This is Brandon responding on behalf of Paul who is out of the office at this time.

        Unfortunately, a PerformanceMetric does not have access to a Strategy object so SystemPerformance could not be used.

        You might find it easiest to use the Analysis Display of the Strategy Analyzer (New > Strategy Analyzer) or the Trade Performance window (New > Trade Performance) to look at Profit Per Month (Right-click in Strategy Analyzer/Trade Performance window > Properties Columns - Analysis > check 'Profit p.m.' box).

        Otherwise, if you would like to build the PerformanceMetric note that PerformanceMetrics deal with Trade objects, and these are comprised of Executions.

        Something you could consider is using the dates from the Trade's Executions to put those trades in a List<Trade> for a particular month. You could also have a List<List<Trade>> that tracks all 'months of' trades.

        See the help guide documentation below for more information.

        Analysis Display Strategy Analyzer: https://ninjatrader.com/support/help...nalysisDisplay
        Analysis Display Trades Performance: https://ninjatrader.com/support/help...nalysisDisplay
        Trade: https://ninjatrader.com/support/help.../nt8/trade.htm
        Execution: https://ninjatrader.com/support/help.../execution.htm
        TradesPerformance: https://ninjatrader.com/support/help...erformance.htm

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

        Comment


          #5
          Thanks Brandon,

          I actually tried something similar but I'm getting strange results and not sure why.

          I created a list of executions and I'm adding to that list in OnAddTrade and then passing that list to SystemPerformance.Calculate, per below. I then simply tried to get the SharpeRatio expecting it to be the same as the "Share ratio" value that's already in Strategy Analyzer. I do get a value, but it doesn't match the strategy analyzer one. I tried a number of other values like tradeCount, gross profit etc, and I do get values but they don't match the strategy analyzer. Can you see anything wrong with this approach?

          Thanks

          Code:
          List<Execution> executions = new List<Execution>();
          
          protected override void OnAddTrade(Cbi.Trade trade)
          {[INDENT]executions.Add(trade.Entry);
          executions.Add(trade.Exit);[/INDENT]
           }
          
          private double Calculate()
          {[INDENT]return SystemPerformance.Calculate(executions).AllTrades.TradesPerformance.SharpeRatio;[/INDENT]
           }
          
          public override string Format(object value, Cbi.PerformanceUnit unit, string propertyName)
          {[INDENT]Values[0] = Calculate();
          return Math.Round(Values[0] ,2).ToString(Core.Globals.GeneralOptions.CurrentCulture);[/INDENT]
           }

          Comment


            #6
            Hello sdd80,

            Thanks for your note.

            I see you are using SystemPerformance.Calculate in your script which is likely causing the differences you are reporting.

            SystemPerformance.Calculate is a custom TradeCollection that is not documented or supported so I would not have a recommended approach for using it.

            See this forum thread for more information: https://ninjatrader.com/support/foru...ns#post1091053

            We are currently tracking interest for this in an internal feature request and I have added your vote.

            The internal tracking number for your feature request is SFT-3088. Please reference this internal tracking number when contacting Platform Support if you ever have questions regarding this feature request.

            When a feature request is implemented, you'll find a description of the new feature in the release notes:
            Let us know if we may assist further.

            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              +1

              Please add my vote.

              Comment


                #8
                Hello bltdavid,

                Thanks for your note.

                Your vote has been added to this feature request.

                Please let me know if you have further questions.
                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by PhillT, Today, 02:16 PM
                2 responses
                3 views
                0 likes
                Last Post PhillT
                by PhillT
                 
                Started by Kaledus, Today, 01:29 PM
                3 responses
                9 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by frankthearm, Yesterday, 09:08 AM
                14 responses
                47 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by gentlebenthebear, Today, 01:30 AM
                2 responses
                14 views
                0 likes
                Last Post gentlebenthebear  
                Started by PaulMohn, Today, 12:36 PM
                2 responses
                17 views
                0 likes
                Last Post PaulMohn  
                Working...
                X