Distance from an average
How the distance from an average measures how far the price is from a moving average in percent, which averages it takes, and how to use it in a QTSurfer strategy.
The distance from an average is how far the price is from a moving average, in percent of the average: positive above it, negative below.
Try it on a series below, against the average you choose, and change its period.
The series are samples, synthetic ones and real crypto ones. They show how the indicator behaves, not what it earns. The line is computed in your browser by the engine’s own indicator class, so it is the line a strategy reads.
What it computes
distance from the average = 100 × (price − average) / average It takes an SMA, an EMA, an MMA, a WMA, an HMA, a TEMA or a KAMA, and the chart lets you choose between them. It refuses any other indicator with Not a moving average indicator: <name>. It is ready when the average is, and it gives 0 when the average is 0.
Reading it
- Zero is the price crossing its average. The sign is the side the price is on.
- A large distance is a stretched price. It says how far the price has gone from its usual level, not that it will come back: in a strong trend it stays large for a long time.
- For an indicator that is not an average, use the distance:
distance("gap", "price", "rsi14")measures the price against any indicator.
In a strategy
setup:
ema(20)
distanceMa("ema20") distanceMa("ema20") registers distema20, and the average has to be registered before it. With another average it is the same: hma(20) then distanceMa("hma20"). The chart gives its average the name avg, and the line it draws is distavg. In Java, .distanceMa("ema20") on the builder.
Related
- Distance: the gap between any two indicators.
- Detrended price oscillator: a past price against the average.
- Z-score: the same gap, in deviations instead of percent.
- QTScript indicators and Java indicators: every indicator a strategy can call, with its forms and the names it registers.