Overall Statistics
Total Trades
17292
Average Win
-0.01%
Average Loss
1.59%
Compounding Annual Return
-89.566%
Drawdown
78.000%
Expectancy
-0.701
Net Profit
-76.944%
Sharpe Ratio
-9.956
Loss Rate
70%
Win Rate
30%
Profit-Loss Ratio
-0.01
Alpha
-1.557
Beta
0.097
Annual Standard Deviation
0.156
Annual Variance
0.024
Information Ratio
-8.569
Tracking Error
0.19
Treynor Ratio
-16.027
Total Fees
$3506.16
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 FxcmFeeModel();

            _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;
        }
    }
}