Overall Statistics
Total Trades
254
Average Win
0.06%
Average Loss
-0.17%
Compounding Annual Return
-0.104%
Drawdown
3.500%
Expectancy
-0.085
Net Profit
-1.436%
Sharpe Ratio
-0.181
Probabilistic Sharpe Ratio
0.000%
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
0.37
Alpha
0
Beta
-0.01
Annual Standard Deviation
0.005
Annual Variance
0
Information Ratio
-0.506
Tracking Error
0.184
Treynor Ratio
0.086
Total Fees
$29.07
using QuantConnect.Securities;

namespace QuantConnect 
{
public partial class Base	///ONDATA
{
	public class Alpha_SYMBOL_DOWN_S2 : AlphaModel
    {   
    	private readonly Symbol _symbol;
    	
    	private string SYMBOL = "CADJPY" ;

        public Alpha_SYMBOL_DOWN_S2(Symbol symbol)
        {
            _symbol = symbol;
        }

		public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)
        {  
        	var open_orders = algorithm.Transactions.GetOpenOrders(x=>x.Status == OrderStatus.Submitted);
			
			if (!open_orders.Any())
			{
				algorithm.Liquidate();
			}
			
			if (!open_orders.Any(x=>x.Tag.Contains("SYMBOL_DOWN_S2_OCO1")))
			{
				Base.SYMBOL_OCO1_DOWN_S2_IsReady = true;
			}

			
			if (open_orders.Any(x=>x.Tag.Contains("SYMBOL_DOWN_S2")))
			{
				foreach (var order in open_orders)
			    {
					if (Base.SYMBOL_OCO1_EO1_DOWN_S2)
		                Base.SYMBOL_OCO1_EO1_DOWN_S2_ID = order.Id;
		
				        if (algorithm.UtcTime - order.CreatedTime >= TimeSpan.FromMinutes(Base.SYMBOL_DOWN_S2_OCO_DELAY_7DAY))
				        {
				        	int SYMBOL_OCO1S1_DOWN_S2 = 0;
			                for (; SYMBOL_OCO1S1_DOWN_S2 < Base.SYMBOL_DOWN_S2_OCO1Sets1.Count; SYMBOL_OCO1S1_DOWN_S2++)
			                    if (Base.SYMBOL_DOWN_S2_OCO1Sets1[SYMBOL_OCO1S1_DOWN_S2].InOrders(order.Id)) 
			                    {
			                        Base.SYMBOL_DOWN_S2_OCO1Sets1[SYMBOL_OCO1S1_DOWN_S2].TimeOut();
			                        yield return Insight.Price(SYMBOL, TimeSpan.FromMilliseconds(1001), InsightDirection.Up, null, null, null, 1);
			                        algorithm.MarketOrder(SYMBOL, order.Quantity, false, "SYMBOL_DOWN_S2_Entry_1__Time out_OCO1");
			                        Base.SYMBOL_DOWN_S2_OCO1Sets1.Clear();
			                        SYMBOL_OCO1S1_DOWN_S2 = 0;
			                        break;
			                    }
				        }
			    }
			}
			
			foreach (var MINUTE in DATMINUTE.Values)
	        {
	        foreach (var MONTH in DATMONTH.Values)
	        {
	        foreach (var ICHIWEEK in DATICHIWEEK.Values)
	        {
	        foreach (var ICHIMONTH in DATICHIMONTH.Values)
	        {
	            if (
	            		ICHIWEEK.BQIsReady &&
	            		ICHIMONTH.BQIsReady &&
	            		MINUTE.BQIsReady &&
		            	MONTH.BQIsReady &&
		            	ICHIWEEK.WasJustUpdated(algorithm.Time) &&
		            	ICHIMONTH.WasJustUpdated(algorithm.Time) &&
		            	MINUTE.WasJustUpdated(algorithm.Time) &&
		            	MONTH.WasJustUpdated(algorithm.Time)
	            	)
	            {

	            	DOWM_SYMBOL_DOWN_S2 = (algorithm.UtcTime.DayOfWeek == DayOfWeek.Monday);
					DOWT_SYMBOL_DOWN_S2 = (algorithm.UtcTime.DayOfWeek == DayOfWeek.Tuesday);
					DOWW_SYMBOL_DOWN_S2 = (algorithm.UtcTime.DayOfWeek == DayOfWeek.Wednesday);
					DOWTH_SYMBOL_DOWN_S2 = (algorithm.UtcTime.DayOfWeek == DayOfWeek.Thursday);
					
					DOWR_SYMBOL_DOWN_S2 = DOWM_SYMBOL_DOWN_S2 || DOWT_SYMBOL_DOWN_S2 || DOWW_SYMBOL_DOWN_S2 || DOWTH_SYMBOL_DOWN_S2 || algorithm.UtcTime.DayOfWeek == DayOfWeek.Friday;

					if (MINUTE.Symbol.Equals(SYMBOL) && MONTH.Symbol.Equals(SYMBOL) && ICHIWEEK.Symbol.Equals(SYMBOL) && ICHIMONTH.Symbol.Equals(SYMBOL)) 
			        {
	                    if (Base.SYMBOL_OCO1_DOWN_S2_IsReady == false)
	                    {
	                    	Base.SYMBOL_OCO1_DOWN_S2_Monthly_IsReady = false;
	                    }

	            		if (algorithm.Time == MONTH.B[0].EndTime)
                    	{
                    		Base.SYMBOL_OCO1_DOWN_S2_Monthly_IsReady = true;
                    	}
						
					Signal1:
					if (
							ICHIWEEK.Kijun[1] - ICHIWEEK.Kijun[0] > MINUTE.B[0].Close * 0.0008m 
		               )
	                    {
		                	SYMBOL_Signal_Condition_DOWN_1 = true ;
		                									    
		                	SYMBOL_DOWN_S2_SL_1 = (ICHIWEEK.Kijun[1] - ICHIWEEK.Kijun[0])*10;
		                	SYMBOL_DOWN_S2_TP1_1 = SYMBOL_DOWN_S2_SL_1 * 0.25m ;
	                    }
						
						if  (
								ICHIWEEK.Kijun[1] - ICHIWEEK.Kijun[0] < MINUTE.B[0].Close * 0.0008m
							)
							{
		                    	SYMBOL_Signal_Condition_DOWN_1 = false;
							}
	                
	                    
	                if (SYMBOL_Signal_Condition_DOWN_1 && 
	                    DOWR_SYMBOL_DOWN_S2 && 
	                    Base.SYMBOL_OCO1_DOWN_S2_IsReady == true)
	                    {
	                    	if (SYMBOL_DOWN_S2_SL_1 != 0)
		                	{
		                		SYMBOL_quantity_DOWN_S2_1 = -(int)Math.Floor(algorithm.Portfolio.GetBuyingPower(MINUTE.Symbol, 0))/((algorithm.Portfolio.Securities.Count()))*0.2m;
		                	}
		                	
	                    	SYMBOL_quantity_SL_DOWN_S2_1 = SYMBOL_quantity_DOWN_S2_1;
	                    	SYMBOL_quantity_TP1_DOWN_S2_1 = (int)Math.Floor(SYMBOL_quantity_DOWN_S2_1 * 1m);
	                    	
	                         Base.SYMBOL_OCO1_EO1_DOWN_S2 = true;
	                         yield return Insight.Price(MINUTE.Symbol, TimeSpan.FromMinutes(5), InsightDirection.Down, null, null, null, 1);
	                         SYMBOL_OCO1_MO1_DOWN_S2 = algorithm.MarketOrder(MINUTE.Symbol, SYMBOL_quantity_TP1_DOWN_S2_1, false,"SYMBOL_DOWN_S2_Entry_TP1_OCO1");
	                         Base.SYMBOL_OCO1_EO1_DOWN_S2 = false;

							Base.SYMBOL_OCO1_DOWN_S2_IsReady = false;
							
							if (Base.SYMBOL_OCO1_DOWN_S2_IsReady == false)
							break;
		
			            }

   
	                yield break;
	            	}
}}
	        	
	        }}}}
	
}}}
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
using QuantConnect.Indicators;
using QuantConnect.Orders;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Selection;

namespace QuantConnect
{   
    public partial class Base : QCAlgorithm
    {
		
		public static TimeSpan TSMINUTE = TimeSpan.FromMinutes(1);
        public static TimeSpan TSDAILY = TimeSpan.FromMinutes(1440);
        
        public static int RL1m = 2;  //3
        public static int RL1D = 4;  //9
        
        public static Dictionary<string, ICHIWEEK> DATICHIWEEK = new Dictionary<string, ICHIWEEK>();
        public static Dictionary<string, ICHIMONTH> DATICHIMONTH = new Dictionary<string, ICHIMONTH>();
        
        public static Dictionary<string, MINUTE> DATMINUTE = new Dictionary<string, MINUTE>();
        public static Dictionary<string, MONTH> DATMONTH = new Dictionary<string, MONTH>();

    	private SYMBOL_UP_S2_OnOrderEvent up_OnOrderEvent;
        private SYMBOL_DOWN_S2_OnOrderEvent down_OnOrderEvent;

        List<string> Pairs = new List<string>
        {
		 /*"EURUSD", "EURJPY", "EURAUD", "EURCHF", "EURGBP", "EURCAD", "EURNZD",
		 "USDJPY", "USDCAD", "USDCHF", "GBPUSD", "GBPCHF", "GBPJPY", "GBPCAD",
		 "GBPAUD", "CHFJPY", */"CADJPY"
        };

	    public override void Initialize()
	    {
	        SetStartDate(2007, 1, 1);
	        SetEndDate(DateTime.Now);
	        
	       // SetEndDate(2016, 1, 1);
	        
	        SetCash(1000000);
	        
	        Settings.RebalancePortfolioOnInsightChanges = false;
            Settings.RebalancePortfolioOnSecurityChanges = false;

	        SetBrokerageModel(BrokerageName.AlphaStreams);
	        
	        SetWarmup(3);

			foreach (var symbol in Pairs)
            {
            	var _symbol_D = AddForex(symbol, Resolution.Minute, Market.FXCM);
		        
		        DATICHIWEEK.Add(symbol, new ICHIWEEK(_symbol_D.Symbol, TSDAILY, RL1D));
		        DATICHIMONTH.Add(symbol, new ICHIMONTH(_symbol_D.Symbol, TSDAILY, RL1D));
		        
		        DATMINUTE.Add(symbol, new MINUTE(_symbol_D.Symbol, TSMINUTE, RL1m));
		        DATMONTH.Add(symbol, new MONTH(_symbol_D.Symbol, TSDAILY, RL1D));
            }

            up_OnOrderEvent = new SYMBOL_UP_S2_OnOrderEvent(this);
			down_OnOrderEvent = new SYMBOL_DOWN_S2_OnOrderEvent(this);

	        foreach (var kvp in DATICHIWEEK)
	        {
	            var ICHIWEEK = kvp.Value;
	            var cons_ichiweek = (IDataConsolidator)new QuoteBarConsolidator(CalendarTypee.Weekly);
	            ICHIWEEK.ichi = new IchimokuKinkoHyo(CreateIndicatorName(ICHIWEEK.Symbol, "ICHIW", Resolution.Daily), RL1D);

	            cons_ichiweek.DataConsolidated += (sender, baseData) =>
	            {
	                var bar = (QuoteBar)baseData;
	                ICHIWEEK.ichi.Update(bar);
	                ICHIWEEK.Kijun.Add(ICHIWEEK.ichi.Kijun.Current.Value);
	            };
	            SubscriptionManager.AddConsolidator(ICHIWEEK.Symbol, cons_ichiweek);
	        }
	          
	        foreach (var kvp in DATICHIMONTH)
	        {
	            var ICHIMONTH = kvp.Value;
	            var cons_ichimonth = (IDataConsolidator)new QuoteBarConsolidator(CalendarTypee.Monthly);
	            ICHIMONTH.ichi = new IchimokuKinkoHyo(CreateIndicatorName(ICHIMONTH.Symbol, "ICHIM", Resolution.Daily), RL1D);

	            cons_ichimonth.DataConsolidated += (sender, baseData) =>
	            {
	                var bar = (QuoteBar)baseData;
	                ICHIMONTH.ichi.Update(bar);
	                ICHIMONTH.Kijun.Add(ICHIMONTH.ichi.Kijun.Current.Value);
	            };
	            SubscriptionManager.AddConsolidator(ICHIMONTH.Symbol, cons_ichimonth);
	        }
			
			foreach (var kvp in DATMINUTE)
	        {   
	        	var MINUTE = kvp.Value;
	        	var cons_bar_minute = (IDataConsolidator)new QuoteBarConsolidator(TSMINUTE);  
				
	            cons_bar_minute.DataConsolidated += (sender, baseData) =>
	            {
	                var bar = (QuoteBar)baseData;
	                 MINUTE.B.Add(bar);
	            };
	            SubscriptionManager.AddConsolidator(MINUTE.Symbol, cons_bar_minute);
	        }
	        
	        foreach (var kvp in DATMONTH)
	        {   
	        	var MONTH = kvp.Value;
	        	var cons_bar_month = (IDataConsolidator)new QuoteBarConsolidator(TSDAILY);  
				
	            cons_bar_month.DataConsolidated += (sender, baseData) =>
	            {
	                var bar = (QuoteBar)baseData;
	                 MONTH.B.Add(bar);
	            };
	            SubscriptionManager.AddConsolidator(MONTH.Symbol, cons_bar_month);
	        }
	        
	        foreach (var ICHIMONTH in DATICHIMONTH.Values)
	        {
	        foreach (var ICHIWEEK in DATICHIWEEK.Values)
	        {
	        	PlotIndicator("ichi", ICHIWEEK.ichi, ICHIMONTH.ichi);
	        }}
	       
	          //AddAlpha(new Alpha_SYMBOL_UP_S2(_SYMBOL));
		      AddAlpha(new Alpha_SYMBOL_DOWN_S2(_SYMBOL)); 
	    }
	    
	    public override void OnOrderEvent(OrderEvent orderEvent)
	    {
			up_OnOrderEvent.OnOrderEvent(this, orderEvent);
	    	down_OnOrderEvent.OnOrderEvent(this, orderEvent);
	    }
	    
	    public void OnInsightsGeneratedVerifier(IAlgorithm algorithm, GeneratedInsightsCollection insightsCollection)
    	{
	        if  (
		        	insightsCollection.Insights.Count(insight => insight.Symbol.Value.Equals("GBPNZD")) != 1
	        	)
	        {
	            throw new Exception("Unexpected insights were emitted");
	        }
        }
    }
	
    
    public class ICHIWEEK
    {
        public readonly Symbol Symbol;
        public readonly TimeSpan TSDAILY;
        public IchimokuKinkoHyo ichi;
        public readonly RollingWindow<decimal> Kijun;


        public ICHIWEEK(Symbol symbol, TimeSpan tsdaily, int RL1D)
        {
            Symbol = symbol;
            TSDAILY = tsdaily;
            
            Kijun = new RollingWindow<decimal>(RL1D);
        }
        
        public bool BQIsReady
        {
            get { return	
            		Kijun.IsReady
            	;}
        }

        public bool WasJustUpdated(DateTime current)
        {
            return 
            	Kijun.Count > 0 
            ;
        }
    }
    
    public class ICHIMONTH
    {
        public readonly Symbol Symbol;
        public readonly TimeSpan TSDAILY;
        public IchimokuKinkoHyo ichi;
        public readonly RollingWindow<decimal> Kijun;


        public ICHIMONTH(Symbol symbol, TimeSpan tsdaily, int RL1D)
        {
            Symbol = symbol;
            TSDAILY = tsdaily;
            
            Kijun = new RollingWindow<decimal>(RL1D);
        }
        
        public bool BQIsReady
        {
            get { return	
            		Kijun.IsReady
            	;}
        }

        public bool WasJustUpdated(DateTime current)
        {
            return 
            	Kijun.Count > 0 
            ;
        }
    }
    
    public class MINUTE
    {
        public readonly Symbol Symbol;
        public readonly RollingWindow<QuoteBar> B;
        public readonly TimeSpan TSMINUTE;

        public MINUTE(Symbol symbol, TimeSpan tsminute,  int RL1m)
        {
            Symbol = symbol;
            TSMINUTE = tsminute;
            
            B = new RollingWindow<QuoteBar>(RL1m);
        }
        
        public bool BQIsReady
        {
            get { return	
            		B.IsReady 
            	;}
        }

        public bool WasJustUpdated(DateTime current)
        {
            return 
            	B.Count > 0 
            	&& 
            	B[0].Time > (current - TimeSpan.FromSeconds(5)) - TSMINUTE
            	&&
            	B[0].Time < (current + TimeSpan.FromSeconds(5)) - TSMINUTE
            ;
        }
    }
    
    public class MONTH
    {
        public readonly Symbol Symbol;
        public readonly RollingWindow<QuoteBar> B;
        public readonly TimeSpan TSDAILY;

        public MONTH(Symbol symbol, TimeSpan tsdaily,  int RL1D)
        {
            Symbol = symbol;
            TSDAILY = tsdaily;
            
            B = new RollingWindow<QuoteBar>(RL1D);
        }
        
        public bool BQIsReady
        {
            get { return	
            		B.IsReady 
            	;}
        }

        public bool WasJustUpdated(DateTime current)
        {
            return 
            	B.Count > 0 &&
            	B[0].EndTime > current - TimeSpan.FromSeconds(5)
            	
            ;
        }
    }
}
using QuantConnect.Securities;

namespace QuantConnect 
{
public partial class Base	///ONDATA
{
	public class Alpha_SYMBOL_UP_S2 : AlphaModel
    {   
    	private readonly Symbol _symbol;
    	
    	private string SYMBOL = "CADJPY" ;
   
        public Alpha_SYMBOL_UP_S2(Symbol symbol)
        {
            _symbol = symbol;
        }

		public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)
        {  
        	var open_orders = algorithm.Transactions.GetOpenOrders(x=>x.Status == OrderStatus.Submitted);
			
			if (!open_orders.Any())
			{
				algorithm.Liquidate();
			}
			
			if (!open_orders.Any(x=>x.Tag.Contains("SYMBOL_UP_S2_OCO1")))
			{
				Base.SYMBOL_OCO1_UP_S2_IsReady = true;
			}

			if (open_orders.Any(x=>x.Tag.Contains("SYMBOL_UP_S2")))
			{
				foreach (var order in open_orders)
			    {
					if (Base.SYMBOL_OCO1_EO1_UP_S2)
		                Base.SYMBOL_OCO1_EO1_UP_S2_ID = order.Id;
		
				        if (algorithm.UtcTime - order.CreatedTime >= TimeSpan.FromMinutes(Base.SYMBOL_UP_S2_OCO_DELAY_7DAY))
				        {
				        	int SYMBOL_OCO1S1_UP_S2 = 0;
			                for (; SYMBOL_OCO1S1_UP_S2 < Base.SYMBOL_UP_S2_OCO1Sets1.Count; SYMBOL_OCO1S1_UP_S2++)
			                    if (Base.SYMBOL_UP_S2_OCO1Sets1[SYMBOL_OCO1S1_UP_S2].InOrders(order.Id)) 
			                    {
			                        Base.SYMBOL_UP_S2_OCO1Sets1[SYMBOL_OCO1S1_UP_S2].TimeOut();
			                        yield return Insight.Price(SYMBOL, TimeSpan.FromMilliseconds(1001), InsightDirection.Down, null, null, null, 1);
			                        algorithm.MarketOrder(SYMBOL, order.Quantity, false, "SYMBOL_UP_S2_Entry_1__Time out_OCO1");
			                        Base.SYMBOL_UP_S2_OCO1Sets1.Clear();
			                        SYMBOL_OCO1S1_UP_S2 = 0;
			                        break;
			                    }
				        }
			    }
			}
			
			foreach (var MINUTE in DATMINUTE.Values)
	        {
	        foreach (var MONTH in DATMONTH.Values)
	        {
	        foreach (var ICHIWEEK in DATICHIWEEK.Values)
	        {
	        foreach (var ICHIMONTH in DATICHIMONTH.Values)
	        {
	            if (
	            		ICHIWEEK.BQIsReady &&
	            		ICHIMONTH.BQIsReady &&
	            		MINUTE.BQIsReady &&
		            	MONTH.BQIsReady &&
		            	ICHIWEEK.WasJustUpdated(algorithm.Time) &&
		            	ICHIMONTH.WasJustUpdated(algorithm.Time) &&
		            	MINUTE.WasJustUpdated(algorithm.Time) &&
		            	MONTH.WasJustUpdated(algorithm.Time)
	            	)
	            {

	            	DOWM_SYMBOL_UP_S2 = (algorithm.UtcTime.DayOfWeek == DayOfWeek.Monday);
					DOWT_SYMBOL_UP_S2 = (algorithm.UtcTime.DayOfWeek == DayOfWeek.Tuesday);
					DOWW_SYMBOL_UP_S2 = (algorithm.UtcTime.DayOfWeek == DayOfWeek.Wednesday);
					DOWTH_SYMBOL_UP_S2 = (algorithm.UtcTime.DayOfWeek == DayOfWeek.Thursday);
					
					DOWR_SYMBOL_UP_S2 = DOWM_SYMBOL_UP_S2 || DOWT_SYMBOL_UP_S2 || DOWW_SYMBOL_UP_S2 || DOWTH_SYMBOL_UP_S2 || algorithm.UtcTime.DayOfWeek == DayOfWeek.Friday;
	
					if (MINUTE.Symbol.Equals(SYMBOL) && MONTH.Symbol.Equals(SYMBOL) && ICHIWEEK.Symbol.Equals(SYMBOL) && ICHIMONTH.Symbol.Equals(SYMBOL)) 
			        {

	                    if (Base.SYMBOL_OCO1_UP_S2_IsReady == false)
	                    {
	                    	Base.SYMBOL_OCO1_UP_S2_Monthly_IsReady = false;
	                    }

	            		if (algorithm.Time == MONTH.B[0].EndTime)
                    	{
                    		Base.SYMBOL_OCO1_UP_S2_Monthly_IsReady = true;
                    	}
					
					Signal1:
					if (
						    ICHIWEEK.Kijun[0] - ICHIWEEK.Kijun[1] > MINUTE.B[0].Close * 0.0001m 
		               )
	                    {
		                	SYMBOL_Signal_Condition_UP_1 = true ;
		                									    
		                	SYMBOL_UP_S2_SL_1 = (ICHIWEEK.Kijun[0] - ICHIWEEK.Kijun[1])*50m;
		                	SYMBOL_UP_S2_TP1_1 = SYMBOL_UP_S2_SL_1 * 10m ;
	                    }
						
						if  (
								ICHIWEEK.Kijun[0] - ICHIWEEK.Kijun[1] < MINUTE.B[0].Close * 0.0001m
							)
							{
		                    	SYMBOL_Signal_Condition_UP_1 =	false;
							}
						

	                if (SYMBOL_Signal_Condition_UP_1 && 
	                    DOWR_SYMBOL_UP_S2 && 
	                    Base.SYMBOL_OCO1_UP_S2_IsReady == true &&
	                    Base.SYMBOL_OCO1_UP_S2_Monthly_IsReady == true)
	                    {
	                    	if (SYMBOL_UP_S2_SL_1 != 0)
		                	{
		                		SYMBOL_quantity_UP_S2_1 = (int)Math.Floor(algorithm.Portfolio.GetBuyingPower(MINUTE.Symbol, 0))/((algorithm.Portfolio.Securities.Count()))*0.2m;
		                	}
		                	
	                    	SYMBOL_quantity_SL_UP_S2_1 = SYMBOL_quantity_UP_S2_1;
	                    	SYMBOL_quantity_TP1_UP_S2_1 = (int)Math.Floor(SYMBOL_quantity_UP_S2_1 * 1m);
	                    	
	                         Base.SYMBOL_OCO1_EO1_UP_S2 = true;
	                         yield return Insight.Price(MINUTE.Symbol, TimeSpan.FromMinutes(5), InsightDirection.Up, null, null, null, 1);
	                         SYMBOL_OCO1_MO1_UP_S2 = algorithm.MarketOrder(MINUTE.Symbol, SYMBOL_quantity_TP1_UP_S2_1, false,"SYMBOL_UP_S2_Entry_TP1_OCO1");
	                         Base.SYMBOL_OCO1_EO1_UP_S2 = false;

							Base.SYMBOL_OCO1_UP_S2_IsReady = false;
							
							if (Base.SYMBOL_OCO1_UP_S2_IsReady == false)
							break;
		
			            }
	                yield break;
			        }
}}
	        	
	        }}}}
    	
    }}}
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
using QuantConnect.Indicators;
using QuantConnect.Orders;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Selection;

namespace QuantConnect
{   
    public partial class Base
    {
    	public static Symbol _SYMBOL;
		
    	///oco1 up
    	public static OrderTicket SYMBOL_OCO1_MO1_UP_S2;

    	
    	public static int SYMBOL_OCO1_EO1_UP_S2_ID ;

        
        public static bool SYMBOL_OCO1_EO1_UP_S2 ;

        
        public static Func<QCAlgorithm, string, decimal, decimal, SYMBOL_OCO1_UP_S2> SYMBOL_OOFE_OCO1_UP_S2_1 ;

        
        public static SYMBOL_OCO1_UP_S2 SYMBOL_PFO_OCO1_UP_S2_1 ;

        
        public static List<SYMBOL_OCO1_UP_S2> SYMBOL_UP_S2_OCO1Sets1 = new List<SYMBOL_OCO1_UP_S2>();
 
        
        public static bool SYMBOL_OCO1_UP_S2_IsReady = true;
        public static bool SYMBOL_OCO1_UP_S2_Monthly_IsReady = true;

        
        //oco1 down
		public static OrderTicket SYMBOL_OCO1_MO1_DOWN_S2 ;

    	
    	public static int SYMBOL_OCO1_EO1_DOWN_S2_ID ;

        
        public static bool SYMBOL_OCO1_EO1_DOWN_S2 ;

        
        public static Func<QCAlgorithm, string, decimal, decimal, SYMBOL_OCO1_DOWN_S2> SYMBOL_OOFE_OCO1_DOWN_S2_1 ;

        
        public static SYMBOL_OCO1_DOWN_S2 SYMBOL_PFO_OCO1_DOWN_S2_1 ;

        
        public static List<SYMBOL_OCO1_DOWN_S2> SYMBOL_DOWN_S2_OCO1Sets1 = new List<SYMBOL_OCO1_DOWN_S2>();

        
        public static bool SYMBOL_OCO1_DOWN_S2_IsReady = true;
        public static bool SYMBOL_OCO1_DOWN_S2_Monthly_IsReady = true;

////////////////////////////
		public static decimal SYMBOL_UP_S2_SL_1 {get; set;}
		public static decimal SYMBOL_UP_S2_TP1_1 {get; set;}

		public static decimal SYMBOL_DOWN_S2_SL_1 {get; set;}
		public static decimal SYMBOL_DOWN_S2_TP1_1 {get; set;}


        public static bool SYMBOL_Signal_Condition_UP_1 ;

        public static bool SYMBOL_Signal_Condition_DOWN_1 ;

        

        public static int SYMBOL_UP_S2_OCO_DELAY_7DAY = 43200;

		public static int SYMBOL_DOWN_S2_OCO_DELAY_7DAY = 43200;

		
		public static bool DOWR_SYMBOL_UP_S2 ;
        public static bool DOWM_SYMBOL_UP_S2 ;
        public static bool DOWT_SYMBOL_UP_S2 ;
        public static bool DOWW_SYMBOL_UP_S2 ;
        public static bool DOWTH_SYMBOL_UP_S2 ;
        
		public static bool DOWR_SYMBOL_DOWN_S2 ;
        public static bool DOWM_SYMBOL_DOWN_S2 ;
        public static bool DOWT_SYMBOL_DOWN_S2 ;
        public static bool DOWW_SYMBOL_DOWN_S2 ;
        public static bool DOWTH_SYMBOL_DOWN_S2 ;

        
		public static decimal SYMBOL_quantity_UP_S2_1 ;
		public static decimal SYMBOL_quantity_SL_UP_S2_1 ;
		public static decimal SYMBOL_quantity_TP1_UP_S2_1 ;

		
		public static decimal SYMBOL_quantity_DOWN_S2_1 ;
		public static decimal SYMBOL_quantity_SL_DOWN_S2_1 ;
		public static decimal SYMBOL_quantity_TP1_DOWN_S2_1 ;

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
using QuantConnect.Orders;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Selection;

namespace QuantConnect
{  	
	public struct SYMBOL_UP_S2_OnOrderEvent
	{
		private QCAlgorithm _algorithm;

		public SYMBOL_UP_S2_OnOrderEvent(QCAlgorithm algorithm)
		{
			_algorithm = algorithm;
		}

		public void OnOrderEvent(QCAlgorithm _algorithm, OrderEvent orderEvent)
		{
				var OrderID = _algorithm.Transactions.GetOrderById(orderEvent.OrderId);

				if (orderEvent.Status == OrderStatus.Filled)
		        {	
		        	if (OrderID.Tag.StartsWith("SYMBOL OCO1 CANCEL 1 UP S2") ||
		        		OrderID.Tag.StartsWith("SYMBOL OCO1 CANCEL 2 UP S2"))
		        	{ 
		        		_algorithm.MarketOrder(OrderID.Symbol, -OrderID.Quantity, false, "OrderID rescue SYMBOL S2");
		        	}
		        }
		        
				if (Base.SYMBOL_OCO1_EO1_UP_S2)
	                Base.SYMBOL_OCO1_EO1_UP_S2_ID = orderEvent.OrderId;

		        if (orderEvent.Status == OrderStatus.Filled || orderEvent.Status == OrderStatus.PartiallyFilled)
		        {	
		            if (orderEvent.OrderId == Base.SYMBOL_OCO1_EO1_UP_S2_ID)
	                {
	                	Base.SYMBOL_OOFE_OCO1_UP_S2_1 = (algo1, symbol, filledPrice, fillQ) =>
		                {
		                    return new SYMBOL_OCO1_UP_S2(
		                        algo1.LimitOrder(orderEvent.Symbol,  -orderEvent.Quantity,  orderEvent.FillPrice + Base.SYMBOL_UP_S2_TP1_1,"TP1_SYMBOL_UP_S2_OCO1"),
		                        algo1.StopMarketOrder(orderEvent.Symbol,  -orderEvent.Quantity,  orderEvent.FillPrice - Base.SYMBOL_UP_S2_SL_1,"SL_TP1_SYMBOL_UP_S2_OCO1"));
		                 };
		                Base.SYMBOL_UP_S2_OCO1Sets1.Add( Base.SYMBOL_OOFE_OCO1_UP_S2_1(_algorithm, orderEvent.Symbol, orderEvent.FillPrice, orderEvent.Quantity));
	                    Base.SYMBOL_OCO1_EO1_UP_S2_ID = -1;
	                }

	                
	                int SYMBOL_OCO1S1_UP_S2 = 0;
	                for (; SYMBOL_OCO1S1_UP_S2 < Base.SYMBOL_UP_S2_OCO1Sets1.Count; SYMBOL_OCO1S1_UP_S2++)
	                    if (Base.SYMBOL_UP_S2_OCO1Sets1[SYMBOL_OCO1S1_UP_S2].InOrders(orderEvent.OrderId)) 
	                    {
	                        Base.SYMBOL_UP_S2_OCO1Sets1[SYMBOL_OCO1S1_UP_S2].Filled();
	                        Base.SYMBOL_UP_S2_OCO1Sets1.RemoveAt(SYMBOL_OCO1S1_UP_S2);
	                        SYMBOL_OCO1S1_UP_S2 = 0;
	                        break;
	                    }
		        }
		}
	}
}
using System.Linq;
using System.Collections.Generic;
using QuantConnect.Orders;
using NodaTime;
using NodaTime.TimeZones;

namespace QuantConnect 
{
    public struct SYMBOL_OCO1_DOWN_S2
    {
        public SYMBOL_OCO1_DOWN_S2(params OrderTicket[] orderTickets)
        {
            this.OrderTickets = orderTickets;
        }

        private OrderTicket[] OrderTickets { get; set; }

        public void Filled()
        {
        	
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTickets)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_DOWN_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_DOWN_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 1 DOWN S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_DOWN_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_DOWN_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 2 DOWN S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_DOWN_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_DOWN_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 3 DOWN S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_DOWN_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_DOWN_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 4 DOWN S2");
                	}
                }
            }
        }
        
        public void TimeOut()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTickets)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_DOWN_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_DOWN_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 1 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_DOWN_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_DOWN_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 2 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_DOWN_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_DOWN_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 3 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_DOWN_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_DOWN_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 4 DOWN S2 TIMEOUT");
                	}
                }
            }
        }

        public bool InOrders(int orderId)
        {
            foreach (var orderTicket in this.OrderTickets)
                if (orderTicket.OrderId == orderId)
                    return true;
            return false;
        }
    }
    
    public struct SYMBOL_OCO1_UP_S2
    {
        public SYMBOL_OCO1_UP_S2(params OrderTicket[] orderTicketsUp)
        {
            this.OrderTicketsUp = orderTicketsUp;
        }

        private OrderTicket[] OrderTicketsUp { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsUp)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_UP_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_UP_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 1 UP S2");
                	}

                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_UP_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_UP_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 2 UP S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_UP_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_UP_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 3 UP S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_UP_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_UP_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 4 UP S2");
                	}
                }
            }
        }

        public void TimeOut()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsUp)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_UP_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_UP_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 1 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_UP_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_UP_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 2 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_UP_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_UP_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 3 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_UP_S2_OCO1" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_UP_S2_OCO1"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 4 UP S2 TIMEOUT");
                	}
                }
            }
        }

        public bool InOrders(int orderId)
        {
            foreach (var orderTicket in this.OrderTicketsUp)
                if (orderTicket.OrderId == orderId)
                    return true;
            return false;
        }
    }
    
    public struct SYMBOL_OCO2_DOWN_S2
    {
        public SYMBOL_OCO2_DOWN_S2(params OrderTicket[] orderTicketsDown)
        {
            this.OrderTicketsDown = orderTicketsDown;
        }

        private OrderTicket[] OrderTicketsDown { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsDown)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_DOWN_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_DOWN_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 1 DOWN S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_DOWN_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_DOWN_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 2 DOWN S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_DOWN_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_DOWN_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 3 DOWN S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_DOWN_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_DOWN_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 4 DOWN S2");
                	}
                }
            }
        }
        
        public void TimeOut()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsDown)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_DOWN_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_DOWN_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 1 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_DOWN_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_DOWN_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 2 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_DOWN_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_DOWN_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 3 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_DOWN_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_DOWN_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO1 CANCEL 4 DOWN S2 TIMEOUT");
                	}
                }
            }
        }

        public bool InOrders(int orderId)
        {
            foreach (var orderTicket in this.OrderTicketsDown)
                if (orderTicket.OrderId == orderId)
                    return true;
            return false;
        }
    }
    
    public struct SYMBOL_OCO2_UP_S2
    {
        public SYMBOL_OCO2_UP_S2(params OrderTicket[] orderTicketsUp)
        {
            this.OrderTicketsUp = orderTicketsUp;
        }

        private OrderTicket[] OrderTicketsUp { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsUp)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_UP_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_UP_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 1 UP S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_UP_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_UP_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 2 UP S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_UP_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_UP_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 3 UP S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_UP_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_UP_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 4 UP S2");
                	}
                }
            }
        }
        
        public void TimeOut()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsUp)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_UP_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_UP_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 1 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_UP_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_UP_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 2 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_UP_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_UP_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 3 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_UP_S2_OCO2" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_UP_S2_OCO2"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO2 CANCEL 4 UP S2 TIMEOUT");
                	}
                }
            }
        }

        public bool InOrders(int orderId)
        {
            foreach (var orderTicket in this.OrderTicketsUp)
                if (orderTicket.OrderId == orderId)
                    return true;
            return false;
        }
    }
    
    public struct SYMBOL_OCO3_DOWN_S2
    {
        public SYMBOL_OCO3_DOWN_S2(params OrderTicket[] orderTicketsDown)
        {
            this.OrderTicketsDown = orderTicketsDown;
        }

        private OrderTicket[] OrderTicketsDown { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsDown)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_DOWN_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_DOWN_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 1 DOWN S2");
                		
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_DOWN_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_DOWN_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 2 DOWN S2");
                    	
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_DOWN_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_DOWN_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 3 DOWN S2");
                    	
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_DOWN_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_DOWN_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 4 DOWN S2");
                    	
                	}
                }
            }
        }
        
        public void TimeOut()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsDown)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_DOWN_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_DOWN_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 1 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_DOWN_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_DOWN_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 2 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_DOWN_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_DOWN_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 3 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_DOWN_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_DOWN_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 4 DOWN S2 TIMEOUT");
                	}
                }
            }
        }

        public bool InOrders(int orderId)
        {
            foreach (var orderTicket in this.OrderTicketsDown)
                if (orderTicket.OrderId == orderId)
                    return true;
            return false;
        }
    }
    
    public struct SYMBOL_OCO3_UP_S2
    {
        public SYMBOL_OCO3_UP_S2(params OrderTicket[] orderTicketsUp)
        {
            this.OrderTicketsUp = orderTicketsUp;
        }

        private OrderTicket[] OrderTicketsUp { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsUp)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {

                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_UP_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_UP_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 1 UP S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_UP_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_UP_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 2 UP S2");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_UP_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_UP_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 3 UP S2");

                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_UP_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_UP_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 4 UP S2");
                	}
                }
            }
        }
        
        public void TimeOut()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsUp)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_UP_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_UP_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 1 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_UP_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_UP_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 2 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_UP_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_UP_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 3 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_UP_S2_OCO3" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_UP_S2_OCO3"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO3 CANCEL 4 UP S2 TIMEOUT");
                	}
                }
            }
        }

        public bool InOrders(int orderId)
        {
            foreach (var orderTicket in this.OrderTicketsUp)
                if (orderTicket.OrderId == orderId)
                    return true;
            return false;
        }
    }
    
    public struct SYMBOL_OCO4_DOWN_S2
    {
        public SYMBOL_OCO4_DOWN_S2(params OrderTicket[] orderTicketsDown)
        {
            this.OrderTicketsDown = orderTicketsDown;
        }

        private OrderTicket[] OrderTicketsDown { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsDown)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_DOWN_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_DOWN_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 1 DOWN S2");
                		
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_DOWN_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_DOWN_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 2 DOWN S2");
                    	
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_DOWN_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_DOWN_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 3 DOWN S2");
                    	
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_DOWN_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_DOWN_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 4 DOWN S2");
                    	
                	}
                }
            }
        }
        
        public void TimeOut()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsDown)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_DOWN_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_DOWN_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 1 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_DOWN_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_DOWN_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 2 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_DOWN_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_DOWN_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 3 DOWN S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_DOWN_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_DOWN_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 4 DOWN S2 TIMEOUT");
                	}
                }
            }
        }

        public bool InOrders(int orderId)
        {
            foreach (var orderTicket in this.OrderTicketsDown)
                if (orderTicket.OrderId == orderId)
                    return true;
            return false;
        }
    }
    
    public struct SYMBOL_OCO4_UP_S2
    {
        public SYMBOL_OCO4_UP_S2(params OrderTicket[] orderTicketsUp)
        {
            this.OrderTicketsUp = orderTicketsUp;
        }

        private OrderTicket[] OrderTicketsUp { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsUp)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_UP_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_UP_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 1 UP S2");
                    	
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_UP_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_UP_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 2 UP S2");

                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_UP_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_UP_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 3 UP S2");

                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_UP_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_UP_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 4 UP S2");

                	}
                }
            }
        }
        
        public void TimeOut()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTicketsUp)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                	if(orderTicket.Tag.StartsWith("TP1_SYMBOL_UP_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP1_SYMBOL_UP_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 1 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP2_SYMBOL_UP_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP2_SYMBOL_UP_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 2 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP3_SYMBOL_UP_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP3_SYMBOL_UP_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 3 UP S2 TIMEOUT");
                	}
                	
                	if(orderTicket.Tag.StartsWith("TP4_SYMBOL_UP_S2_OCO4" ) || orderTicket.Tag.StartsWith("SL_TP4_SYMBOL_UP_S2_OCO4"))
                	{
                    	orderTicket.Cancel("SYMBOL OCO4 CANCEL 4 UP S2 TIMEOUT");
                	}
                }
            }
        }

        public bool InOrders(int orderId)
        {
            foreach (var orderTicket in this.OrderTicketsUp)
                if (orderTicket.OrderId == orderId)
                    return true;
            return false;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
using QuantConnect.Orders;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Selection;

namespace QuantConnect
{  	
	public struct SYMBOL_DOWN_S2_OnOrderEvent
	{
		private QCAlgorithm _algorithm;

		public SYMBOL_DOWN_S2_OnOrderEvent(QCAlgorithm algorithm)
		{
			_algorithm = algorithm;
		}

		public void OnOrderEvent(QCAlgorithm _algorithm, OrderEvent orderEvent)
		{
				var OrderID = _algorithm.Transactions.GetOrderById(orderEvent.OrderId);
				
				if (orderEvent.Status == OrderStatus.Filled)
		        {	
		        	if (OrderID.Tag.StartsWith("SYMBOL OCO1 CANCEL 1 DOWN S2") || 
		        		OrderID.Tag.StartsWith("SYMBOL OCO1 CANCEL 2 DOWN S2"))
		        	{ 
		        		_algorithm.MarketOrder(OrderID.Symbol, -OrderID.Quantity, false, "OrderID rescue SYMBOL S2");
		        	}
		        }
		        
				if (Base.SYMBOL_OCO1_EO1_DOWN_S2)
	                Base.SYMBOL_OCO1_EO1_DOWN_S2_ID = orderEvent.OrderId;
	        	
		        if (orderEvent.Status == OrderStatus.Filled || orderEvent.Status == OrderStatus.PartiallyFilled)
		        {	
		            if (orderEvent.OrderId == Base.SYMBOL_OCO1_EO1_DOWN_S2_ID)
	                {
	                	Base.SYMBOL_OOFE_OCO1_DOWN_S2_1 = (algo1, symbol, filledPrice, fillQ) =>
		                {
		                    return new SYMBOL_OCO1_DOWN_S2(
		                        algo1.StopMarketOrder(orderEvent.Symbol,  -orderEvent.Quantity,  orderEvent.FillPrice + Base.SYMBOL_DOWN_S2_SL_1,"SL_TP1_SYMBOL_DOWN_S2_OCO1"),
		                        algo1.LimitOrder(orderEvent.Symbol,  -orderEvent.Quantity,  orderEvent.FillPrice - Base.SYMBOL_DOWN_S2_TP1_1,"TP1_SYMBOL_DOWN_S2_OCO1"));
		                 };
		                Base.SYMBOL_DOWN_S2_OCO1Sets1.Add( Base.SYMBOL_OOFE_OCO1_DOWN_S2_1(_algorithm, orderEvent.Symbol, orderEvent.FillPrice, orderEvent.Quantity));
	                    Base.SYMBOL_OCO1_EO1_DOWN_S2_ID = -1;
	                }

	                int SYMBOL_OCO1S1_DOWN_S2 = 0;
	                for (; SYMBOL_OCO1S1_DOWN_S2 < Base.SYMBOL_DOWN_S2_OCO1Sets1.Count; SYMBOL_OCO1S1_DOWN_S2++)
	                    if (Base.SYMBOL_DOWN_S2_OCO1Sets1[SYMBOL_OCO1S1_DOWN_S2].InOrders(orderEvent.OrderId)) 
	                    {
	                        Base.SYMBOL_DOWN_S2_OCO1Sets1[SYMBOL_OCO1S1_DOWN_S2].Filled();
	                        Base.SYMBOL_DOWN_S2_OCO1Sets1.RemoveAt(SYMBOL_OCO1S1_DOWN_S2);
	                        SYMBOL_OCO1S1_DOWN_S2 = 0;
	                        break;
	                    }

		        }
		}
	}
}
using System;

namespace QuantConnect.Data.Consolidators
{
    [Obsolete("CalendarType is obsolete, please use Calendar instead")]
    public static class CalendarTypee
    {
        /// <summary>
        /// Computes the start of week (previous Monday) of given date/time
        /// </summary>
        public static Func<DateTime, CalendarInfo> Weekly => Calendar.Weekly;

        /// <summary>
        /// Computes the start of month (1st of the current month) of given date/time
        /// </summary>
        public static Func<DateTime, CalendarInfo> Monthly => Calendar.Monthly;
        
        public static Func<DateTime, CalendarInfo> Yearly => Calendar.Yearly;
        
        public static Func<DateTime, CalendarInfo> Quarterly => Calendar.Quarterly;
    }
}