Overall Statistics
Total Orders
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Start Equity
100000
End Equity
100000
Net Profit
0%
Sharpe Ratio
0
Sortino 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
-2.749
Tracking Error
0.098
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
from datetime import timedelta
from AlgorithmImports import *


class FT1Indexes(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2024, 1, 1)  # monday = holiday..
        self.set_end_date(2024, 2, 1)
        self.set_cash(100000)

        self.spy = self.add_equity("SPY", Resolution.HOUR).symbol

        self.daily_consolidator = TradeBarConsolidator(timedelta(days=1))

        self._rsi = RelativeStrengthIndex(14, MovingAverageType.WILDERS)
        self._sto = Stochastic(14, 3, 3)
        self.register_indicator(self.spy, self._rsi, self.daily_consolidator)
        self.register_indicator(self.spy, self._sto, self.daily_consolidator)

        # warm_up indicator
        self.warm_up_indicator(self.spy, self._rsi, timedelta(days=1))
        self.warm_up_indicator(self.spy, self._sto, timedelta(days=1))


        self._rsi_history = RelativeStrengthIndex(14, MovingAverageType.WILDERS)
        self._sto_history = Stochastic(14, 3, 3)
        self.register_indicator(self.spy, self._rsi_history, self.daily_consolidator)
        self.register_indicator(self.spy, self._sto_history, self.daily_consolidator)

        # history warm up
        history = self.history[TradeBar](self.spy, 20, Resolution.DAILY)
        for bar in history:
            self._rsi_history.update(bar.end_time, bar.close)
            self._sto_history.update(bar)

    def on_data(self, data: Slice):
        if self.is_warming_up:
            return

        if data.contains_key(self.spy):
            chart_name = "warm_up_indicator"
            self.plot(chart_name, "RSI", self._rsi.current.value)
            self.plot(chart_name, "STO K", self._sto.stoch_k.current.value)
            self.plot(chart_name, "STO D", self._sto.stoch_d.current.value)

            chart_name = "History Warmup"
            self.plot(chart_name, "RSI", self._rsi_history.current.value)
            self.plot(chart_name, "STO K", self._sto_history.stoch_k.current.value)
            self.plot(chart_name, "STO D", self._sto_history.stoch_d.current.value)