【发布时间】:2020-05-04 08:26:35
【问题描述】:
在 tradingview 的 pine-script 中,我试图找到高于最后收盘价的前一个分形 (HF1),并绘制 HF1 的水平
到目前为止,我的代码并不能正常工作:
//@version=4
strategy("Fractal Breakout Strategy", overlay=true)
HF = bar_index>5 and high[2]>high[1] and high[2]>high and high[2]>high[3] and high[2]>high[4] ? -1 : 0
LF = bar_index>5 and low[2]<low[1] and low[2]<low and low[2]<low[3] and low[2]<low[4] ? 1 : 0
tot = HF + LF
pl = abs(tot)>=1 ? 1 : 0
//Plot fractal arrows:
plotarrow(pl==1 ? tot : na, colorup=color.teal, colordown=color.orange,offset=-2,maxheight=15)
HF1 = 0.0
for i = 0 to 40
HF1_temp = valuewhen(HF, high[2],i)
if (HF1_temp > close[1])
HF1 := HF1_temp
break
plot(HF1, color = color.blue)
我怀疑这与文档 here 中的最后一段有关
为避免这种情况,您可以使用自己的无状态函数实现。 这是具有相同行为的内置函数列表:
sma(source, length):长度是有状态的。
ema(source, length):长度是有状态的。
sum(source, length):长度是有状态的。
valuewhen(条件、来源、发生):发生是有状态的。
rsi(x, y):当 y 是整数类型并且表现得像一个长度时,y 是有状态的。
..但无法真正弄清楚如何实现这一点...任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: pine-script