dgtrd

Price Distance to its MA by DGT

Prices high above the moving average (MA) or low below it are likely to be remedied in the future by a reverse price movement as stated in an Article by Denis Alajbeg, Zoran Bubas and Dina Vasic published in International Journal of Economics, Commerce and Management

Here comes a study to indicate the idea of this article, Price Distance to its Moving Averages (P/MA Ratio)

The analysis expressed in the paper indicates that there is a connection between the distance of the prices to moving averages and subsequent returns : portfolios of stocks with lower prices to moving averages generally outperformed portfolios of stocks with higher prices to moving averages. This “overextended” effect is more pronounced when using shorter moving averages of 20 and 50 days, and is especially strong in short-term holding periods like one and two weeks. The highest annual returns are recorded when buying in the range of 0-5% below shorter moving averages of 20/50 days, and 0-10% below longer moving averages of 100/200 days. However, buying very far below almost all moving averages on almost all holding periods produces the lowest returns.

The concept of this study recognizes three different modes of action.
In a clearly established upward trend traders should be buying when prices are near or below the MA line and selling when prices move too far above the MA.
Conversely, in downward trend stocks should be shorted when reaching or going above the moving average and covered when they drop too far below the MA line.
In a sideways movement traders are advised to buy if the price is too low below the moving average and sell when it goes too far above it

Short-term traders can expect to outperform in a one or two week time window if buying stocks with lower prices compared to their 20 and 50 SMA / EMA , one to two-week holding periods is quite high, ranging from 72,09% to 90,61% for the SMA (20, 50) and 85,03% to 87,5% for the EMA (20, 50). The best results for the SMA 20 and 50, on average, are concentrated in the region of 0-5% below the MA for the majority of holding periods. Buying very far below almost all MA in almost all holding periods turns out to be the worst possible option

Candle patterns, momentum could be used in conjunction with this indicator for better results. Try Colored DMI and Ichimoku colored SuperTrend by DGT
Release Notes: Price distance to its 10 * MA added as second line for better judgment. additionally the wide and narrow states of MA and 10 * MA can be used with analysis as well

Secondly, Exponential Moving Average (EMA) is added as option besides SMA as it has been analyzed with the article stated above
Release Notes: small update : price to it’s slow moving average ratio (convergence/divergence) line made configurable by user
Release Notes: small update : theshold lines made settabale
Release Notes: Price Distance to its MA (P/MA) study when look closely you will observe similarities to The Relative Strength Index (RSI). Because of its similarity to RSI, the P/MA can be used in a similar way

Over bought and over sold levels needs to be adjusted based on the market. For crypto it is suggested 25/-25 (default setting) for forex and stocks 10/-10
Release Notes: Display format updated as percentages since we measure changes in percentage with this study
Release Notes: In statistics, the standard deviation is a measure of the amount of variation or dispersion of a set of values. the standard deviation is commonly used to measure confidence in statistical conclusions

the percentage of values 68.27%, 95.45% and 99.73% of the values lie within one, two and three standard deviations of the mean. nearly all values are taken to lie within three standard deviations of the mean, and thus it is empirically useful to treat 99.7% probability as near certainty.

Bollinger Bands, developed by John Bollinger, is a well-known technical analysis tool defined by a set of trendlines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of a security's price

This update implements standard deviations concept adapted to fit the Price Distance to it's MA (P/MA) Indicator, with the aim to define threshold lines
Release Notes: minor update :

* alert conditions added
- when fast price / moving average line crosses outer bands alerts can be triggered

* theshold bands default value settings reduced slightly
Release Notes: █ enhancement

for trading opportunities - added additional method and/or confirmation method.

trading opportunity is considered when crossing of P/MA line (fast and/or slow) and its Moving Average line, more clearly when histogram changes direction, and ONLY in case when both trends have same direction (this is to avoid false signals). It is important to note that the moving average determines the direction

histogram (cycle indicator) is derived from the P/MA line. It is

cycle = pma – pma ma

By default the histogram for fast and slow P/MA will be displayed and alerts are also added for the new method introduced

The same approach is applied with the Lefort indicator that I have adapted earlier in Trading View, here is the link of the study STPMT by DGT, please check for further details with usage example that is applicable with this update
Release Notes: minor update

- plotting title correction

- histogram plotting is now available as Candles or Columns

Special thanks to @AtomOfScent for his feedback and suggestion
Skript med en öppen källkod

I sann TradingView-anda har författaren till detta skript publicerat det som öppen källkod, så att handlare kan förstå och verifiera det. Skål för författaren! Du kan använda den gratis men återanvändning av den här koden i en publikation regleras av våra Ordningsregler. Du kan göra den till favorit för att använda den i ett diagram.

Vill du använda det här skriptet i ett diagram?

Kommentarer

Very much trying to understand the entry and exit signals on this. Are you saying enter/exit when it is in the colored section? The horizontal colored bands moving horizontal at the bottom. Or do you mean enter when the green bars print and exit when they change color? Thanks I am new here and trying to understand all this scripting language.
+1 Svara
dgtrd chartripper
hello @chartripper, thanks for the comment

The idea of this script
Prices high above the moving average (MA) or low below it are likely to be remedied in the future by a reverse price movement

So the green and red bands represent area of interest, price may reverse or regress

Moving average of P/MA (blue line) and histogram are for futher confirmation. The blue and red line crosses or simply when histogram changes direction are assumed as signals ONLY in case when both trends have same direction (this is to avoid false signals). It is important to note that the moving average (blue line) determines the direction
Svara
@dgtrd, Thanks, I notice when the blue crosses below red, the price tends to move up. When you say both trends have same direction, are you talking about both the green and red line having an upward slope in the case of looking for a buy? Many thanks!
Svara
dgtrd chartripper
@chartripper, yes exactly, both the blue and red line having an upward slope in case buy, additionally if red line moves from below or within green band upwards is better
Svara
I've been checking out all your scripts and this one is definitely a gem. :) However, I think I noticed a tiny bug, cycleSlowHist/cycleFastHist and cycleSlow/cycleFast seem reversed. I also found the histograms look better with columns or area since plotcandle borders don't display well at all when zoomed out (I reported to support so hopefully they improve it). Cheers!

plotcandle(0., 0., 0., cycleSlowHist, "Cycle Histogram of Fast Price/MA", cycleSlow > 0 ? color.new(color.blue , 34) : color.new(color.yellow, 34))//, bordercolor=#ffffff00)
plotcandle(0., 0., 0., cycleFastHist, "Cycle Histogram of Slow Price/MA", cycleFast > 0 ? color.new(color.green, 34) : color.new(color.red , 34))//, bordercolor=#ffffff00)
Svara
dgtrd AtomOfScent
Thank You very much @AtomOfScent, this study is one of my favorites too :) I have interpreted it differently and adapted to other studies too.



And thanks for the feedback and suggestion, I have just corrected the title issue and added optionally histogram as columns, they used to be as columns earlier but changed it to candles and the reason was that, when you zoom out the plottings were becoming messy and with plotcandle histogram somehow was disapearing and did not look too messy ;)
+1 Svara
@dgtrd, I added adaptive periods, selectable average types for the fast/slow MAs, signals when it crosses under the positive band or above the negative band and optional smoothing for the difference histograms. :) The band concept has proven a useful addition to almost any script 👍🏻
Svara
dgtrd AtomOfScent
@AtomOfScent, this looks pretty, and different colors represents different moving averages, good

btw, colors on style settings is removed by design. they disapear in case any of the color is required to be calculated on run-time otherwise they remain
Svara
@dgtrd, thanks :)
I don't think I like this design change at all. Seems it makes basic things like being able to choose the colors for a plot that changes color above/below zero impossible without modifying the code or manually adding a bunch of input color variables. :/
Svara
dude this is good!!!
I change the slow ma to 713 periods and looks beautiful for me
Svara