移动平均线只显示到最后 ticker.id 收盘
Moving average line is only shown till last ticker.id close
我正在研究移动平均线指标,它显示给定时间范围内的 MA 线。
出于某种原因,MA 线仅在最后一个 ticker.id 周期收盘时才移动。因此,例如,当我将指标设置为显示每日 MA 时,该线仅在当天结束时更新。
(Link 到图像 https://i.stack.imgur.com/QjkvO.jpg)
有谁知道我的指标如何能够包含每日收盘之间的数据,所以该线会不断更新?
我认为这条线没有持续更新也会导致标签被绘制在图表上的 1 点/美元高度处。
我最近才开始写代码,如果这是一个愚蠢的问题,请原谅。我已经编写了这段代码,查看其他指标并尝试将部分内容放入我自己的
这是整个指标的代码。
//@version=4
study(title="Custom Timeframe SMA", shorttitle="Custom TF MA", overlay=true)
res = input(title="MA Timeframe", type=input.resolution, defval="D",options=["60", "240", "D", "W"])
length1 = input(title="SMA Length", type=input.integer, defval=50)
Label=input(title="show Labels",defval=true)
sma1 = sma(close, length1)
sourceEmaSmooth1 = security(syminfo.tickerid, res, sma1, barmerge.gaps_on, barmerge.lookahead_on)
plot(sourceEmaSmooth1, style=plot.style_line, linewidth=2, title="25 period", color=#a21e7b)
plotchar((sourceEmaSmooth1 ? Label : barstate.islast and not barstate.isconfirmed) ? sourceEmaSmooth1 : na, location=location.absolute, text=" 50 SMA", textcolor=#a21e7b, offset=10, editable=false)
将 barmerge.gaps_on
与 security()
一起使用会创建 漏洞 ,这些漏洞在图表的分辨率下显示为 na
值,这就是为什么您的 ma' t总是显示。它在历史柱上并不明显,因为 plot()
函数将 space 从非缺口填充到非缺口(如果您绘制圆圈而不是直线,您可以看到它)。
将 barmerge.lookahead_on
与 security()
一起使用会在历史柱上产生前瞻性偏差。如果您不为所获取的值编制索引,那将非常糟糕,如本出版物中有关如何正确使用 security()
的解释:How to avoid repainting when using security().
我向您添加了 show_last = 1
标签绘制调用并修复了条件。因为它现在只绘制最后一次出现的标签,我们不再需要担心条形图:
//@version=4
study(title="Custom Timeframe SMA", shorttitle="Custom TF MA", overlay=true)
res = input(title="MA Timeframe", type=input.resolution, defval="D",options=["60", "240", "D", "W"])
length1 = input(title="SMA Length", type=input.integer, defval=50)
Label=input(title="show Labels",defval=true)
sma1 = sma(close, length1)
sourceEmaSmooth1 = security(syminfo.tickerid, res, sma1)
plot(sourceEmaSmooth1, linewidth=2, title="25 period", color=#a21e7b)
plotchar(Label ? sourceEmaSmooth1 : na, location=location.absolute, text=" 50 SMA", textcolor=#a21e7b, offset=10, show_last = 1, editable=false)
我正在研究移动平均线指标,它显示给定时间范围内的 MA 线。 出于某种原因,MA 线仅在最后一个 ticker.id 周期收盘时才移动。因此,例如,当我将指标设置为显示每日 MA 时,该线仅在当天结束时更新。
(Link 到图像 https://i.stack.imgur.com/QjkvO.jpg)
有谁知道我的指标如何能够包含每日收盘之间的数据,所以该线会不断更新?
我认为这条线没有持续更新也会导致标签被绘制在图表上的 1 点/美元高度处。
我最近才开始写代码,如果这是一个愚蠢的问题,请原谅。我已经编写了这段代码,查看其他指标并尝试将部分内容放入我自己的
这是整个指标的代码。
//@version=4
study(title="Custom Timeframe SMA", shorttitle="Custom TF MA", overlay=true)
res = input(title="MA Timeframe", type=input.resolution, defval="D",options=["60", "240", "D", "W"])
length1 = input(title="SMA Length", type=input.integer, defval=50)
Label=input(title="show Labels",defval=true)
sma1 = sma(close, length1)
sourceEmaSmooth1 = security(syminfo.tickerid, res, sma1, barmerge.gaps_on, barmerge.lookahead_on)
plot(sourceEmaSmooth1, style=plot.style_line, linewidth=2, title="25 period", color=#a21e7b)
plotchar((sourceEmaSmooth1 ? Label : barstate.islast and not barstate.isconfirmed) ? sourceEmaSmooth1 : na, location=location.absolute, text=" 50 SMA", textcolor=#a21e7b, offset=10, editable=false)
将 barmerge.gaps_on
与 security()
一起使用会创建 漏洞 ,这些漏洞在图表的分辨率下显示为 na
值,这就是为什么您的 ma' t总是显示。它在历史柱上并不明显,因为 plot()
函数将 space 从非缺口填充到非缺口(如果您绘制圆圈而不是直线,您可以看到它)。
将 barmerge.lookahead_on
与 security()
一起使用会在历史柱上产生前瞻性偏差。如果您不为所获取的值编制索引,那将非常糟糕,如本出版物中有关如何正确使用 security()
的解释:How to avoid repainting when using security().
我向您添加了 show_last = 1
标签绘制调用并修复了条件。因为它现在只绘制最后一次出现的标签,我们不再需要担心条形图:
//@version=4
study(title="Custom Timeframe SMA", shorttitle="Custom TF MA", overlay=true)
res = input(title="MA Timeframe", type=input.resolution, defval="D",options=["60", "240", "D", "W"])
length1 = input(title="SMA Length", type=input.integer, defval=50)
Label=input(title="show Labels",defval=true)
sma1 = sma(close, length1)
sourceEmaSmooth1 = security(syminfo.tickerid, res, sma1)
plot(sourceEmaSmooth1, linewidth=2, title="25 period", color=#a21e7b)
plotchar(Label ? sourceEmaSmooth1 : na, location=location.absolute, text=" 50 SMA", textcolor=#a21e7b, offset=10, show_last = 1, editable=false)