变量没有成为一系列值。为什么?
我创建了此脚本来检测秋千高数和低点,然后确定这些摇摆的高值和低值。该代码适用于最后一个栏,但我希望这些值是我可以参考的系列,但事实并非如此。它只是保留最后值。不知道为什么。我包含了指示器的图片,其中包括最后5个摇摆高值的角落中的一个copeand桌子。...您可以看到,桌子上有不同的秋千高点,但表格中的值相同。这是代码:
//Swing Highs and Lows
swing_detection(index)=>
swing_high = false
swing_low = false
start = (index*2) - 1 // -1 so we have an even number of
swing_point_high = high[index]
swing_point_low = low[index]
//Swing Highs
for i = 0 to start
swing_high := true
if i < index
if high[i] > swing_point_high
swing_high := false
break
// Have to do checks before pivot and after seperately because we can get
// two highs of the same value in a row. Notice the > and >= difference
if i > index
if high[i] >= swing_point_high
swing_high := false
break
//Swing lows
for i = 0 to start
swing_low := true
if i < index
if low[i] < swing_point_low
swing_low := false
break
// Have to do checks before pivot and after seperately because we can get
// two lows of the same value in a row. Notice the > and >= difference
if i > index
if low[i] <= swing_point_low
swing_low := false
break
[swing_high, swing_low]
// Check for a swing
[swing_high, swing_low] = swing_detection(barsback)
//Determine Swing High and Low Values
var float swing_high_price = na
var float swing_low_price = na
if swing_high
swing_high_price := high[barsback]
if swing_low
swing_low_price := low[barsback]
I created this script to detect Swing Highs and Lows and then to determine the High and Low values of these Swings. The code works for the last bar, but I would like these values to be a series I can refer back to, but it's not. It's just retaining the last value. Not sure why. I included a picture of the indicator that includes this codeand a table in the corner with the last 5 swing high values....as you can see there are different swing highs but the same value in the table. Here is the code:
//Swing Highs and Lows
swing_detection(index)=>
swing_high = false
swing_low = false
start = (index*2) - 1 // -1 so we have an even number of
swing_point_high = high[index]
swing_point_low = low[index]
//Swing Highs
for i = 0 to start
swing_high := true
if i < index
if high[i] > swing_point_high
swing_high := false
break
// Have to do checks before pivot and after seperately because we can get
// two highs of the same value in a row. Notice the > and >= difference
if i > index
if high[i] >= swing_point_high
swing_high := false
break
//Swing lows
for i = 0 to start
swing_low := true
if i < index
if low[i] < swing_point_low
swing_low := false
break
// Have to do checks before pivot and after seperately because we can get
// two lows of the same value in a row. Notice the > and >= difference
if i > index
if low[i] <= swing_point_low
swing_low := false
break
[swing_high, swing_low]
// Check for a swing
[swing_high, swing_low] = swing_detection(barsback)
//Determine Swing High and Low Values
var float swing_high_price = na
var float swing_low_price = na
if swing_high
swing_high_price := high[barsback]
if swing_low
swing_low_price := low[barsback]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看不到任何明确构建系列/数组的代码,所以我想您期望
swing_high_price
是逐键添加值bar bar bar(由Pine Engine构建)时。但是,使用
var
定义的变量需要谨慎处理,否则您将在其系列中添加空白,而Pine通常会在其中barfs。而不是最后的IF结构,请尝试以下操作:
swing_high_price
将始终在每个栏上设置。这将导致连续的系列,这使Pine感到高兴。I don't see any code that explicitly builds a series/array so I suppose you expect
swing_high_price
to be the series as you add value bar-by-bar (built by the Pine engine automatically).However Variables defined with
var
needs to be handled with care or you will put gaps into their series, on which Pine usually barfs.Instead of the IF structure at the end, try this:
That is,
swing_high_price
will be always set on every bar. This will result in a continuous series, which keeps Pine happy.谢谢。我让它可以使用valuewhen()创建函数。
Thank you. I got it working creating a function using valuewhen().