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

TrendIntensity — Trend Intensity

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

How far price sits from its own simple moving average, as a percentage. Positive means above the average, negative means below, and the magnitude says how stretched the move is.

TrendIntensity is the identifier a strategy writes; Trend Intensity is the label the chart’s indicator picker shows. Single value — .value is the only accessor.

Signature

TrendIntensity(period, on=<source>)
Argument Type Required Notes
period int Param or literal Yes Length of the moving average. Default 20, bounds 2–200.
on= symbol, OHLCV field, or indicator No Source. Defaults to the trade symbol’s close.

Formula

$$ \text{SMA}N = \frac{1}{N} \sum{i=0}^{N-1} \text{close}_{t-i}, \qquad \text{TrendIntensity} = \frac{\text{close}_t - \text{SMA}_N}{\max(\text{SMA}_N,\ 0.0001)} \times 100 $$

The result is a percentage: 2.5 means price closed 2.5% above its N-bar average. The denominator is floored at a small epsilon so an average at or near zero cannot divide by zero.

Warmup

period bars. Before the window fills the indicator returns 0 — which reads as “price is exactly on its average”, the most neutral value on the scale. A strategy never observes it (execute() waits until every indicator is ready); it is what the chart plots on the leading bars.

Reading the value

ti.value # percent deviation from the SMA
ti.value_at(1)
ti > 0 # price above its average
ti.crossed_above(0) # the bar price reclaims its average
ti > 5 # stretched 5% above — thin air, or a strong trend

Example

class QuietTrend(Strategy):
period = Param(20, min=2, max=200)
trade = Symbol()
sizing = FixedCapital()
def execute(self):
ind = TrendIntensity(self.period, on=self.trade)
self.stop_loss(2.0)
if ind.value > 0 and self.trade.is_flat:
self.buy(self.trade, reason=f"Trend {ind.value:.1f}%")
if ind.value < 0 and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Trend flipped")

Notes

  • Sign and magnitude answer different questions. The sign is a trend filter — ti > 0 is exactly close > SMA(period). The magnitude is a stretch gauge, and the two are often used in opposite directions in the same strategy: trade with the sign, fade the extreme magnitudes.
  • Percentage-scaled, so thresholds carry across instruments. This is MADeviation divided by the average — same measurement, portable units.
  • It compares price to the average of the window that includes it, so the reading is structurally damped: a single bar can move the average as well as the price.
  • Not bounded. In a violent move it can read tens of percent; there is no ±100 rail to lean on.