I made this script to test what is the better Moving Average type to predict the market direction, so I put a function with All the MA I know.
To go beyond, this script have an option to increase the MA length as a Fibonacci Number or any other simple number to step.
If the drawing is too slow, just reduce the amount of MA lines in the input option ("Number of MA to Plot:") to 10 or less and it will be faster.
Hope you like, and if you know other Moving Average type, just tell me how can I get the formula and (if its good, not copyrighted and I have time) I can add here and update for all of us.
Obs: To avoid errors, the Maximum Nth Fibonacci Term to use in MA Length is 19 (4181)
版本注释
⋅
► Put an option to change colors when a slow MA crossover the right next fast MA line; ► Change the labels to one Info Panel or just simple symbols with the content in tooltip; ► Put a list of Fibonacci Sequence Terms in Inputs to help.
版本注释
⋅
After some update in TradingView's Pine Code, the old script stop to works.
So, I rewrite some part of the code to fix the new problem; And in addition, I put 4 new Moving Average kind to the script.
Rodrigo, thank you for your great work, I think it is something magnificent. As you have requested, I have devoted myself to researching more moving averages so that you can add them to your magnificent work. Here I leave you the name of the average, its formula and the source where I found them. Let me know how it goes to see if you can include them hopefully all. Best wishes.
1. Linear Weighted Moving Average (LWMA)
In the case of weighted moving average, the latest data is of more value than more early data. Weighted moving average is calculated by multiplying each one of the closing prices within the considered series, by a certain weight coefficient:
LWMA = SUM (CLOSE (i) * i, N) / SUM (i, N)
Where:
SUM — sum;
CLOSE(i) — current close price;
SUM (i, N) — total sum of weight coefficients;
N — smoothing period.
The standard exponential moving average formula converts the time period to a fraction using the formula EMA% = 2/(n + 1) where n is the number of days. For example, the EMA% for 14 days is 2/(14 days +1) = 13.3%. Wilder, however, uses an EMA% of 1/14 which equals 7.1%. This equates to a 27-day exponential moving average using the standard formula.
Average True Range;
Directional Movement System;
Relative Strength Index; and
Twiggs Money Flow — developed by Colin Twiggs using Wilder's moving average formula.
Indicator Time Frames
We recommend that users try shorter time periods when using one of the above indicators. For example, if you are tracking a 30-day cycle you would normally select a 15-day Indicator Time Period. With the RSI, adjust the time period as follows:
RSI time period = (n + 1) / 2 = (15 + 1) / 2 = 8 days
Displaced Moving Averages are useful for trend-following purposes, reducing the number of whipsaws compared to an equivalent Exponential or Simple Moving Average.
Moving averages are prone to whipsaws, when price crosses back and forth across the moving average in a ranging market. Traders have developed a number of filters over the years to eliminate false signals.
Adaptive Moving Average (AMA) Technical Indicator is used for constructing a moving average with low sensitivity to price series noises and is characterized by the minimal lag for trend detection. This indicator was developed and described by Perry Kaufman in his book "Smarter Trading".
Calculation
To define the current market state Kaufman introduced the notion of Efficiency Ratio (ER), which is calculated by the below formula:
ER(i) = Signal(i)/Noise(i)
Where:
ER(i) — current value of the Efficiency Ratio;
Signal(i) = ABS(Price(i) - Price(i - N)) — current signal value, absolute value of difference between the current price and price N period ago;
Noise(i) = Sum(ABS(Price(i) - Price(i-1)),N) — current noise value, sum of absolute values of the difference between the price of the current period and price of the previous period for N periods.
At a strong trend the Efficiency Ratio (ER) will tend to 1; if there is no directed movement, it will be a little more than 0. The obtained value of ER is used in the exponential smoothing formula:
EMA(i) = Price(i) * SC + EMA(i-1) * (1 - SC)
Where:
SC = 2/(n+1) — EMA smoothing constant, n — period of the exponential moving;
EMA(i-1) — previous value of EMA.
The smoothing ratio for the fast market must be as for EMA with period 2 (fast SC = 2/(2+1) = 0.6667), and for the period of no trend EMA period must be equal to 30 (slow SC = 2/(30+1) = 0.06452). Thus the new changing smoothing constant is introduced (scaled smoothing constant) SSC:
SSC(i) = (ER(i) * ( fast SC - slow SC) + slow SC
or
SSC(i) = ER(i) * 0.60215 + 0.06425
For a more efficient influence of the obtained smoothing constant on the averaging period Kaufman recommends squaring it.