| Overall Statistics |
|
Total Trades 260 Average Win 5.10% Average Loss -5.17% Compounding Annual Return 426.720% Drawdown 33.800% Expectancy 0.284 Net Profit 433.456% Sharpe Ratio 4.811 Probabilistic Sharpe Ratio 93.723% Loss Rate 35% Win Rate 65% Profit-Loss Ratio 0.99 Alpha 2.709 Beta -0.066 Annual Standard Deviation 0.561 Annual Variance 0.314 Information Ratio 3.995 Tracking Error 0.634 Treynor Ratio -41.038 Total Fees $0.00 Estimated Strategy Capacity $3800000.00 Lowest Capacity Asset ETHUSD XJ |
# CRYPTO EMAC_D LS, SL, PT
from AlgorithmImports import *
# ---------------------------------------------------------------
CRYPTO = "ETHUSD"; EMA_F = 13; EMA_S = 48; SL = -0.02; TP = 0.02;
# ---------------------------------------------------------------
class MovingAverageCrossAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2021, 1, 1)
self.SetCash(100000)
self.crypto = self.AddCrypto(CRYPTO, Resolution.Daily).Symbol
self.ema_f = self.EMA(self.crypto, EMA_F, Resolution.Daily)
self.ema_fd = IndicatorExtensions.Of(Delay(1), self.ema_f)
self.ema_s = self.EMA(self.crypto, EMA_S, Resolution.Daily)
self.ema_sd = IndicatorExtensions.Of(Delay(1), self.ema_s)
self.SetWarmUp(5*EMA_S + 1, Resolution.Daily)
def OnData(self, data):
if self.IsWarmingUp: return
if not (self.ema_s.IsReady and self.ema_sd.IsReady): return
price = self.Securities[self.crypto].Price
pnl = self.Securities[self.crypto].Holdings.UnrealizedProfitPercent
ema_f = self.ema_f.Current.Value
ema_s = self.ema_s.Current.Value
ema_fd = self.ema_fd.Current.Value
ema_sd = self.ema_sd.Current.Value
self.Plot(self.crypto, "Price", price)
self.Plot(self.crypto, "ema_f", ema_f)
self.Plot(self.crypto, "ema_s", ema_s)
if not self.Portfolio.Invested:
if ema_f >= ema_s and ema_fd >= ema_sd:
self.SetHoldings(self.crypto, 1, False, "fast >= slow")
elif ema_f < ema_s and ema_fd < ema_sd:
self.SetHoldings(self.crypto, -1, False, "fast < slow")
elif self.Portfolio.Invested:
if pnl < SL:
self.Liquidate(self.crypto, "Stop Loss")
elif pnl > TP:
self.Liquidate(self.crypto, "Take Profit")