Overall Statistics
Total Trades
438
Average Win
0.10%
Average Loss
-0.21%
Compounding Annual Return
-46.509%
Drawdown
27.000%
Expectancy
-0.689
Net Profit
-26.795%
Sharpe Ratio
-3.365
Probabilistic Sharpe Ratio
0.001%
Loss Rate
79%
Win Rate
21%
Profit-Loss Ratio
0.48
Alpha
-0.4
Beta
0.011
Annual Standard Deviation
0.119
Annual Variance
0.014
Information Ratio
-1.393
Tracking Error
0.218
Treynor Ratio
-36.726
Total Fees
$458.09
namespace QuantConnect.Algorithm.CSharp
{
    public class PStocks : QCAlgorithm
    {
    	//Vars
    	SecurityChanges _changes = SecurityChanges.None;
    	//---------------------------------------------------------------------
    	//Current Stop Loss & Take Profit Orders
    	//List<SL_Order> _orders;
    	//---------------------------------------------------------------------
    	//Const Vars
    	const decimal _cash = 10000;
    	const Resolution _res = Resolution.Daily;
    	const int _stopLossPercent = 1;
    	const int _takeProfitPercent = 2;
    	const int _numberOfSymbols = 10;
    	const decimal _priceLimit = 10;
    	//---------------------------------------------------------------------
    	
        public override void Initialize()
        {
            SetStartDate(2010, 1, 1);
            SetEndDate(2010, 7, 1);
            SetCash(_cash);
            
            //_orders = new List<SL_Order>(_numberOfSymbols);
            
            UniverseSettings.Resolution = _res;
            UniverseSettings.Leverage = 1m;
            AddUniverse(CoarseSelectionFilter);
            SetSecurityInitializer(s => s.SetMarketPrice(GetLastKnownPrice(s)));
        }

        public void OnData(TradeBars data)
        {
        	if(_changes == SecurityChanges.None) return;
        	
        	var cashPerSymbol = (int)Math.Floor(Portfolio.Cash * 0.9m) / _numberOfSymbols;
        	
        	foreach (var security in _changes.RemovedSecurities)
            {
                if (security.Invested)
                {
                    Liquidate(security.Symbol);
                }
            }
    		foreach (var security in _changes.AddedSecurities)
    		{
    			var symbol = security.Symbol;
    			var currentPrice = security.Close;
    			if (currentPrice == 0)
    			{
    				continue;
    			}
    			Debug($"Security Symbol: {symbol}, Price: {currentPrice}");
    			var shares = (int)Math.Floor(cashPerSymbol / currentPrice);
    			var StopLimitOrderID = StopLimitOrder(symbol, shares, currentPrice - (currentPrice * _stopLossPercent / 100), currentPrice + (currentPrice * _takeProfitPercent / 100));
				//_orders.Add(new SL_Order(StopLimitOrderID));
    		}
    		
    		_changes = SecurityChanges.None;
        }
        
        public IEnumerable<Symbol> CoarseSelectionFilter(IEnumerable<CoarseFundamental> coarse)
        {	
        	var sortedByDollarVolume = coarse.OrderByDescending(x => x.DollarVolume);
        	var top = sortedByDollarVolume.Where(x => x.Price < _priceLimit && x.Price > 0).Take(_numberOfSymbols);
        	return top.Select(x => x.Symbol);
        }
        
        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
            _changes = changes;
            Log($"OnSecuritiesChanged({UtcTime:o}):: {changes}");
        }
        
        public override void OnOrderEvent(OrderEvent fill)
		{
			Log($"OnOrderEvent({UtcTime:o}):: {fill}");
		}
		
		public override void OnEndOfDay()
		{
			
		}
    }
}