Overall Statistics
Total Trades
582
Average Win
7.59%
Average Loss
-6.26%
Compounding Annual Return
180.022%
Drawdown
51.100%
Expectancy
0.216
Net Profit
1987.013%
Sharpe Ratio
1.307
Loss Rate
45%
Win Rate
55%
Profit-Loss Ratio
1.21
Alpha
1.014
Beta
-0.101
Annual Standard Deviation
0.772
Annual Variance
0.596
Information Ratio
1.221
Tracking Error
0.782
Treynor Ratio
-9.943
Total Fees
$73443.36
using MathNet.Numerics;
namespace QuantConnect 
{   
    
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	public string pair1 = "GBPUSD";
    	RollingWindow<TradeBar> window;
    	const int WL = 10;
    	double entryPrice = 0;
    	int holdHours = 0;
    	bool Long = false;
    	bool hasTraded = false;
    	BollingerBands bb;
    	
        public override void Initialize() 
        {
        	SetStartDate(2014,01,01);
            SetEndDate(2016, 12, 12);         
            
            SetBrokerageModel(BrokerageName.FxcmBrokerage);
            //SetBrokerageModel(BrokerageName.OandaBrokerage);
            
            SetCash(10000);
            
            window = new RollingWindow<TradeBar>(WL);
            
            //AddForex(pair1, Resolution.Minute, Market.Oanda);
            AddForex(pair1, Resolution.Hour, Market.FXCM);
            bb = BB(pair1, WL, 2.2M, MovingAverageType.Simple, Resolution.Hour);
        }
        
	    public void OnData(TradeBars data) {
			window.Add(data[pair1]);
			if(!window.IsReady) return;
			
			if(data[pair1].Time.Hour == 1){
				hasTraded = false;
			}

			var close = (double)data[pair1].Close;
			// Entry
			if(data[pair1].Time.Hour > 4 && data[pair1].Time.Hour <= 10 
				&& !Portfolio.Invested && !hasTraded){
				if(close > bb.UpperBand){
					SetHoldings(pair1, 50);
					holdHours = 0;
					Long = true;
					hasTraded = true;
					entryPrice = close;
				}
				if(close < bb.LowerBand){
					SetHoldings(pair1, -50);
					holdHours = 0;
					Long = false;
					hasTraded = true;
					entryPrice = close;
				}
			}
			
			// Exit
			if(Portfolio.Invested){
				// Take profit
				if(Long && close > entryPrice +0.00080)
					Liquidate();
				if(!Long && close < entryPrice -0.00080) 
					Liquidate();
				// Stop loss
				if(Long && close < entryPrice - 0.00180)
					Liquidate();
				if(!Long && close > entryPrice + 0.00180)
					Liquidate();
				// Timed exit
				holdHours++;
				if(holdHours > 5)
					Liquidate();
			}

        }
        
	  
    }
}