Overall Statistics
Total Trades
161
Average Win
0.83%
Average Loss
-0.66%
Compounding Annual Return
-2.152%
Drawdown
4.900%
Expectancy
0.312
Net Profit
-0.247%
Sharpe Ratio
-0.662
Probabilistic Sharpe Ratio
29.064%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
1.27
Alpha
-0.436
Beta
1.933
Annual Standard Deviation
0.201
Annual Variance
0.04
Information Ratio
-2.894
Tracking Error
0.1
Treynor Ratio
-0.069
Total Fees
$161.00
Estimated Strategy Capacity
$6600000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Securities;
using static System.DateTime;
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
using QuantConnect.Securities.Equity;
using QuantConnect.Interfaces;



namespace QuantConnect
{
    /// <summary>
    /// Basic template algorithm simply initializes the date range and cash
    /// </summary>
    public class DailyIdentityAlgorithm : QCAlgorithm
    {


        decimal initial_cash = 10000;
        
       
        
        ////////////////////////////////////// SPY VARIABLES //////////////////////////////////////////////////
        private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
        private SimpleMovingAverage _sma_SPY;
        private Identity _identity_spy;
        private decimal highOfTheDaySpy=0;
        private RollingWindow<decimal> SPY_trailing;

        
        private bool trade=false;
       


        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        public override void Initialize()
        {
            SetStartDate(2020, 11 ,24);   //Set Start Date
            SetEndDate(2021, 12, 27);       //Set End Date
            initial_cash = 10000;
            SetCash(initial_cash);   


            
   //////////////////////// Manual Universe Selection ///////////////////////////////////////////////////////////////       
            
            ////////////////////////////////////// SPY VARIABLES INITIALIZATION //////////////////////////////////////////////////
            AddEquity("SPY", Resolution.Minute);
            _sma_SPY = SMA("SPY", 60, Resolution.Daily, x => ((TradeBar)x).Volume);
            _identity_spy = Identity("SPY", Resolution.Daily, Field.High);
             SPY_trailing = new RollingWindow<decimal>(20);


            
            
            

 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
        
            
            // schedule an event to fire every trading day for a security
            // the time rule here tells it to fire 10 minutes before SPY's market close
            bool liquidate = Convert.ToBoolean(GetParameter("liquidate"));
            if (liquidate = true){
            Schedule.On(DateRules.EveryDay("SPY"), TimeRules.BeforeMarketClose("SPY", 10), () => //Don't have to change it for  every instrument in the portfolio
             {
            	Liquidate();//Liquidate entire portfolio
             });
            
            }
            
           
            

        }//closes initialize
        
        
    
        
        

        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">Slice object keyed by symbol containing the stock data</param>
        public override void OnData(Slice data)
        {
         TradeBars bars = data.Bars;
   
        //////////////////////////// SPY BLOCK ///////////////////////////////////////////////////
        
         if (Portfolio["SPY"].Invested==true){ //block for trailing st
         	SPY_trailing.Add(Securities["SPY"].Holdings.UnrealizedProfit);
         	var SPY_trailing_list = new List<Decimal>(20);
            SPY_trailing_list.AddRange(SPY_trailing);
            //var max = SPY_trailing_list.GetRange(20, 20).Max();
            Debug("Max unrealized profit");
            //Debug(max);
         }
       

         if (data.Bars.ContainsKey("SPY") ){
         	
         	 
           	  var ticket = LimitOrder("SPY", 10, 5000);  
           	    
         	    
         	   
         }
         

        }//closes OnData
	    
    }
        	
}