PineScript 将来创建一个带有 n 个蜡烛的源,用于 Tradingview 中的预测 [英] PineScript create a source with n Candles in future for forcasts in Tradingview
问题描述
除了我在 EMA for One 中的问题未来的蜡烛我现在正在尝试修改 Tradingview 中某些预测的来源.
in addition to my question in EMA for One Candle in Future I'm now trying to modify a source for some forecasts in Tradingview.
在此修改中,我想以这种方式修改默认系列,即我将系列 N 中的每根蜡烛都移到过去,并用最新的柱线覆盖然后空出的位置.
In this modification I would like to modify the default series in that way, that I move every candle in the series N places into the past and overwrite the the places that were then vacated with the newest bar.
我只需要在当前柱上执行此操作,因为我想将 offset=n 的结果绘制到未来.
I only need to do this on the current bar, as I want to plot the result with offset=n into the future.
当前的想法正在遵循,但我无法编译.错误是输入="处的语法错误.你能帮我创建这个函数吗?
Current idea is following, but I cannot compile. Error is Syntax error at input '='. Could you help me to create this function please?
非常感谢.
//@version=4
study(title="candle experiment", shorttitle="candle_experiement")
sourcePlusTwoCandle(src , length) =>
newSource := na
for i = 2 to length+2
newSource[i]=src[i-2] //move every value places into the past
newSource[1]=src[0] //overwrite the "vacated place" with current bar
newSource[0]=src[0] //overwrite the "vacated place" with current bar
candles = 0.0
if not barstate.isconfirmed
candles = sourcePlusTwoCandle(close, 20)
plot(candles, color=color.white,offset=2,linewidth=6)
推荐答案
你应该使用赋值运算符的方式是这样的:
The way you should use the assignment operator is like this:
//@version=4
study(title="candle experiment", shorttitle="candle_experiement")
var float newSource = na
var float candles = na
sourcePlusTwoCandle(src, length) =>
newSource := na
for i = 2 to length+2
newSource[i] := src[i-2] //move every value places into the past
newSource[1] := src[0] //overwrite the "vacated place" with current bar
newSource[0] := src[0] //overwrite the "vacated place" with current bar
candles := 0.0
if not barstate.isconfirmed
candles := sourcePlusTwoCandle(close, 20)
plot(candles, color=color.white,offset=2,linewidth=6)
但这也不会编译,因为您过去试图为条形赋值.
这在 Pine 中是做不到的.为什么会这样,在 我可以使用 :=
运算符为系列的过去值赋值吗?
But that too won't compile, because you're trying to assign a value to a bar in the past.
That cannot be done in Pine. Why that is, is explained in Can I use the :=
operator to assign values to past values of a series?
这篇关于PineScript 将来创建一个带有 n 个蜡烛的源,用于 Tradingview 中的预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!