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

class ChartingDemoAlgorithm(QCAlgorithm):

    def Initialize(self) -> None:
        self.SetStartDate(2023, 8, 18)
        self.SetEndDate(2023, 8, 18)
        self.resol = Resolution.Minute

        self.equity = self.AddEquity("AAPL", self.resol, dataNormalizationMode=DataNormalizationMode.Raw)
        self.symbol = self.equity.Symbol
        
        chart = Chart("Candlestick")
        self.AddChart(chart)

        chart.AddSeries(CandlestickSeries(self.symbol, "$"))

        # Create a Bollinger Band indicator
        self.bollinger = self.BB(self.symbol, 20, 2, MovingAverageType.Simple, self.resol)
        # Add Bollinger Band series to the chart
        chart.AddSeries(Series("UpperBand", SeriesType.Line, 0))
        chart.AddSeries(Series("MiddleBand", SeriesType.Line, 0))
        chart.AddSeries(Series("LowerBand", SeriesType.Line, 0))

        # Add Volume series to the chart
        chart.AddSeries(Series("Volume", SeriesType.Bar, 1))

    def OnData(self, data) -> None:
        if not data.ContainsKey(self.symbol):
            return        
        if self.IsMarketOpen(self.symbol):
            self.Plot("Candlestick", self.symbol, data[self.symbol])
            # Plot the Bollinger Band values
            self.Plot("Candlestick", "UpperBand", self.bollinger.UpperBand.Current.Value)
            self.Plot("Candlestick", "MiddleBand", self.bollinger.MiddleBand.Current.Value)
            self.Plot("Candlestick", "LowerBand", self.bollinger.LowerBand.Current.Value)        
        
            # Plot the Volume
            self.Plot("Candlestick", "Volume", data[self.symbol].Volume)