![]() |
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
|
|||||||
| NinjaScript File Sharing Discussion Discussion for shared NinjaScript files. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Oct 2010
Location: Dutchland
Posts: 6
Thanks: 0
Thanked 1 time in 1 post
|
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;
}
|
|
|
|
|
The following user says thank you to bobido for this post: |
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Thanks for sharing your work here bobido, unfortunately adding to the default performance viewer stats is not supported.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Dec 2010
Posts: 58
Thanks: 3
Thanked 3 times in 2 posts
|
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.
|
|
|
|
|
|
#4 |
|
Member
Join Date: Feb 2010
Posts: 30
Thanks: 2
Thanked 2 times in 2 posts
|
Nice one, thanks for sharing
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|