Overall Statistics
Total Trades
22
Average Win
4.27%
Average Loss
-3.06%
Compounding Annual Return
6511.615%
Drawdown
6.300%
Expectancy
0.522
Net Profit
17.496%
Sharpe Ratio
9.211
Loss Rate
36%
Win Rate
64%
Profit-Loss Ratio
1.39
Alpha
5.62
Beta
-133.464
Annual Standard Deviation
0.377
Annual Variance
0.142
Information Ratio
9.166
Tracking Error
0.377
Treynor Ratio
-0.026
Total Fees
$0.00
namespace QuantConnect 
{  
	public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	public string[] Symbols = {"AUDUSD", "EURUSD", "USDCAD", "USDJPY"};
    	private Dictionary<string, DonchianChannel> Local = new Dictionary<string, DonchianChannel>();
    	private Dictionary<string, RollingWindow<bool>> Entered = new Dictionary<string, RollingWindow<bool>>();
    	public Dictionary<string, DateTime> Entry = new Dictionary<string, DateTime>();
    	public Dictionary<string, decimal> High = new Dictionary<string, decimal>();
    	public Dictionary<string, decimal> Low = new Dictionary<string, decimal>();
    	public bool Day;
    	
        public override void Initialize() 
        {
            SetStartDate(2018, 1, 1);         
            SetEndDate(DateTime.Now);
            SetCash(10000);
            foreach (var symbol in Symbols)
            {
            	AddForex(symbol, Resolution.Minute);
            	Local[symbol] = DCH(symbol, 24, Resolution.Hour);
            	Entered[symbol] = new RollingWindow<bool>(2);
            }
            SetWarmup(1500);
        }
        
        public void OnData(QuoteBars data) 
        {
        	foreach (var symbol in Symbols)
        	{
        		Entered[symbol].Add(Portfolio[symbol].Invested);
        		if (!Entered[symbol].IsReady) return;
        		if (!data.ContainsKey(symbol)) return;
        		if (!Local.ContainsKey(symbol)) return;
        		if (!Entered.ContainsKey(symbol)) return;
        		if (!Entry.ContainsKey(symbol)){
        			Entry.Add(symbol, Time);
        		}
        		if (!High.ContainsKey(symbol)){
        			High.Add(symbol, data[symbol].High);
        		}
        		if (!Low.ContainsKey(symbol)){
        			Low.Add(symbol, data[symbol].Low);
        		}
        	}
        	
        	foreach (var symbol in Symbols)
        	{
        		Schedule.On(DateRules.EveryDay(symbol), TimeRules.At(17, 00), () => 
                {
        			High[symbol] = Local[symbol].UpperBand;
        			Low[symbol] = Local[symbol].LowerBand;
        			Day = false;
        		});
        	}
        	foreach (var symbol in Symbols)
        	{
        		if (!(High[symbol] > 0 && Low[symbol] > 0)) return;
        		if (Entered[symbol][0] && !Entered[symbol][1])
        		{
        			Transactions.CancelOpenOrders(symbol);
        			//Entry[symbol] = Time;
        			if (Portfolio[symbol].IsShort)
        			{
        				Notify.Sms("5714396200","Algorithm opened short of " + symbol + " at " + Low[symbol]);
        				Notify.Sms("8188529720","Algorithm opened short of " + symbol + " at " + Low[symbol]);
        			}
        			if (Portfolio[symbol].IsLong)
        			{
        				Notify.Sms("5714396200","Algorithm opened long of " + symbol + " at " + High[symbol]);
        				Notify.Sms("8188529720","Algorithm opened long of " + symbol + " at " + High[symbol]);
        			}
        		}
        	}
        	if (Day == true) return;
        	foreach (var symbol in Symbols)
        	{
        		var qty = CalculateOrderQuantity(symbol, 12.5m);
        		if (!Portfolio[symbol].Invested)
        		{
        			Transactions.CancelOpenOrders(symbol);
        			StopLimitOrder(symbol, qty, High[symbol], High[symbol], "Breakout at " + High[symbol]);
        			StopLimitOrder(symbol, -qty, Low[symbol], Low[symbol], "Breakdown at " + Low[symbol]);
        			Log("Orders should be out at " + High[symbol] + " and " + Low[symbol]);
        		}
        		if (Portfolio[symbol].Invested)// && (Time- Entry[symbol] >= TimeSpan.FromDays(1)))
        		{
        			if (Portfolio[symbol].IsShort)
        			{
        				Notify.Sms("5714396200","Algorithm covered short of " + symbol + " at " + data[symbol].Close);
        				Notify.Sms("8188529720","Algorithm covered short of " + symbol + " at " + data[symbol].Close);
        			}
        			if (Portfolio[symbol].IsLong)
        			{
        				Notify.Sms("5714396200","Algorithm closed long of " + symbol + " at " + data[symbol].Close);
        				Notify.Sms("8188529720","Algorithm closed long of " + symbol + " at " + data[symbol].Close);
        			}
        			Transactions.CancelOpenOrders(symbol);
        			LimitOrder(symbol, -Portfolio[symbol].Quantity, data[symbol].Close, "Time is " + Time + " and Price is " + data[symbol].Close);
        		}
        	}
        	Day = true;
        }
    }
}