NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript File Sharing > NinjaScript File Sharing Discussion

NinjaScript File Sharing Discussion Discussion for shared NinjaScript files.

Reply
 
Thread Tools Display Modes
Old 10-15-2010, 07:53 PM   #1
bobido
Junior Member
 
Join Date: Oct 2010
Location: Dutchland
Posts: 6
Thanks: 0
Thanked 1 time in 1 post
Post 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
File Type: cs @MaxExpectunity.cs (3.3 KB, 25 views)
bobido is offline  
Reply With Quote
The following user says thank you to bobido for this post:
Old 10-16-2010, 09:19 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Thanks for sharing your work here bobido, unfortunately adding to the default performance viewer stats is not supported.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-06-2011, 01:56 PM   #3
motownlucas
Member
 
Join Date: Dec 2010
Posts: 58
Thanks: 3
Thanked 3 times in 2 posts
Default

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.
motownlucas is offline  
Reply With Quote
Old 12-13-2011, 05:25 AM   #4
mokodo
Member
 
Join Date: Feb 2010
Posts: 30
Thanks: 2
Thanked 2 times in 2 posts
Default Cheers

Nice one, thanks for sharing
mokodo is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:01 PM.