Overall Statistics
Total Trades
1
Average Win
67.21%
Average Loss
0%
Compounding Annual Return
29.325%
Drawdown
14.900%
Expectancy
0
Net Profit
67.21%
Sharpe Ratio
1.503
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.031
Beta
1.453
Annual Standard Deviation
0.182
Annual Variance
0.033
Information Ratio
0.665
Tracking Error
0.097
Treynor Ratio
0.188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QuantConnect;
using QuantConnect.Algorithm;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;

namespace Sandbox
{
    public class Jagtar : QCAlgorithm
    {
        public const string Symbol = "SPY";
        public IndicatorBase<IndicatorDataPoint> avg;
        public IndicatorBase<IndicatorDataPoint> mom;
        public IndicatorBase<IndicatorDataPoint> avgOfMomentum; 

        public override void Initialize()
        {
            SetStartDate(2013, 01, 01);
            SetEndDate(2015, 01, 01);

            AddSecurity(SecurityType.Equity, Symbol, Resolution.Minute);

            // define the indicator pieces individually
            MovingAverageType type = MovingAverageType.Exponential;
            avg = type.AsIndicator(30);
            mom = type.AsIndicator(5).Of(new MomentumPercent(45), "Smoothed Momentum(60)");

            // compose them together using the Of extension method
            avgOfMomentum = avg.Of(mom, "Momentum Of SMA");

            // when pumping data in, you only need data to go into the 'composed' indicator, in this case,
            // the momentumOfSma and it will automatically update its child indicators (sma, mom)

            // update the indicator manually like this in OnData method if you don't want auto updates
            //momentumOfSma.Update(time, value);

            // register the indicator for automatic updates
            RegisterIndicator(Symbol, avgOfMomentum, Resolution.Daily, data => data.Value);
        }

        decimal threshold = 0.015m;
        public void OnData(TradeBars data)
        {
            if (!avgOfMomentum.IsReady) return;
            
            if (Portfolio[Symbol].Quantity < 1 && avg > threshold)
            {
                SetHoldings(Symbol, 1.0);
            }
            else if (Portfolio[Symbol].Quantity > -1 && avg < -threshold)
            {
                SetHoldings(Symbol, -1.0);
            }
        }

        public override void OnEndOfDay()
        {
            if (!avgOfMomentum.IsReady) return;
            
            Plot(Symbol, "Price", Securities[Symbol].Price);
            Plot(Symbol, "Mom", Securities[Symbol].Price + 100m*mom);
            Plot(Symbol, "AvgMom", Securities[Symbol].Price + 100m*avg);
            
            // scale our momentum percentage by a factor of 100
            Plot(Symbol + "_mom", "Momentum%",     100m*mom);
            Plot(Symbol + "_mom", "SMA Momentum%", 100m*avgOfMomentum);
        }
    }
}