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.444
Tracking Error
0.197
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
# region imports
from AlgorithmImports import *
import plotly.express as px
import plotly.graph_objects as go
# endregion

class DeterminedOrangePony(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 2, 14)
        self.SetEndDate(2023, 8, 15)
        self.SetCash(1000000)
        self.SetWarmup(200)

        self.ticker = self.AddEquity("SPY", Resolution.Daily, dataNormalizationMode=DataNormalizationMode.Raw).Symbol
        self.rsi_period = 13
        self.rollingWindow = RollingWindow[TradeBar](self.rsi_period + 1)
        self.Consolidate(self.ticker, Resolution.Daily, self.CustomBarHandler)
        self.rsi = self.RSI(self.ticker, self.rsi_period, MovingAverageType.Simple, Resolution.Daily)
        
        
        self.macd = self.MACD(self.ticker, 13, 34, 8, MovingAverageType.Exponential, Resolution.Daily)
        self.bb = self.BB(self.ticker, 21, 2)

    def OnData(self, data: Slice):
        if self.IsWarmingUp:
            return
        if not self.rollingWindow.IsReady: 
            return
        self.highprice = self.Securities["SPY"].High
        self.lowprice = self.Securities["SPY"].Low
        self.openprice = self.Securities["SPY"].Open
        self.closeprice = self.Securities["SPY"].Close
        self.lowerBB = self.bb.LowerBand.Current.Value
        self.upperBB = self.bb.UpperBand.Current.Value
        self.fastMacd = self.macd.Fast.Current.Value
        self.slowMacd = self.macd.Slow.Current.Value
        self.sigMacd = self.macd.Signal.Current.Value
        self.macdLine = self.fastMacd - self.slowMacd 


        self.Plot("SPY", "High", self.highprice)
        self.Plot("SPY", "Low", self.lowprice)
        self.Plot("SPY", "Open", self.openprice)
        self.Plot("SPY", "Close", self.closeprice)
        self.Plot("SPY", "RSI", self.rsi.Current.Value)
        self.Plot("SPY", "MACD", self.macdLine)
        self.Plot("SPY", "Signal", self.sigMacd)
        self.Plot("SPY", "LowerBB", self.lowerBB)
        self.Plot("SPY", "Upper BB", self.upperBB)


    def CustomBarHandler(self, bar):
        self.rollingWindow.Add(bar)