Overall Statistics |
Total Trades 32175 Average Win 0.04% Average Loss -0.06% Compounding Annual Return 816.692% Drawdown 2.900% Expectancy 0.096 Net Profit 316.298% Sharpe Ratio 10.604 Loss Rate 31% Win Rate 69% Profit-Loss Ratio 0.59 Alpha 1.543 Beta 0.1 Annual Standard Deviation 0.146 Annual Variance 0.021 Information Ratio 8.057 Tracking Error 0.182 Treynor Ratio 15.51 Total Fees $0.00 |
namespace QuantConnect.CSharp.Algorithms { public class ScalpingAlgorithm : QCAlgorithm { private WilliamsFractals _wf; private string symbol = "NZDCHF"; public override void Initialize() { SetStartDate(2016, 1, 1); SetEndDate(DateTime.Now); SetCash(3000); AddSecurity(SecurityType.Forex, symbol, Resolution.Minute); Securities[symbol].FeeModel = new ConstantFeeModel(0.0m); _wf = new WilliamsFractals(); } public void OnData(TradeBars data) { _wf.Update(data[symbol]); if (_wf.IsReady) { if (data[symbol].Price >= _wf.BarryUp) { SetHoldings(symbol, -1.0m); } else if (data[symbol].Price <= _wf.BarryDown) { SetHoldings(symbol, 1.0m); } } } } }
using Accord.Extensions; using QuantConnect.Data.Market; namespace QuantConnect.Indicators { public class WilliamsFractals : TradeBarIndicator { private readonly RollingWindow<TradeBar> _fractal; private readonly int _fractalMidIndex; private decimal _barryUp; private decimal _barryDown; public decimal BarryUp => _barryUp; public decimal BarryDown => _barryDown; public decimal MidPoint => (_barryUp - _barryDown) / 2m; public override bool IsReady => _fractal.IsReady; public WilliamsFractals(int fractalLength = 5) : this("WilliamsFractals" + fractalLength, fractalLength) { } public WilliamsFractals(string name, int fractalLength = 5) : base(name) { _fractal = new RollingWindow<TradeBar>(fractalLength); _fractalMidIndex = fractalLength / 2 - (fractalLength % 2 == 0 ? 1 : 0); } protected override decimal ComputeNextValue(TradeBar input) { _fractal.Add(input); if (!_fractal.IsReady) return MidPoint; if (_fractal.IndexOfMax((bar, index) => bar.High) == _fractalMidIndex) { _barryUp = input.High; } if (_fractal.IndexOfMin((bar, index) => bar.Low) == _fractalMidIndex) { _barryDown = input.Low; } return MidPoint; } } }