零点课堂 | How To Create TA Indicators on TradingView(5)

The simple moving average (SMA)

We might as well plot the SMA, just so we can compare the two after. Add this line to your script:

plot(sma(close, 10))

This plots the average of the previous ten days. Tweak the number in the brackets to see how the curve changes when taking into account different lengths.

The SMA, based on the previous ten days.

The exponential moving average (EMA)

The EMA will be a bit trickier to understand, but not to worry. Let’s break down the formula first:

EMA = (Close - Previous Day’s EMA) * Multiplier - Previous Day’s EMA

So, what’s this telling us? Well, for each day, we calculate a new moving average based on the previous day’s one. The multiplier is what “weighs” the most recent period, and is calculated with the following formula:

Multiplier = 2 / (Length of EMA + 1)

As with simple moving averages, we need to specify how long the EMA will be. Syntactically, the function to plot EMA is similar to the SMA one. Plot it alongside the SMA so you can compare the two:

//@version=4
study("My Script", overlay=true)
plot(sma(close, 10))
plot(ema(close,10))

You can see a slight difference in the two types of MA.

声明:本文由 Binance撰写,零点财经收录,观点仅代表作者本人,绝不代表零点财经赞同其观点或证实其描述。

本文由 零点财经 作者:tao 发表,其版权均为 零点财经 所有,文章内容系作者个人观点,不代表 零点财经 对观点赞同或支持。如需转载,请注明文章来源。
分享生成图片
52

发表回复

零点课堂 | How To Create TA Indicators on TradingView(5)

2021-03-25 10:24:22

The simple moving average (SMA)

We might as well plot the SMA, just so we can compare the two after. Add this line to your script:

plot(sma(close, 10))

This plots the average of the previous ten days. Tweak the number in the brackets to see how the curve changes when taking into account different lengths.

The SMA, based on the previous ten days.

The exponential moving average (EMA)

The EMA will be a bit trickier to understand, but not to worry. Let’s break down the formula first:

EMA = (Close - Previous Day’s EMA) * Multiplier - Previous Day’s EMA

So, what’s this telling us? Well, for each day, we calculate a new moving average based on the previous day’s one. The multiplier is what “weighs” the most recent period, and is calculated with the following formula:

Multiplier = 2 / (Length of EMA + 1)

As with simple moving averages, we need to specify how long the EMA will be. Syntactically, the function to plot EMA is similar to the SMA one. Plot it alongside the SMA so you can compare the two:

//@version=4
study("My Script", overlay=true)
plot(sma(close, 10))
plot(ema(close,10))

You can see a slight difference in the two types of MA.

声明:本文由 Binance撰写,零点财经收录,观点仅代表作者本人,绝不代表零点财经赞同其观点或证实其描述。