// // Copyright (C) 2006, NinjaTrader LLC . // /* Translated to NinjaTrader by Optiondreamer(2013-02-08) from link below Excel file, http://www.modulusfe.com/ptr.asp for Big Mike's Trading Forum users. */ /* PositiveTrade Ratio is a reward-to-variability ratio similar to Sharpe ratio. Both provide a measure of profit per unit of risk.   Like the Sharpe ratio, PTR is directly computable from any observed series of returns without need for additional information surrounding the source of profitability. PTR was developed to overcome the Sharpe ratio limitation where investments with excessive profits are effectively punished for being successful, due to the use of standard deviation. Instead of factoring any deviation from the mean, PTR calculates only the standard deviation of losing trades. Therefore PTR is similar to the Sortino ratio, except it is simplified in that there is no need for a Minimum Acceptable Rate of Return (MAR) or Downside Deviation (DD). Copyright (c) 2011. PTR was developed by Richard Gardner at Modulus Financial Engineering, Inc. You may copy and distribute this file and or formula provided that this notice including the author's name and company name remain in place. */ #region Using declarations using System; using System.ComponentModel; using System.Drawing; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { /// /// [Gui.Design.DisplayName("Positive Trade Ratio")] public class PositiveTradeRatio : OptimizationType { /// /// Return the performance value of a backtesting result. /// /// /// public override double GetPerformanceValue(SystemPerformance systemPerformance) { double avg = systemPerformance.AllTrades.TradesPerformance.Percent.AvgProfit; double pl = 0; double cumptr = 0; double ptr = 0; foreach (Trade trade in systemPerformance.AllTrades) { pl = trade.ProfitPercent; if ((pl - avg) < 0) cumptr += Math.Pow(pl - avg, 2); } ptr = avg / Math.Sqrt(1.0 / (systemPerformance.AllTrades.Count - 1) * cumptr); return ptr; } } }