Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
namespace QuantConnect.Algorithm.CSharp
{
    public class ResistanceNadionCoreWave : QCAlgorithm
    {
    	private Dictionary<Symbol, TradeBar> MyStocks = new Dictionary<Symbol, TradeBar>();

        public override void Initialize()
        {
            SetStartDate(2018, 1, 1);  //Set Start Date
            SetCash(5000);             //Set Strategy Cash
            
            // AddEquity("SPY", Resolution.Minute);
			AddUniverse(CoarseSelectionFilter);
			UniverseSettings.Resolution = Resolution.Minute;
			UniverseSettings.Leverage = 2;
			
			Schedule.On(DateRules.Every(DayOfWeek.Friday), TimeRules.At(11,30), CloseAllPositions);
        }

        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// Slice object keyed by symbol containing the stock data
        public override void OnData(Slice data)
        {
        	foreach(var security in MyStocks)
        	{
        		continue;
        		var symbol = security.Key;
        		
        		if((Portfolio.ContainsKey(symbol) && !Portfolio[symbol].Invested) && MyStocks.ContainsKey(symbol))
        		{
        			Log("Not invested in " + security.Key + " and Consolidator set");
        			
        			if(data[symbol.Value].Close > security.Value.High)
        			{
        				SetHoldings(symbol, 0.1m);
        				Log("Long: " + symbol);
        			}
        			if(data[symbol.Value].Close < security.Value.Low)
        			{
        				SetHoldings(symbol, -0.1m);
        				Log("Short: " + symbol);
        			}
        		}
        	}
        	
        }
        
        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
        	foreach(var security in changes.AddedSecurities)
        	{
        		var symbol = security.Symbol;
        		
        		if(!MyStocks.ContainsKey(symbol))
        		{
        			MyStocks.Add(symbol, null);
					Consolidate(security.Symbol, TimeSpan.FromMinutes(30), OnDataConsolidation);
        		}
        	}
        	
        	foreach(var security in changes.RemovedSecurities)
        	{
        		MyStocks.Remove(security.Symbol.Value);
        	}
        }
        
        private void OnDataConsolidation(TradeBar bar)
        {
        	if(bar.Time.Hour == 9 && bar.Time.Minute == 30)
        	{
        		MyStocks[bar.Symbol.Value] = bar;
        	}
        }
        
        private void CloseAllPositions()
        {
        	foreach(var security in Securities)
        	{
        		Liquidate(security.Key);
        		MyStocks[security.Key] =null;
        	}
        }
        
        public IEnumerable<Symbol> CoarseSelectionFilter(IEnumerable<CoarseFundamental> coarse)
        {	
        	var sortedByDollarVolume = coarse.OrderByDescending(x => x.DollarVolume);
        	var filteredByPrice = sortedByDollarVolume.Where(x => x.Price > 10).Select(x => x.Symbol);
        	filteredByPrice = filteredByPrice.Take(10);
        	return filteredByPrice;
        }

    }
}