18 using System.Collections.Generic;
29 private readonly decimal _maximumDrawdownPercent;
30 private decimal _portfolioHigh;
31 private bool _initialised =
false;
32 private bool _isTrailing;
43 _maximumDrawdownPercent = -Math.Abs(maximumDrawdownPercent);
44 _isTrailing = isTrailing;
54 var currentValue = algorithm.
Portfolio.TotalPortfolioValue;
58 _portfolioHigh = currentValue;
63 if (_isTrailing && (_portfolioHigh < currentValue))
65 _portfolioHigh = currentValue;
69 var pnl = GetTotalDrawdownPercent(currentValue);
70 if (pnl < _maximumDrawdownPercent && targets.Length != 0)
74 foreach (var target
in targets)
76 var symbol = target.Symbol;
79 algorithm.
Insights.Cancel(
new[] { symbol });
87 private decimal GetTotalDrawdownPercent(decimal currentValue)
89 return (currentValue / _portfolioHigh) - 1.0m;