使用tradingview的安全功能,如何平滑缺口?

发布于 2025-01-09 15:01:41 字数 2000 浏览 1 评论 0原文

我正在尝试在 15 分钟图表上绘制多个时间范围 EMA,这是我的代码。


//@version=5
indicator(title='higher tf', overlay=true)


// 4 hr

show_4h = input(title='Show 4 hour', defval=true, group = "4 HOUR")

show_ema20_4 = input(title='Show 20 EMA of 4 hour', defval=true, group = "4 HOUR")
ema20_4_period = input(title='20 EMA of 4 hour Period', defval=20, group = "4 HOUR")

show_ema50_4 = input(title='Show 50 EMA of 4 hour', defval=true, group = "4 HOUR")
ema50_4_period = input(title='50 EMA of 4 hour Period', defval=50, group = "4 HOUR")

show_ema100_4 = input(title='Show 100 EMA of 4 hour', defval=true, group = "4 HOUR")
ema100_4_period = input(title='100 EMA of 4 hour Period', defval=100, group = "4 HOUR")

show_ema200_4 = input(title='Show 200 EMA of 4 hour', defval=true, group = "4 HOUR")
ema200_4_period = input(title='200 EMA of 4 hour Period', defval=200, group = "4 HOUR")

ema20_4 = request.security(syminfo.tickerid, '360', ta.ema(close, ema20_4_period),lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema50_4 = request.security(syminfo.tickerid, '360', ta.ema(close, ema50_4_period),lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema100_4 = request.security(syminfo.tickerid, '360', ta.ema(close, ema100_4_period), lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema200_4 = request.security(syminfo.tickerid, '360', ta.ema(close, ema200_4_period), lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)


plot(show_4h ? show_ema20_4 ? ema20_4 : na : na, title='20 EMA 4 hour')
plot(show_4h ?show_ema50_4?ema50_4: na : na, title="50 EMA 4 hour")
plot(show_4h ?show_ema100_4?ema100_4: na : na, title="100 EMA 4 hour")
plot(show_4h ?show_ema200_4?ema200_4: na : na, title="200 EMA 4 hour")

绘图时,图表上有步骤。

然而,当我使用内置指标并将时间范围更改为 4 小时时,该线完全平滑。

这就是它的样子。

输入图片这里的描述

红线是内置指标,蓝线是我的指标。

怎样才能让线条流畅呢?

I am trying to plot multiple timeframe EMA on 15 min chart, this is my code.


//@version=5
indicator(title='higher tf', overlay=true)


// 4 hr

show_4h = input(title='Show 4 hour', defval=true, group = "4 HOUR")

show_ema20_4 = input(title='Show 20 EMA of 4 hour', defval=true, group = "4 HOUR")
ema20_4_period = input(title='20 EMA of 4 hour Period', defval=20, group = "4 HOUR")

show_ema50_4 = input(title='Show 50 EMA of 4 hour', defval=true, group = "4 HOUR")
ema50_4_period = input(title='50 EMA of 4 hour Period', defval=50, group = "4 HOUR")

show_ema100_4 = input(title='Show 100 EMA of 4 hour', defval=true, group = "4 HOUR")
ema100_4_period = input(title='100 EMA of 4 hour Period', defval=100, group = "4 HOUR")

show_ema200_4 = input(title='Show 200 EMA of 4 hour', defval=true, group = "4 HOUR")
ema200_4_period = input(title='200 EMA of 4 hour Period', defval=200, group = "4 HOUR")

ema20_4 = request.security(syminfo.tickerid, '360', ta.ema(close, ema20_4_period),lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema50_4 = request.security(syminfo.tickerid, '360', ta.ema(close, ema50_4_period),lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema100_4 = request.security(syminfo.tickerid, '360', ta.ema(close, ema100_4_period), lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema200_4 = request.security(syminfo.tickerid, '360', ta.ema(close, ema200_4_period), lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)


plot(show_4h ? show_ema20_4 ? ema20_4 : na : na, title='20 EMA 4 hour')
plot(show_4h ?show_ema50_4?ema50_4: na : na, title="50 EMA 4 hour")
plot(show_4h ?show_ema100_4?ema100_4: na : na, title="100 EMA 4 hour")
plot(show_4h ?show_ema200_4?ema200_4: na : na, title="200 EMA 4 hour")

on plotting, there are steps on the graph.

However, when I use the in-built indicator and change the timeframe to 4 hour that line is completely smooth.

This is how it looks like.

enter image description here

the red line is the in-built indicator and the blue line is my indicator.

How can I make the line smooth?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尹雨沫 2025-01-16 15:01:41

您只需将“timeframe_gaps=true”添加到您的indicator()中即可。

indicator(title='higher tf', overlay=true, timeframe_gaps=true)

如果您想向 strategy() 添加时间范围间隙,则必须向变量添加“barmerge.gaps_on”。

You can just add "timeframe_gaps=true" to your indicator().

indicator(title='higher tf', overlay=true, timeframe_gaps=true)

If u want to add timeframe gaps to a strategy() you have to add "barmerge.gaps_on" to your variable.

执手闯天涯 2025-01-16 15:01:41

您面临这个问题,因为您将指数移动平均线“EMA”的时间范围值设为360,这意味着6 小时,因此一旦您打开任何图表,EMA 将针对6小时,您应该将其更改为timeframe.period,使其成为类似于时间范围时间范围.period

//@version=5
indicator(title='higher tf', overlay=true)


// 4 hr

show_4h = input(title='Show 4 hour', defval=true, group = "4 HOUR")

show_ema20_4 = input(title='Show 20 EMA of 4 hour', defval=true, group = "4 HOUR")
ema20_4_period = input(title='20 EMA of 4 hour Period', defval=20, group = "4 HOUR")

show_ema50_4 = input(title='Show 50 EMA of 4 hour', defval=true, group = "4 HOUR")
ema50_4_period = input(title='50 EMA of 4 hour Period', defval=50, group = "4 HOUR")

show_ema100_4 = input(title='Show 100 EMA of 4 hour', defval=true, group = "4 HOUR")
ema100_4_period = input(title='100 EMA of 4 hour Period', defval=100, group = "4 HOUR")

show_ema200_4 = input(title='Show 200 EMA of 4 hour', defval=true, group = "4 HOUR")
ema200_4_period = input(title='200 EMA of 4 hour Period', defval=200, group = "4 HOUR")

ema20_4 = request.security(syminfo.tickerid, timeframe.period, ta.ema(close, ema20_4_period),lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema50_4 = request.security(syminfo.tickerid, timeframe.period, ta.ema(close, ema50_4_period),lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema100_4 = request.security(syminfo.tickerid, timeframe.period, ta.ema(close, ema100_4_period), lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema200_4 = request.security(syminfo.tickerid, timeframe.period, ta.ema(close, ema200_4_period), lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)


plot(show_4h ? show_ema20_4 ? ema20_4 : na : na, title='20 EMA 4 hour')
plot(show_4h ?show_ema50_4?ema50_4: na : na, title="50 EMA 4 hour")
plot(show_4h ?show_ema100_4?ema100_4: na : na, title="100 EMA 4 hour")
plot(show_4h ?show_ema200_4?ema200_4: na : na, title="200 EMA 4 hour")

You face this problem, because you make the values of timeframe for exponential moving average "EMA" is 360 which mean 6 hours so once you open any chart the EMA will be for 6 hours, you should to change it to timeframe.period to be the EMA similar to timeframe timeframe.period

//@version=5
indicator(title='higher tf', overlay=true)


// 4 hr

show_4h = input(title='Show 4 hour', defval=true, group = "4 HOUR")

show_ema20_4 = input(title='Show 20 EMA of 4 hour', defval=true, group = "4 HOUR")
ema20_4_period = input(title='20 EMA of 4 hour Period', defval=20, group = "4 HOUR")

show_ema50_4 = input(title='Show 50 EMA of 4 hour', defval=true, group = "4 HOUR")
ema50_4_period = input(title='50 EMA of 4 hour Period', defval=50, group = "4 HOUR")

show_ema100_4 = input(title='Show 100 EMA of 4 hour', defval=true, group = "4 HOUR")
ema100_4_period = input(title='100 EMA of 4 hour Period', defval=100, group = "4 HOUR")

show_ema200_4 = input(title='Show 200 EMA of 4 hour', defval=true, group = "4 HOUR")
ema200_4_period = input(title='200 EMA of 4 hour Period', defval=200, group = "4 HOUR")

ema20_4 = request.security(syminfo.tickerid, timeframe.period, ta.ema(close, ema20_4_period),lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema50_4 = request.security(syminfo.tickerid, timeframe.period, ta.ema(close, ema50_4_period),lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema100_4 = request.security(syminfo.tickerid, timeframe.period, ta.ema(close, ema100_4_period), lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
ema200_4 = request.security(syminfo.tickerid, timeframe.period, ta.ema(close, ema200_4_period), lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)


plot(show_4h ? show_ema20_4 ? ema20_4 : na : na, title='20 EMA 4 hour')
plot(show_4h ?show_ema50_4?ema50_4: na : na, title="50 EMA 4 hour")
plot(show_4h ?show_ema100_4?ema100_4: na : na, title="100 EMA 4 hour")
plot(show_4h ?show_ema200_4?ema200_4: na : na, title="200 EMA 4 hour")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文