Overall Statistics
namespace QuantConnect 
{   
    public class TimeBasedAlgo : QCAlgorithm
    {
        public override void Initialize() 
        {
            SetStartDate(2018, 1, 1);
            SetEndDate(2018, 1, 2);
            SetCash(5000);
            SetBenchmark("SPY");
            
            SetBrokerageModel(BrokerageName.OandaBrokerage);
            
            AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Tick);
            
            
        }
        public override void OnData(Slice data) 
        {
        	
        	var holdings = Portfolio["EURUSD"].Quantity;
        	var sma = SMA("EURUSD", 24, Resolution.Hour);
        	
        	var currentPrice = Securities["EURUSD"].BidPrice;
      
        	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);
                
                SetHoldings("EURUSD", 1);
                Log("Purchased EURUSD on " + Time.ToShortDateString());
             
            	if(tradeInPlace == true && Portfolio["EURUSD"].IsLong)
            	{
                	Schedule.On(DateRules.On(endTime), TimeRules.At(13, 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);
                
                SetHoldings("EURUSD", 1);
                Log("Sold EURUSD on " + Time.ToShortDateString());
                
                if(tradeInPlace == true && Portfolio["EURUSD"].IsShort)
            	{
                	Schedule.On(DateRules.On(endTime), TimeRules.At(13, 0), () =>
					{
						Liquidate("EURUSD");
						SetHoldings("EURUSD", 0);
						List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD");
            			Log("Cancelled All Orders & Closed Short Trade " + Time.ToShortDateString());
					});
            	}
            }
        }
    }
}