EMA 20,50,200

William_Playfair · study · 51 行 · 点赞 16 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// EMA 20,50,200
// Three customisable EMAs: 20 (blue), 50 (green), and 200 (red).
// Default source: close. Each EMA receives additional 9-period EMA smoothing.
// Change periods, colours, visibility, source, and smoothing in Settings > Inputs.
// Smoothing options: None, SMA, or EMA. Additional smoothing increases lag.
// The chart title remains fixed when periods change; input selections are hidden.
// This indicator does not generate buy/sell signals or include alerts.
//
// Historical reference:
// William Playfair (1759-1823) was a pioneer of statistical graphics, widely
// credited with introducing the statistical line graph, bar chart, and pie chart.
// This acknowledges his contribution to charting, not authorship of EMAs or this script.
// Reference: https://academic.oup.com/oxford-dictionary-of-national-biography/reference/63486/reference-article-abstract/581769537
 
indicator("EMA 20,50,200", shorttitle="EMA 20,50,200", overlay=true)
 
source = input.source(close, "Price source", tooltip="Historical reference: William Playfair (1759-1823) was a pioneer of statistical graphics, widely credited with introducing the statistical line graph, bar chart, and pie chart. This acknowledges his contribution to charting, not authorship of EMAs or this script.", display=display.none)
 
length1 = input.int(20, "EMA period", minval=1, group="EMA 1", display=display.none)
colour1 = input.color(color.blue, "Colour", group="EMA 1", display=display.none)
show1 = input.bool(true, "Show", group="EMA 1", display=display.none)
 
length2 = input.int(50, "EMA period", minval=1, group="EMA 2", display=display.none)
colour2 = input.color(color.green, "Colour", group="EMA 2", display=display.none)
show2 = input.bool(true, "Show", group="EMA 2", display=display.none)
 
length3 = input.int(200, "EMA period", minval=1, group="EMA 3", display=display.none)
colour3 = input.color(color.red, "Colour", group="EMA 3", display=display.none)
show3 = input.bool(true, "Show", group="EMA 3", display=display.none)
 
smoothingType = input.string("EMA", "Smoothing type", options=["None", "SMA", "EMA"], group="Smoothing", display=display.none)
smoothingLength = input.int(9, "Smoothing period", minval=1, group="Smoothing", display=display.none)
 
smooth(seriesValue, period, method) =>
    switch method
        "SMA" => ta.sma(seriesValue, period)
        "EMA" => ta.ema(seriesValue, period)
        => seriesValue
 
ema1 = ta.ema(source, length1)
ema2 = ta.ema(source, length2)
ema3 = ta.ema(source, length3)
 
line1 = smooth(ema1, smoothingLength, smoothingType)
line2 = smooth(ema2, smoothingLength, smoothingType)
line3 = smooth(ema3, smoothingLength, smoothingType)
 
plot(show1 ? line1 : na, title="EMA 1", color=colour1, linewidth=2)
plot(show2 ? line2 : na, title="EMA 2", color=colour2, linewidth=2)
plot(show3 ? line3 : na, title="EMA 3", color=colour3, linewidth=2)

← 返回列表