Overall Statistics
namespace QuantConnect 
{   
    public class TimeBasedAlgo : QCAlgorithm
    {
        public override void Initialize() 
        {
            SetStartDate(2017, 1, 1);
            SetEndDate(2018, 1, 1);
            SetCash(5000);
            SetBenchmark("SPY");
            
            SetBrokerageModel(BrokerageName.OandaBrokerage);
            
            AddForex("EURUSD", Resolution.Hour, Market.Oanda);
            
            SetWarmUp(TimeSpan.FromDays(7));
            var sma = SMA("EURUSD", 24, Resolution.Hour);
            
        }
        public override void OnData(Slice data) 
        {
        	
        	
        	if (IsWarmingUp) return;
        	
        	var sma = SMA("EURUSD", 24, Resolution.Hour);
        	var holdings = Portfolio["EURUSD"].Quantity;
        	
        	
        	var currentPrice = data["EURUSD"].Bid.Close;
        	var close = Securities["EURUSD"].Close;
        	var limitPriceUp =  close * 1.002m;
        	var limitPriceDown = close * 1.0016m;
        	
      
        	DateTime endTime = DateTime.Today.AddDays(10);
        	
            bool tradeInPlace;
            
            
			if(Portfolio["EURUSD"].Invested)
			{
				tradeInPlace = true;
			}
			else
			{
				tradeInPlace = false;
			}
        	
        
           if(holdings <= 0 & currentPrice > sma & tradeInPlace == false)
            {
                MarketOrder("EURUSD", 100000);
                LimitOrder("EURUSD", -100000, limitPriceUp);
               // SetHoldings("EURUSD", 1);
                Log("Purchased EURUSD on " + Time.ToShortDateString());
             
            	if(tradeInPlace == true && Portfolio["EURUSD"].IsLong)
            	{
                	Schedule.On(DateRules.On(endTime), TimeRules.At(1, 0), () =>
					{
						Liquidate("EURUSD");
						//SetHoldings("EURUSD", 0);
						List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD");
            			Log("Cancelled All Orders & Closed Long Trade " + Time.ToShortDateString());
					});
            	}
            }
            
            if(holdings <= 0 & currentPrice < sma & tradeInPlace == false)
            {
                MarketOrder("EURUSD", -100000);
                LimitOrder("EURUSD", 100000, limitPriceDown);
                //SetHoldings("EURUSD", 1);
                Log("Sold EURUSD on " + Time.ToShortDateString());
                
                if(tradeInPlace == true && Portfolio["EURUSD"].IsShort)
            	{
                	Schedule.On(DateRules.On(endTime), TimeRules.At(1, 0), () =>
					{
						Liquidate("EURUSD");
					//	SetHoldings("EURUSD", 0);
						List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD");
            			Log("Cancelled All Orders & Closed Short Trade " + Time.ToShortDateString());
					});
            	}
            }
        }
    }
}