OPEN-SOURCE SCRIPT

EMA 9 & EMA 21

Indicator Declaration:

pinescript
Copy code
//version=5
indicator("EMA 9 & EMA 21", overlay=true)
Specifies the script uses Pine Script version 5.
The overlay=true ensures the EMAs are plotted directly on the price chart, rather than in a separate pane.
Input Parameters:

pinescript
Copy code
ema9Length = input.int(9, title="EMA 9 Length", minval=1)
ema21Length = input.int(21, title="EMA 21 Length", minval=1)
input.int() allows the user to customize the EMA lengths.
The minval=1 ensures the length is always a positive integer.
Default lengths are set to 9 and 21 for the short- and medium-term EMAs, respectively.
EMA Calculations:

pinescript
Copy code
ema9 = ta.ema(close, ema9Length)
ema21 = ta.ema(close, ema21Length)
ta.ema() computes the exponential moving average based on the close price of candles.
ema9 and ema21 are dynamically calculated for every candle on the chart.
Plot EMAs:

pinescript
Copy code
plot(ema9, color=color.blue, title="EMA 9", linewidth=2)
plot(ema21, color=color.red, title="EMA 21", linewidth=2)
plot() draws the EMAs on the chart:
ema9 is plotted in blue to represent the short-term EMA.
ema21 is plotted in red to represent the medium-term EMA.
The linewidth=2 makes the lines slightly thicker for better visibility.
educationalExponential Moving Average (EMA)multitimeframe

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明