Overall Statistics
Total Trades
135
Average Win
2.26%
Average Loss
-0.54%
Compounding Annual Return
539.233%
Drawdown
7.100%
Expectancy
2.894
Net Profit
193.665%
Sharpe Ratio
10.606
Probabilistic Sharpe Ratio
100.000%
Loss Rate
25%
Win Rate
75%
Profit-Loss Ratio
4.22
Alpha
2.809
Beta
0.651
Annual Standard Deviation
0.258
Annual Variance
0.067
Information Ratio
12.226
Tracking Error
0.233
Treynor Ratio
4.207
Total Fees
$247.90
Estimated Strategy Capacity
$820000000.00
Lowest Capacity Asset
NQ Y1VKEF59AV41
# region imports
from AlgorithmImports import *
# endregion

class AlertFluorescentPinkGorilla(QCAlgorithm):

    def Initialize(self):

        # Setup
        self.SetStartDate(2022, 1, 7)
        self.SetCash(100000)

        # Add index
        self.NDX = self.AddIndex("NDX", Resolution.Minute).Symbol

        #  Consolidator
        cons = TradeBarConsolidator(timedelta(minutes = 30))
        cons.DataConsolidated += self.FiveMinuteHandler
        self.SubscriptionManager.AddConsolidator(self.NDX, cons)

        # EMA
        self.ema_indicator = ExponentialMovingAverage(50)
        self.RegisterIndicator(self.NDX, self.ema_indicator, cons)

        # Request futures
        NQ_future = self.AddFuture(Futures.Indices.NASDAQ100EMini) 
        NQ_future.SetFilter(0, 90)
        self.NQ_future_symbol = NQ_future.Symbol

        # Data storage
        self.data_storage = 0

        # Warmup period
        self.SetWarmUp(timedelta(days = 10))

    def OnData(self, data: Slice):

        # If not warming up
        if not self.IsWarmingUp:
        
            # Data storage
            self.data_storage = data

    def FiveMinuteHandler(self, sender, bar):
        
        # If not warmup
        if not self.IsWarmingUp:

            # If close above EMA
            if self.Securities[self.NDX].Close > self.ema_indicator.Current.Value:
                if not self.Portfolio.Invested:
                    for kvp in self.data_storage.FutureChains:
                        symbol = kvp.Key
                        if symbol == self.NQ_future_symbol:
                            chain = kvp.Value
                            for contract in chain:
                                self.MarketOrder(contract.Symbol, 1)
                                break
            
            # Else
            else:
                self.Liquidate()