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
#region imports
from AlgorithmImports import *
#endregion
# EMA of the midpoint

# -------------------------
CRYPTO = "BTCUSD"; PERIOD = 3;
# -------------------------

class EmaOfTheMidpoint(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2022, 5, 1) 
        self.SetEndDate(2022, 5, 1)   
        self.crypto = self.AddCrypto(CRYPTO, Resolution.Minute).Symbol
        self.SetWarmUp(5*PERIOD, Resolution.Minute)

        data_consolidator = TradeBarConsolidator(timedelta(minutes=2))
        data_consolidator.DataConsolidated += self.OnDataConsolidated

        openp = self.Identity(self.crypto, Resolution.Minute, Field.High)
        close = self.Identity(self.crypto, Resolution.Minute, Field.Low)
        midpoint = IndicatorExtensions.Over(IndicatorExtensions.Plus(openp, close), 2)
        self.custom_ema = IndicatorExtensions.EMA(midpoint, PERIOD)
        self.RegisterIndicator(self.crypto, self.custom_ema, data_consolidator, Field.Median)

        self.ema = ExponentialMovingAverage(PERIOD)
        self.RegisterIndicator(self.crypto, self.ema, data_consolidator, Field.Median)

        stockPlot = Chart(self.crypto)
        stockPlot.AddSeries(Series("price", SeriesType.Line, "", Color.Red))
        stockPlot.AddSeries(Series("ema", SeriesType.Line, "", Color.Yellow))
        stockPlot.AddSeries(Series("custom_ema", SeriesType.Line, "", Color.Orange))
        self.AddChart(stockPlot)

    def OnDataConsolidated(self, sender, data):
        self.Debug('withing dataconsolidated') # this is getting printed

    def OnData(self, data):
        if self.IsWarmingUp: return

        price = data[self.crypto].Close        
        ema_ = self.ema.Current.Value
        custom_ema_ = self.custom_ema.Current.Value

        self.Plot(self.crypto, "price", price)
        self.Plot(self.crypto, "ema", ema_)     
        self.Plot(self.crypto, "custom_ema", custom_ema_)

    def OnEndOfAlgorithm(self):
        pass