Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Expectunity

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

    Expectunity

    Hi there,

    On basis of the ninjascript made for the calculation on the expectancy (by: Elliot Wave) as a optimalization type, I made a script for showing the expectunity of a given strategy. Adding the dimension of opportunity as Van Tharp states. I added it to the globals, so u can use it to show the expectunity in the output window or log window on the end of each simulation. Even better would be the ability to add it in the performance window, but I have not found a reference for that so far?

    Also added is the Optimizer Type: Max. Expectunity
    Comments are always welcome.

    Code:

    Code:
            /// <summary>
            /// Returns the current Expectancy calculated for this strategy.
            /// This calculation needs at least 1 trade
            /// </summary>
            /// <remarks>Expectancy. Coded by Elliott Wave 12/15/2008.</remarks>
            /// <returns></returns>
            public double GetCurrentExpectancy()
            {
                double expectancyTemp;
                double percentWin, percentLose;
                double aveWin, aveLose;
    
                if (this.Performance.AllTrades.Count == 0 || this.Performance.AllTrades.LosingTrades.Count == 0)
                {
                    return 0;
                }
                else
                {
                    percentWin = (double)this.Performance.AllTrades.WinningTrades.Count / this.Performance.AllTrades.Count;
                    percentLose = (double)this.Performance.AllTrades.LosingTrades.Count / this.Performance.AllTrades.Count;
                    aveWin = this.Performance.AllTrades.WinningTrades.TradesPerformance.Currency.AvgProfit;
                    aveLose = this.Performance.AllTrades.LosingTrades.TradesPerformance.Currency.AvgProfit;
                    expectancyTemp = (aveWin * percentWin + aveLose * percentLose) / Math.Abs(aveLose);
                    //expectancyTemp = (percentWin * aveWin) - (percentLose * aveLose);
                    return expectancyTemp;
                }
            }
    
            /// <summary>
            /// Get the current Expectunity
            /// </summary>
            /// <returns></returns>
            public double GetCurrentExpectunity()
            {
                //Set the days in a year
                double Daysinyear = 365;
    
                //Get the total number of trades
                int numberoftrades = this.Performance.AllTrades.TradesCount;
    
                //If there arent many trades don't calc
                if (numberoftrades < 3)
                    return 0;
    
                //Get the total number of days that were traded
                /* <-- Any other way to get this value? --> */
                int days = ((this.Performance.AllTrades[numberoftrades - 1].Exit.Time)-(this.Performance.AllTrades[0].Entry.Time)).Days;
    
                //Get the amount of years traded
                double years = (days > Daysinyear) ? days / Daysinyear : 1;
    
                //Check the number of trades made p.day - p.year (since expectunity is calculated on a year basis?)
                double Opportunity = (numberoftrades / years) / Daysinyear;
    
                //Return the expectunity
                return this.GetCurrentExpectancy() * Opportunity;
            }
    Attached Files

    #2
    Thanks for sharing your work here bobido, unfortunately adding to the default performance viewer stats is not supported.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for sharing Bobido! Could you provide some directions on exactly how to use this code? I copied the file to C:\...\NinjaTrader 7\bin\Custom\Type and was able to select it as the optimization parameter, but I can't find the results anywhere.

      Comment


        #4
        Cheers

        Nice one, thanks for sharing

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,265 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X