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.
ملاحظات الأخبار
UPDATE - September 24th, 2024

I've added the ability to track the slope of the min/max values between crossovers/unders of the trend line. This considers both previous crossovers/unders, as well as the current trend. By default, I'm going to leave this as "disabled" since it's a somewhat arbitrary metric which you can also just visually see quite clearly, but I think the slope could be useful to put a number to "how quickly and greatly something is changing".

I also added alert conditions for the trend crossovers, which I mistakenly left out in the past. My bad!

Fun note: I had originally intended to calculate the degree of the slope, but this isn't feasible because PineScript doesn't provide the "width" of a bar and so any degree calculation would be inaccurate. Basically the x-axis of "time" (bars) and the y-axis of "trend value" aren't of the same unit, therefore degrees aren't really possible to calculate. So instead, I compromised, going with the intent of this update and just returned the slope scaled by 100.
Moving Averages

نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الرمز في المنشور يخضع لقواعد‎‎قوانين الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟


يعمل أيضًا:

إخلاء المسؤولية