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
0.557
Tracking Error
0.202
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
#region imports
from AlgorithmImports import *
#endregion
import clr
clr.AddReference("QuantConnect.Common")
clr.AddReference("QuantConnect.Algorithm")
clr.AddReference("QuantConnect.Indicators")

from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *

class Nasdaq100Strategy(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 1, 1)
        self.SetEndDate(2022, 12, 31)
        self.SetCash(100000)
        self.AddFuture("ND")
        self.buy = False
        self.sell = False
        self.short = False
        self.exit = False
        self.buy_price = 0
        self.short_price = 0
        self.count = 0

    def OnData(self, data):
        if not self.Portfolio.Invested:
            if data["ND"].Close < data["ND"].Close[1]:
                self.buy = True
                self.buy_price = data["ND"].Close
                self.count = 0
        elif self.Portfolio.Invested:
            self.count += 1
            if data["ND"].Close > self.buy_price:
                self.Sell("ND", 1)
                self.buy = False
                self.exit = True
            elif self.count > 4 and data["ND"].Close > data["ND"].Close[1]:
                self.short = True
                self.short_price = data["ND"].Close
                self.count = 0
            elif self.short and self.count > 4 + 2:
                if data["ND"].Close < self.short_price:
                    self.Sell("ND", 1)
                    self.short = False
                    self.exit = True
        if self.buy:
            self.Buy("ND", 1)
        if self.short:
            self.Sell("ND", 1)