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 trilliantrader, Today, 03:01 PM
        0 responses
        2 views
        0 likes
        Last Post trilliantrader  
        Started by pechtri, 06-22-2023, 02:31 AM
        9 responses
        122 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by frankthearm, 04-18-2024, 09:08 AM
        16 responses
        67 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by habeebft, Today, 01:18 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by benmarkal, Today, 12:52 PM
        2 responses
        19 views
        0 likes
        Last Post benmarkal  
        Working...
        X