Overall Statistics
Total Orders
199
Average Win
5.76%
Average Loss
-2.85%
Compounding Annual Return
6.997%
Drawdown
42.100%
Expectancy
0.314
Start Equity
100000
End Equity
186801.39
Net Profit
86.801%
Sharpe Ratio
0.245
Sortino Ratio
0.173
Probabilistic Sharpe Ratio
0.560%
Loss Rate
57%
Win Rate
43%
Profit-Loss Ratio
2.03
Alpha
0.033
Beta
0.232
Annual Standard Deviation
0.208
Annual Variance
0.043
Information Ratio
-0.115
Tracking Error
0.235
Treynor Ratio
0.219
Total Fees
$3256.30
Estimated Strategy Capacity
$360000000.00
Lowest Capacity Asset
NVDA RHM8UTD8DT2D
Portfolio Turnover
4.35%
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using QuantConnect.Algorithm.Selection;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Positions;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion


namespace QuantConnect.Algorithm.CSharp
{
    public class CMFAlphaModel : AlphaModel
    {
        int period = 21;
        Dictionary<Symbol, ChaikinMoneyFlow> _dict = new Dictionary<Symbol, ChaikinMoneyFlow>();

        public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
        {
            foreach (var security in changes.AddedSecurities)
            {
                var symbol = security.Symbol;
                _dict.Add(symbol, algorithm.CMF(symbol, period, Resolution.Daily));
            }
        }
        
        public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data) 
        {
            var timeSpanPeriod = TimeSpan.FromDays(3);

            // if already triggered Insight within time span period and it presents in the portfolio
            var alreadyTriggered = algorithm.Insights
                .Any(c => algorithm.Portfolio.Any(x => x.Key == c.Symbol)
                    && algorithm.UtcTime > c.GeneratedTimeUtc 
                    && algorithm.UtcTime < c.GeneratedTimeUtc.Add(timeSpanPeriod));

            if (alreadyTriggered)
            {
                return Enumerable.Empty<Insight>();
            }            

            var stocksForBuying = _dict
                .Where(c => c.Value.IsReady)
                .Where(c => c.Value.Current.Value >= 0.2m)
                .Select(c => Insight.Price(c.Key, timeSpanPeriod, InsightDirection.Up))
                .ToList();

            var stocksForSelling = _dict            
                .Where(c => c.Value.IsReady)
                .Where(c => c.Value.Current.Value <= -0.2m)
                .Select(c => Insight.Price(c.Key, timeSpanPeriod, InsightDirection.Down))
                .ToList();

            var signals = new List<Insight>();
            signals.AddRange(stocksForBuying);
            signals.AddRange(stocksForSelling);

            if (signals.Count == 0)
            {
                return Enumerable.Empty<Insight>();
            }

            return Insight.Group(signals.ToArray());
        }
    }
}


#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Algorithm.Selection;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion
namespace QuantConnect.Algorithm.CSharp
{
    public class RetrospectiveApricotElephant : QCAlgorithm
    {
        public override void Initialize()
        {
            SetStartDate(2015, 1, 1);
            SetCash(100000);

            this.UniverseSettings.Resolution = Resolution.Hour;

            AddUniverseSelection(new StockUniverseSelectionModel());
            AddAlpha(new CMFAlphaModel());
            SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); 
            SetExecution(new ImmediateExecutionModel());
            // SetExecution(new ScheduledExecutionModel(TimeSpan.FromHours(15))); // at 3PM
        }
    }
}
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Algorithm.Selection;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion


namespace QuantConnect.Algorithm.CSharp {
    public class ScheduledExecutionModel : ExecutionModel
    {
        private readonly TimeSpan _triggerTime;

        public ScheduledExecutionModel(TimeSpan triggerTime)
        {
            _triggerTime = triggerTime;
        }


        public override void Execute(QCAlgorithm algorithm, IPortfolioTarget[] targets)
        {
            foreach (var target in targets.OrderTargetsByMarginImpact(algorithm))
            {
                var security = algorithm.Securities[target.Symbol];

                // calculate remaining quantity to be ordered
                var quantity = OrderSizing.GetUnorderedQuantity(algorithm, target, security);
                if (quantity != 0)
                {
                    if (security.BuyingPowerModel.AboveMinimumOrderMarginPortfolioPercentage(security, quantity,
                        algorithm.Portfolio, algorithm.Settings.MinimumOrderMarginPortfolioPercentage))
                    {
                        algorithm.Schedule.On(algorithm.DateRules.Today, algorithm.TimeRules.At(_triggerTime), 
                            () => algorithm.MarketOrder(security, quantity));                            
                    }
                    else if (!PortfolioTarget.MinimumOrderMarginPercentageWarningSent.HasValue)
                    {
                        // will trigger the warning if it has not already been sent
                        PortfolioTarget.MinimumOrderMarginPercentageWarningSent = false;
                    }
                }
            }
        }
    }
}
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using QuantConnect.Algorithm.Selection;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Positions;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion

namespace QuantConnect.Algorithm.CSharp {
    public class StockUniverseSelectionModel : ManualUniverseSelectionModel
    {
        public StockUniverseSelectionModel()
            : base(SelectSymbols()) { }

        public static IEnumerable<Symbol> SelectSymbols()
        {
            // // var tickers = new[] { "NVDA", "MMM", "ABBV", "MSFT", "TSLA", "COIN", "V", "NFLX", "MCD" };
            var tickers = new[] {"NVDA"};
            return tickers.Select(ticker => QuantConnect.Symbol.Create(ticker, SecurityType.Equity, Market.USA));
        }
    }
}