Simple Moving Average (MA) of N periods.
Syntax:
1 |
Average[N](price) |
Average instruction can be extend with a second parameter under brackets to modify the arithmetic calculation of the average :
1 |
Average[N,M](price) |
Where M can be set with any of these values, to return the specific moving average calculation:
0 = SMA
1 = EMA
2 = WMA
3 = Wilder
4 = Triangular
5 = End point
6 = Time series
7 = Hull (PRT v11 only)
8 = ZeroLag (PRT v11 only)
Example:
Simple representation of 2 Simple Moving Average :
1 2 3 4 |
FastMA = Average[7](Close) SlowMA = Average[20](Close) RETURN FastMA coloured(221,33,33), SlowMA coloured(35,194,57) |
Fast EMA and Slow Triangular moving average:
1 2 3 |
FastMA = Average[7,1](Close) SlowMA = Average[20,4](Close) RETURN FastMA coloured(221,33,33), SlowMA coloured(35,194,57) |
Any moving average can also be use to smooth a value within its period :
1 2 3 4 5 6 |
myRSI = RSI[14] //Smoothing the RSI value on 10 periods SmoothRSI = Average[10](myRSI) RETURN myRSI, SmoothRSI coloured(121,45,180) |
Why isn’t the syntax shown in line 4 of the code at http://www.prorealcode.com/prorealtime-indicators/moving-average-3-soldiers-3-crows/ reflected here for our use.
Explanation of the second parameters has been added to the article. It returns the average with a different method of calculation (from 0 to 6).
Hi, I am looking for a way of displaying the 15min and 60 min 20ema onto the 5 min chart, is there an indicator that allows this?
There is no way to display the others timeframe average through the programming language sorry
Hi, is there any way to offset this averages in the past like you do with the built in averages?
You mean graphically?
I have created a code that gives me the “Comparative Relative Strength” between a Security and its Index:
indicator1 = RSI[14](close)
c1 = (indicator1 >= 50)
c2 = close //Close of security
c3 =1598.2747 //Value of the Index
c4 = c2/c3 // Comparative Relative Strength
return c4
I have coded the same in Tradingview and the “Comparative Relative Strength” chart is the same with the same values. But when adding SMA (20) and EMA (50) to “Comparative Relative Strength” chart the values does not correspond to the value that I get in Tradingview.
What could the reason for that be?