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:
/// <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; }
Comment