基于 1 小时图的 5 分钟图的指数移动平均线

Exponential-Moving-Average for the 5-Minute-Chart based on 1-Hour-Chart

我正在尝试使用 Pine Script 为交易视图编写一个指标。

我想根据 1 小时图编写 EMA 并在 5 分钟图上使用它。包括一个 8 和 34 个交易周期 (2 EMA)。那可能吗?

当我在 5 分钟图上交易时,这对于查看更高趋势很有用。

这是我第一次尝试编写代码。

可惜没时间学

如果有人能告诉我如何解决这个问题,那就太好了。

我试图找到一些 google 的指南,但只有一些关于如何编写 EMA 的指南。

我发现的所有内容是:

//@version=3

// 在 pine 脚本的最开始,我们总是声明我们将要使用的版本, // 可以看到,上面我们使用的是版本3的pine脚本 // pine脚本中的@version字必须在脚本开头注释掉

学习("Coding ema in pinescript",叠加=真)

// 这是我们定义研究的地方, // pinescipt 中的一个学习函数用于告诉 pine 脚本我们将构建一个指标 // 使用“overlay=true”,让 pine 脚本知道您想将图表中的绘图叠加到 // 蜡烛图。

// 现在我们定义一个 EMA 函数,命名为 pine_ema,带有 2 个参数 x 和 y // 这个 pine_ema 函数的唯一目的是 return 当前蜡烛收盘价的当前 ema pine_ema(src, time_period) =>

alpha = 2 / (time_period + 1)
// we have defined the alpha function above
ema = 0.0
// this is the initial declaration of ema, since we dont know the first ema we will declare it to 0.0 [as a decimal]
ema := alpha * src + (1 - alpha) * nz(ema[1])
// this returns the computed ema at the current time
// notice the use of : (colon) symbol before =, it symbolises, that we are changing the value of ema,
// since the ema was previously declared to 0
// this is called mutable variale declaration in pine script
ema
// return ema from the function

_10_period_ema = pine_ema(关闭, 10) // 这里我们只是调用我们的函数,src 为 close,time_period 的值为 10

plot(_10_period_ema, color=red, transp=30, linewidth=2) // 现在我们绘制 _10_period_ema

您可以在不到 1 小时的任何图表上使用它:

//@version=4
study("", "Emas 1H", true)
fastLength = input(8)
slowLength = input(34)
ema1hFast = security(syminfo.tickerid, "60", ema(close, fastLength))
ema1hSlow = security(syminfo.tickerid, "60", ema(close, slowLength))
plot(ema1hFast)
plot(ema1hSlow, color = color.fuchsia)

[编辑 2019.09.07 08:55 — LucF]

//@version=4
study("", "Emas 1H", true)
fastLength  = input(8)
slowLength  = input(34)
smooth      = input(false, "Smooth")
smoothLen   = input(4, "Smoothing length", minval = 2)

ema1hFastRaw    = security(syminfo.tickerid, "60", ema(close, fastLength))
ema1hSlowRaw    = security(syminfo.tickerid, "60", ema(close, slowLength))
ema1hFastSm     = ema(ema(ema(ema1hFastRaw, smoothLen), smoothLen), smoothLen)
ema1hSlowSm     = ema(ema(ema(ema1hSlowRaw, smoothLen), smoothLen), smoothLen)
ema1hFast       = smooth ? ema1hFastSm : ema1hFastRaw
ema1hSlow       = smooth ? ema1hSlowSm : ema1hSlowRaw

plot(ema1hFast)
plot(ema1hSlow, color = color.fuchsia)