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
Probabilistic 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
-6.66
Tracking Error
0.087
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
from datetime import timedelta
from QuantConnect import Market, Resolution, SecurityType, Symbol
from QuantConnect.Algorithm import QCAlgorithm
from QuantConnect.Data.Consolidators import CalendarInfo, TradeBarConsolidator
from QuantConnect.Data.Market import Bar, FuturesChain, TradeBar
from QuantConnect.Indicators import RollingWindow
from QuantConnect.Securities import Futures
from AlgorithmImports import DateTime


class FutureTrendFollowing(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(DateTime(2021, 8, 1, 9, 00, 0))  # Set Start Date
        self.SetEndDate(self.StartDate + timedelta(5))  # Set End Date
        self.SetCash(100000)  # Set Strategy Cash
        self.time_interval = 15  # 15 min time interval
        self.contract_size = 1

        self.es = self.AddFuture(
            Futures.Indices.SP500EMini, resolution=Resolution.Minute)
        self.es.SetFilter(7, 95)
        self.Consolidate(self.es.Symbol, timedelta(
            minutes=self.time_interval), self.OndataConsolidated)

    def OnData(self, data):
        for chain in data.FutureChains:
            if self.Time.hour == 11 and self.Time.minute == 0:
                self.Log("Number of contracts selected {}".format(
                    len([k for k in chain.Value])))

    def OndataConsolidated(self, consolidated):
        self.Log(type(consolidated))
        self.Log(
            f"{consolidated.EndTime} >> OndataConsolidated >> {consolidated.Close}")