javascript - 基于 1 小时图的 5 分钟图的指数移动平均线
问题描述
我正在尝试使用 Pine Script 为交易视图编写指标。
我想根据 1 小时图编写一个 EMA 并在 5 分钟图中使用它。包括 8 和 34 交易期 (2 EMA)。那可能吗?
当我在 5 分钟图表中进行交易时,有助于查看更高的趋势。
这是我第一次尝试编写代码。
不幸的是我没有时间学习它。
如果有人能给我一些关于如何解决这个问题的尝试,那就太好了。
我试图用谷歌找到一些指南,但只有一些关于如何编写 EMA 的指南。
我发现的一切都是:
//@版本=3
// 在 pine 脚本的最开始,我们总是声明我们将要使用的版本, // 你可以看到,上面我们使用的是 pine 脚本的版本 3 // pine 脚本中的@version 字必须被注释在脚本的开头
study("在 pinescript 中编码 ema", overlay=true)
// 这是我们定义研究的地方, // pinescipt 中的研究函数用于告诉 pine 脚本我们将构建一个指标 // 使用“overlay=true”,让 pine 脚本知道您想将图表中的图叠加到 // 烛台图表上。
// 现在我们定义一个名为 pine_ema 的 EMA 函数,带有 2 个参数 x 和 y // 这个 pine_ema 函数的唯一目的是返回当前蜡烛收盘价的当前 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(close, 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)
推荐阅读
- spring-boot - Spring boot,Tomcat无法识别JSF bean
- javascript - 如何使用类 Javascript 删除现有 ul 中的 li
- javascript - 从 Coldfusion 调用 javascript 函数
- ios - PNG图像未写入画廊
- postgresql - Postgres SELECT 行加上带有条件的下一行
- pybind11 - Pybind11 - 返回指向 unique_ptr 容器的指针
- python - 带有自定义处理程序的 SQLAlchemy 日志记录冻结
- sql - 更新另一个表中的列,其中 datetime 在另一列中有多个值
- rxjs6 - 合并/合并到数组
- c# - 微服务架构 CQRS