TradingView
Electrified
8 Feb 2021 pukul 00.55

Moving Average Periodical 

S&P 500 IndexTVC

Deskripsi

PMA derives the length of its rendered SMA from the number of periods (example: 5 days) and the length of the period (example: 390 minutes)

The result is an indicator that should be the same across different time-frames of the same type. Allowing for the simple calculation and generation of a Daily Moving Average like the 5 Day SMA (the default for minute based time-frames).

Catatan Rilis


Change-list:

  • Now allows for targeting varying moving average types. Now SMA, WMA, and EMA are options.
  • A float value is now used to allow for more fine tuning.
Komentar
Xela_1234
I want to combine the 50 Periodical Average with a 21 Exponential Moving Average. I inserted this code, but it is not working. It only shows the 21 EMA and not the periodical. Can you help?

//@version=4
study(shorttitle = "50 PMA vs. 21 EMA", title="50 PMA vs. 21 EMA", overlay=true)

src = input(close, title="Source")
periods = input(5.0, minval=0.01, title="Periods")
mode = input(title="Mode", defval="EMA", options=["SMA", "WMA", "EMA"])
plen = input(390, minval=1, title="Period Length")

len = ceil(periods * plen / timeframe.multiplier)
ma =
mode=="EMA" ? ema(src, len) :
mode=="WMA" ? wma(src, len) :
sma(src, len)

plot(ma, color=color.red, linewidth=2, title="PMA")

MAPeriod1 = input(21, title="MA Period 1")
MA1 = ema(close, MAPeriod1)
plot(MA1, color=color.green, linewidth=2)
Electrified
@Xela_1234, you have to be careful with your indentation.
Can you post the snippet someplace else like gist.github.com?
PU5H
Looking through some of your work, very nice!!
TL_ID
Nice work, thanks!
Electrified
@TL_ID, after a lot of searching (not finding) on TradingView, this seemed like the simplest and most flexible solution.
Lebih lanjut