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.557 Tracking Error 0.202 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
#region imports from AlgorithmImports import * #endregion from trSum import trSum class trSumIndicator(QCAlgorithm): def Initialize(self): self.SetStartDate(2022, 1, 1) # Set Start Date self.SetEndDate(2023, 1, 1) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.resolution = Resolution.Daily self.period = 10 self.sym = self.AddEquity("SPY", self.resolution).Symbol self.trSum = trSum("trSum", self.period) self.RegisterIndicator(self.sym, self.trSum, self.resolution) self.SetWarmUp(20) def OnData(self, data): if not [self.trSum.IsReady]: return if self.IsWarmingUp: return self.Plot("trSum", "Value", self.trSum.Current.Value)
#region imports from AlgorithmImports import * #endregion import numpy as np class trSum(PythonIndicator): def __init__(self, name, length): self.Name = name self.Length = length self.highs = RollingWindow[float](length) self.lows = RollingWindow[float](length) self.closes = RollingWindow[float](length) self.true_ranges = RollingWindow[float](length) self.Value = 0 def Update(self, input): self.highs.Add(input.High) self.lows.Add(input.Low) self.closes.Add(input.Close) if not (self.highs.IsReady and self.lows.IsReady and self.closes.IsReady): return False self.true_ranges.Add(self.TrueRange(self.highs[0], self.lows[0], self.closes[1])) if not self.true_ranges.IsReady: return False self.Value = sum(list(self.true_ranges)[0:self.Length]) return True def TrueRange(self, high, low, close): return max(high - low, abs(high - self.closes[1]), abs(low - self.closes[1]))