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.848
Tracking Error
0.223
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
# TaLib DEMA

from AlgorithmImports import *

# https://www.quantconnect.com/project/9660424

import numpy as np
import talib 

STOCK = 'SPY'; PERIOD = 50;

class TaLibDEMA(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 31)
        self.SetEndDate(2021, 10, 20) 
        self.SetWarmUp(5*PERIOD, Resolution.Daily)
        self.stock = self.AddEquity(STOCK, Resolution.Daily).Symbol
        self.rollingWindow = RollingWindow[TradeBar](5*PERIOD)
        self.Consolidate(self.stock, Resolution.Daily, self.CustomBarHandler)
        
        
    def CustomBarHandler(self, bar):
        self.rollingWindow.Add(bar)         
        if self.IsWarmingUp: return
        if not self.rollingWindow.IsReady: return
        highs = np.flipud(np.array([self.rollingWindow[i].High for i in range(5*PERIOD)]))
        lows = np.flipud(np.array([self.rollingWindow[i].Low for i in range(5*PERIOD)]))
        closes = np.flipud(np.array([self.rollingWindow[i].Close for i in range(5*PERIOD)]))

        talib_midprice = float(talib.MIDPRICE(highs,lows,2)[-1])
        talib_dema = float(talib.DEMA(closes, PERIOD)[-1])

        self.Plot("Indicator", "talib_midprice", talib_midprice)
        self.Plot("Indicator", "talib_dema", talib_dema)