OPEN-SOURCE SCRIPT

MA Difference

已更新
The MA Difference indicator shows 3 histograms representing differences in moving averages between a base MA (10) and 3 MA's: short (20), medium (50), and long (200). It also shows an exponentially weighted trend line which can indicate breakout opportunities, has alerts on all base <-> X crossovers, and shows potential consolidation zones where MA differences are below a user-defined tolerance.

The suggested way to use this indicator is to place a trade when the trend line is above the histogram (and filling the space between them). This indicates that the current MA values are significantly above or below the expected range and that prices are in the midst of breaking out. You may also consult the consolidation zones to eliminate false breakouts and momentary changes in trend. You may also consult the various short, medium, and long crossovers and crossunders to time entries and exits accordingly.

Histograms

The 3 histograms represent the differences between:

  • Base MA (10) and Short MA (20)
  • Base MA (10) and Medium MA (50)
  • Base MA (10) and Long MA (200)


All 4 moving average values can be configured in the indicator's settings. Consistency in direction and color of the histogram indicates a consistent trend across the various moving averages.

Trend Line

The trend line is an exponentially weighted average of the 3 moving averages, scaled by a factor configurable in the settings. When using the trend line, shading will be applied to the difference between the extremes of the histogram and the trend line to indicate that the chart is in a "breakout zone" and is beyond the normal, gradual sway of price action.

Crossovers/Crossunders

You may optionally turn on crossovers and crossunders in the indicator's settings to display when a short, medium, or long crossover occurs against the base moving average. Likewise, alerts are available for each crossover and crossunder for each of the 3 moving average convergences.

Consolidation Zones

Consolidation zones, as well as a line representing the current amount of consolidation, can also be optionally drawn on the chart. These indicate when a security is likely in consolidation, according to the spread of various MA values.
版本注释
Including or excluding the long MA in the calculation for consolidation.
版本注释
UPDATE - September 17th, 2024

I've now added an "unweighted trend line", colored according to the long or short direction, which can be used in conjunction with the "weighted trend line" (also just called the "trend line"). This provides the ability to do crossovers between the unweighted and weighted trend lines, in the same way that a MACD crossover trading strategy works.

The idea behind the unweighted trend line is that it's intended to be a true average of the differences between the base and short, base and medium, and base and long moving averages. The weighted trend line, however, is the same calculation, but weighted by a "trend factor" that scales it up or down accordingly.

When the weighted and unweighted trend lines cross over each other, they denote a shift in various moving average beyond what is considered "normal" price movement.
版本注释
Update - September 17th, 2024 (2nd update)

I have redone the consolidation detection logic to be simpler. Now we simply detect the high and low ranges of the moving average differences and plot accordingly. You might want to consider modifying the consolidation tolerance to fit the volatility of the symbol you're applying this to. Every symbol will have a different concept of what is considered "volatile" and "consolidated" - this is more of an art than a science.
版本注释
Bug fix:

Applying absolute value to the diff calculation for consolidation zones.
Moving Averages
cereallarceny

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明