| Overall Statistics |
|
Total Trades 3017 Average Win 0.04% Average Loss -0.12% Compounding Annual Return -20.623% Drawdown 50.400% Expectancy -0.247 Net Profit -37.614% Sharpe Ratio -0.662 Probabilistic Sharpe Ratio 0.187% Loss Rate 45% Win Rate 55% Profit-Loss Ratio 0.36 Alpha 0.052 Beta -1.199 Annual Standard Deviation 0.198 Annual Variance 0.039 Information Ratio -0.845 Tracking Error 0.335 Treynor Ratio 0.109 Total Fees $3163.56 Estimated Strategy Capacity $34000000.00 Lowest Capacity Asset QQQ RIWIV7K5Z9LX |
#region imports
from AlgorithmImports import *
#endregion
# Trading QC Super Trend Indicator
# --------------------------------------------
STOCK = "QQQ"; BAR = 1; SL = -0.0145; TP = 0.01; #ATR = 3; MULT = 0.09; wil m 0.2 and kama 0.16 spy 3 0.1.. A1M0.1 A2M0.2 A1M0.16
# --------------------------------------------
class SuperTrendIndicator(QCAlgorithm):
def Initialize(self):
self.SetStartDate(DateTime(2020, 5, 17, 9, 30, 0))
self.SetEndDate(DateTime(2022, 6, 1, 16, 0, 0))
self.SetCash(200000)
res = Resolution.Hour
ATR = int(self.GetParameter("ATR_A"))
MULT = float(self.GetParameter("MULT_A"))
self.stock = self.AddEquity(STOCK, res).Symbol
self.heikin_ashi = HeikinAshi(self.stock)
#self.heikin_ashi = self.HeikinAshi(self.stock, res) # heikin ashi
consolidator = TradeBarConsolidator(timedelta(hours = BAR))
self.Consolidate(self.stock, timedelta(hours = BAR), self.BarHandler)
self.st = IndicatorExtensions.Of(SuperTrend(ATR, MULT, MovingAverageType.Kama), self.heikin_ashi)
self.RegisterIndicator(self.stock, self.st, consolidator)
self.SetWarmUp(5*BAR*ATR, res)
#Close every friday
#self.Schedule.On(self.DateRules.Every(DayOfWeek.Friday), self.TimeRules.At(16, 0), self.FridayClosed)
#Liquidate at 10k loss
#self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.Every(timedelta(minutes=10)), self.LiquidateUnrealizedLosses)
#Close Every Friday
#def FridayClosed(self):
#self.Liquidate(self.stock)
#self.Log(f"Friday at 4pm: Fired at: {self.Time}")
#liquidate at 10k loss
#def LiquidateUnrealizedLosses(self):
# Liquidate any unrealized loss of over 10000 dollars or can use percentage of available funds,
#if self.Portfolio.TotalUnrealizedProfit < -10000:
#self.Log(f"Liquidated due to unrealized losses at: {self.Time}")
#self.Liquidate()
def BarHandler(self, consolidated):
if self.IsWarmingUp: return
if not self.st.IsReady: return
if not self.heikin_ashi: return
self.Plot(STOCK, "Price", self.Securities[self.stock].Price)
self.Plot(STOCK, "Super Trend", self.st.Current.Value)
#stop trading at 3:30 every Friday
#stop_time = self.Time.replace(day=5, hour=15, minute=30, second=0)
#if self.Time >= stop_time:
#return
pnl = self.Securities[self.stock].Holdings.UnrealizedProfitPercent
if self.heikin_ashi.High.Current.Value > self.st.Current.Value: # Bullish
self.SetHoldings(self.stock, 1, True, "Buy Signal")
elif self.heikin_ashi.Low.Current.Value < self.st.Current.Value: # Bearish
self.SetHoldings(self.stock, -1, True, "Sell Signal")
#self.Liquidate(self.stock, "Sell Signal")
if self.Portfolio[self.stock].Invested:
if pnl < SL:
self.Liquidate(self.stock, "Stop Loss")
#elif pnl > TP:
#self.Liquidate(self.stock, "Take Profit")