In [ ]:
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);
       
            AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Tick);
            
            SetWarmUp(TimeSpan.FromDays(7));
            var smaDaily = SMA("EURUSD", 24, Resolution.Hour);
           
           
            var dayCount = TimeSpan.FromDays(10);  // I need to be able to count number of days after trade was placed?  
            int tradeTime;                         // Not sure how to set time that trade was taken
            int totalTime = 0;
            
            
            var currentPrice = slice.Ticks("EURUSD"); // or maybe OnData(Slice data) used here??
            
            var longTrade = MarketOrder("EURUSD", 10000);
            var shortTrade = MarketOrder("EURUSD", -10000);
            
            var longProfitTarget = LimitOrder("EURUSD",+20 pips, "Profit Target 20 Pips"); // ??
            var shortProfitTarget = LimitOrder("EURUSD",-20 pips, "Profit Target 20 Pips"); // ??
           
        }

        public override void OnData(Ticks data) 
        {
            if (!Portfolio["EURUSD"].Invested and currentPrice > smaDaily and totalTime == 0) // Trying to say that currently NOT invested and current price above SMA then initiate Buy Order
            {
                longTrade;
                longProfitTarget; // I don't know how to set target profit, will cancel this order if 10 days is up, with logic below
                totalTime = tradeTime + dayCount;
                Log("Purchased EURUSD on " + Time.ToShortDateString());
                
            }
            
            if (!Portfolio["EURUSD"].Invested and currentPrice < smaDaily and totalTime == 0) // Trying to say that currently NOT invested and current price below SMA then initiate Sell Order
            {
                shorTrade;
                shortProfitTarget; // I don't know how to set target profit and cancel this order if 10 days is up?
                totalTime = tradeTime + dayCount;
                Log("Sold EURUSD on " + Time.ToShortDateString());
            }
            
            if (Portfolio["EURUSD"].IsLong and totalTime > 10 )
            {
            	shortTrade;
            	List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD"); // I think 
            	totalTime = 0;
            	Log("Closed Long Trade " + Time.ToShortDateString() + "and cancelled all orders");
            }
            
            if (Portfolio["EURUSD"].IsShort and totalTime > 10 )
            {
            	longTrade;
            	List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD")
            	totalTime = 0;
            	Log("Closed Short Trade " + Time.ToShortDateString()) + "and cancelled all orders";
            }
            
        }
    }
}
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: