Overall Statistics
Total Trades
726
Average Win
0.07%
Average Loss
-0.07%
Compounding Annual Return
-73.666%
Drawdown
7.600%
Expectancy
-0.273
Net Profit
-6.368%
Sharpe Ratio
-11.058
Loss Rate
66%
Win Rate
34%
Profit-Loss Ratio
1.13
Alpha
-0.828
Beta
0.801
Annual Standard Deviation
0.083
Annual Variance
0.007
Information Ratio
-11.003
Tracking Error
0.073
Treynor Ratio
-1.144
Total Fees
$0.00
namespace QuantConnect.MAAlgorithm
{
    public class MAAlgorithm : QCAlgorithm
    {
        public string[] Symbols = {"EURUSD","NZDUSD","AUDUSD","USDCAD"};

    	private Dictionary<string, RollingWindow<QuoteBar>> _windows = new Dictionary<string, RollingWindow<QuoteBar>>();

        private Dictionary<string, ExponentialMovingAverage> fast = new Dictionary<string, ExponentialMovingAverage>();
        private Dictionary<string, ExponentialMovingAverage> slow = new Dictionary<string, ExponentialMovingAverage>();

        public override void Initialize()
        {
            SetStartDate(2017, 04, 01);
            SetEndDate(2017, 04, 20);
			SetCash(10000);
            SetBrokerageModel(BrokerageName.OandaBrokerage);
			
			foreach (var symbol in Symbols)
            {
	            AddSecurity(SecurityType.Forex, symbol, Resolution.Hour);
	            Securities[symbol].FeeModel = new ConstantFeeModel(0);
	            
            	_windows[symbol] = new RollingWindow<QuoteBar>(2);
            	
	            fast[symbol] = EMA(symbol, 13, Resolution.Hour);
	            slow[symbol] = EMA(symbol, 48, Resolution.Hour);
            }
        }
        
        public void OnData(QuoteBars data)
        {
        	foreach (var symbol in Symbols)
        	{
    			var holdingsL = Portfolio[symbol].IsLong;
    			var holdingsS = Portfolio[symbol].IsShort;
    			var currentHigh = data[symbol].High;
    			var currentLow = data[symbol].Low;
    			var quantity = 10000;
    			
    			_windows[symbol].Add(data[symbol]);
    		 	if (!_windows[symbol].IsReady) return;
    		 	
        		var previousLow = _windows[symbol][1].Low;
        		var previousHigh = _windows[symbol][1].High;
    	
        		if (!holdingsL && fast[symbol] > slow[symbol])
    			{
	            	Log("Long  " + symbol + "  at  " + Securities[symbol].Price);
	                MarketOrder(symbol, quantity);
            	}
            	
            	if (holdingsL && ((currentLow < previousLow) || (fast[symbol] < slow[symbol])))
            	{
	            	Log("Sold  " + symbol + "  at  " + Securities[symbol].Price);
	            	Liquidate(symbol);
            	}
        		
            	if (!holdingsS && fast[symbol] < slow[symbol])
        		{
	            	Log("Short  " + symbol + "  at  " + Securities[symbol].Price);
	            	MarketOrder(symbol, -quantity);
            	}
            	
            	if (holdingsS && ((currentHigh > previousHigh) || (fast[symbol] > slow[symbol])))
            	{
	            	Log("Covered  " + symbol + "  at  " + Securities[symbol].Price);
	            	Liquidate(symbol);
            	}
        	}
    	}
    }
}