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
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
# region imports
from AlgorithmImports import *
# endregion

# ------------------------------------------------------------
TICKER = "SPY"; OPENING_RANGE = 3; WAIT = 0; MULTIPLIER = 1
# ------------------------------------------------------------

class MeasuredMagentaDogfish(QCAlgorithm):

    def Initialize(self):
        self.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw))
        self.SetStartDate(2023, 3, 10)  # Set Start Date
        self.SetCash(10000)  # Set Strategy Cash
        self.stock = self.AddEquity(TICKER, Resolution.Tick).Symbol
        self.high_window = RollingWindow[float](3)
        self.low_window = RollingWindow[float](3)
        self.min_value = 0
        self.max_value = 0

        consolidator = TickQuoteBarConsolidator(TimeSpan.FromMinutes(1)) ## force consolidator to produce 1 minute bars
        consolidator.DataConsolidated += self.OnCandle
        self.SubscriptionManager.AddConsolidator(self.stock, consolidator)

    def OnData(self, data):
        ## Any trading code in here will be at the tick level
        pass
        
    def OnCandle(self, sender, bar):
        ## Any trading code in here will be at the minute level
        self.high_window.Add(bar.High)
        self.low_window.Add(bar.Low)

        if self.high_window.IsReady and self.low_window.IsReady:
            self.max_value = max(list(self.high_window)[0:2])
            self.min_value = min(list(self.low_window)[0:2])

            self.Plot("Values", "High", self.max_value)
            self.Plot("Values", "Low", self.min_value)