דלגו לתוכן
פתיחת RaamTrade

TrendQuality — Trend Quality

תוכן זה אינו זמין עדיין בשפה שלך.

Trend strength divided by the noise around it: the regression’s total move over the window, scaled by its own standard error. Statistically this is a t-statistic for the slope — it asks not “is price rising” but “is the rise larger than the scatter”.

Signature

TrendQuality(period, on=<source>)
Argument Type Required Notes
period int Param or literal Yes Regression window. Default 20, bounds 3–400.
on= symbol, OHLCV field, or indicator No Source. Defaults to the trade symbol’s close.

Formula

$$ \text{TQ} = \frac{\text{slope}\cdot(n-1)}{SE} $$

Warmup

period bars; 0 until then, and 0 on a perfect fit where the error vanishes.

Reading the value

tq.value
tq.value > 3

Example

class QualityGate(Strategy):
"""Join only trends that are large relative to their own noise."""
trade = Symbol()
sizing = FixedCapital()
def execute(self):
tq = TrendQuality(20, on=self.trade)
if tq.value > 3 and self.trade.is_flat:
self.buy(self.trade, reason=f"Trend quality {tq.value:.1f}")
if tq.value < 0 and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Quality gone")

Notes

  • The regression t-statistic, used as a trend filter.
  • Proven by an assert-via-trade run on SPY daily (built from the same regression that StandardError was verified against; zero alarm trades).
  • Signed: positive is a clean uptrend, negative a clean downtrend, near zero either flat or noisy. Magnitude, not sign, is the quality read.