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
-1.469
Tracking Error
0.505
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
# talib Elder Force Index

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

import numpy as np
import talib 

CRYPTO = 'BTCUSD'; PERIOD = 13; EMA = 13; MA = 13; ATR_MULT = 0.3;

class TaLibElderForceIndex(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 9, 21)
        self.SetEndDate(2021, 12, 9) 
        self.SetWarmUp(PERIOD + EMA + 2*MA + 2, Resolution.Daily)
        self.crypto = self.AddCrypto(CRYPTO, Resolution.Daily).Symbol
        self.SetBenchmark(self.crypto)


    def OnData(self,data):

        if self.IsWarmingUp: return
    
        closes = self.History([self.crypto], PERIOD + EMA + 2*MA + 2, Resolution.Daily)['close']
        highs = self.History([self.crypto], PERIOD + EMA + 2*MA + 2, Resolution.Daily)['high']
        lows = self.History([self.crypto], PERIOD + EMA + 2*MA + 2, Resolution.Daily)['low']
        volumes = self.History([self.crypto], PERIOD + EMA + 2*MA + 2, Resolution.Daily)['volume']
        
        changes = (talib.ROCP(closes, 1)[-EMA-2*MA-1:] * closes[-EMA-2*MA-1:])[-EMA-2*MA-1:]
        efi = talib.EMA(changes * volumes[-EMA-2*MA-1:], EMA)[-2*MA-1:]
        efi_ema = talib.EMA(efi, MA)[-2*MA-1:]
        
        atr = talib.ATR(highs, lows, closes, MA)[-MA:]
        atr_ema = abs(talib.SMA(atr, MA))
        vol_sma = talib.SMA(volumes[-MA:], MA)
        ub = efi_ema[-1] + ATR_MULT*vol_sma[-1]*atr_ema[-1] 
        lb = efi_ema[-1] - ATR_MULT*vol_sma[-1]*atr_ema[-1] 
        
        self.Plot("EFI", "efi", efi[-1])
        self.Plot("EFI", "efi_ema", efi_ema[-1])
        self.Plot("EFI", "ub", ub)
        self.Plot("EFI", "lb", lb)
        self.Plot("EFI", "zero", 0)
        
        self.Plot("ATR", "atr", atr[-1])
        self.Plot("ATR", "atr_ema", atr_ema[-1])
        
        self.Plot("Volume", "volume", volumes[-1])