条件(应该)满足但预期的动作(plotchar)没有发生
Condition is (supposedly) met but expected action (plotchar) doesn't happen
我正在尝试创建一个筛选器。从绘图开始:
(a) 两条红色直线水平线标记回顾期的最高价和最低价。
(b) 两条蓝色直线水平线标记此范围内的 25% 和 75% 点。
请查看屏幕截图。
我的问题是:当满足以下所有四个条件时,它应该标记 (plotchar),但它不工作 atm。
(1) 前半段高位至少一次处于区间上轨
(2) 前半段至少有一次低位处于下轨
(3) 后半期,高位至少一次处于区间上轨。
(4) 下半期低位下穿区间线
除非我遗漏了什么,否则屏幕截图中的所有这四个条件都满足,因此应该用蜡烛图绘制|4| (当 LOW CROSSES-UNDER LOW RANGE LINE 时),但没有绘制任何东西。
非常感谢任何帮助!
下面是代码的相关部分,但是 all code is here 如果您想检查 and/or 重新使用。
lookBack = input(title="Lookback", type=input.integer, defval=24, minval=2)
range = input(title="Upper & Lower Range", type=input.integer, defval=4, minval=10)
// INDICATORS & VARIABLES
highestHigh = highest(high, lookBack)
lowestLow = lowest(low, lookBack)
xAxisStartsAt = bar_index[lookBack]
xAxisFinishesAt = bar_index
upperLimit = highestHigh
lowerLimit = lowestLow
upperRange = ((highestHigh - lowestLow)/range) + lowestLow
lowerRange = highestHigh - ((highestHigh - lowestLow)/range)
HighAboveUpperRange = high > upperRange
LowBelowLowerRange = low < lowerRange
occurrencesAboveTotal = sum(HighAboveUpperRange ? 1 : 0, lookBack)
occurrencesAboveSecondHalf = sum(HighAboveUpperRange ? 1 : 0, lookBack/2)
occurrencesAboveFirstHalf = occurrencesAboveTotal - occurrencesAboveSecondHalf
occurrencesBelowTotal = sum(LowBelowLowerRange ? 1 : 0, lookBack)
occurrencesBelowSecondHalf = sum(LowBelowLowerRange ? 1 : 0, lookBack/2)
occurrencesBelowFirstHalf = occurrencesBelowTotal - occurrencesBelowSecondHalf
// STRATEGY
triggerA = occurrencesAboveFirstHalf >= 1 ? true : false
triggerB = occurrencesAboveSecondHalf >= 1 ? true : false
triggerC = occurrencesBelowFirstHalf >= 1 ? true : false
triggerD = crossunder(low, lowerRange)
condition = triggerA and triggerB and triggerC and triggerD
// PAINTBRUSH
plotchar(condition)
更新
在第二个和第三个屏幕截图中,绘制了星星 (plotchar),但不是预期的位置(当 LOW 穿过较低的蓝色 line/lower 范围(条件 4)时,它们是预期的)。
在你的脚本中,确定范围的公式混淆了,你有这样
upperRange = ((highestHigh - lowestLow)/range) + lowestLow
lowerRange = highestHigh - ((highestHigh - lowestLow)/range)
但应该是这样的
lowerRange = ((highestHigh - lowestLow)/range) + lowestLow
upperRange = highestHigh - ((highestHigh - lowestLow)/range)
在你的脚本中添加调试行,你会看到很多有用的信息
plot(lowerRange,color=color.red)
plot(upperRange,color=color.green)
plot(low, color=color.black)
我不确定,但在我看来 crossunder(low, lowerRange)
这不是您要测试的条件。
祝你好运。
我正在尝试创建一个筛选器。从绘图开始:
(a) 两条红色直线水平线标记回顾期的最高价和最低价。
(b) 两条蓝色直线水平线标记此范围内的 25% 和 75% 点。
请查看屏幕截图。
我的问题是:当满足以下所有四个条件时,它应该标记 (plotchar),但它不工作 atm。
(1) 前半段高位至少一次处于区间上轨
(2) 前半段至少有一次低位处于下轨
(3) 后半期,高位至少一次处于区间上轨。
(4) 下半期低位下穿区间线
除非我遗漏了什么,否则屏幕截图中的所有这四个条件都满足,因此应该用蜡烛图绘制|4| (当 LOW CROSSES-UNDER LOW RANGE LINE 时),但没有绘制任何东西。
非常感谢任何帮助!
下面是代码的相关部分,但是 all code is here 如果您想检查 and/or 重新使用。
lookBack = input(title="Lookback", type=input.integer, defval=24, minval=2)
range = input(title="Upper & Lower Range", type=input.integer, defval=4, minval=10)
// INDICATORS & VARIABLES
highestHigh = highest(high, lookBack)
lowestLow = lowest(low, lookBack)
xAxisStartsAt = bar_index[lookBack]
xAxisFinishesAt = bar_index
upperLimit = highestHigh
lowerLimit = lowestLow
upperRange = ((highestHigh - lowestLow)/range) + lowestLow
lowerRange = highestHigh - ((highestHigh - lowestLow)/range)
HighAboveUpperRange = high > upperRange
LowBelowLowerRange = low < lowerRange
occurrencesAboveTotal = sum(HighAboveUpperRange ? 1 : 0, lookBack)
occurrencesAboveSecondHalf = sum(HighAboveUpperRange ? 1 : 0, lookBack/2)
occurrencesAboveFirstHalf = occurrencesAboveTotal - occurrencesAboveSecondHalf
occurrencesBelowTotal = sum(LowBelowLowerRange ? 1 : 0, lookBack)
occurrencesBelowSecondHalf = sum(LowBelowLowerRange ? 1 : 0, lookBack/2)
occurrencesBelowFirstHalf = occurrencesBelowTotal - occurrencesBelowSecondHalf
// STRATEGY
triggerA = occurrencesAboveFirstHalf >= 1 ? true : false
triggerB = occurrencesAboveSecondHalf >= 1 ? true : false
triggerC = occurrencesBelowFirstHalf >= 1 ? true : false
triggerD = crossunder(low, lowerRange)
condition = triggerA and triggerB and triggerC and triggerD
// PAINTBRUSH
plotchar(condition)
更新
在第二个和第三个屏幕截图中,绘制了星星 (plotchar),但不是预期的位置(当 LOW 穿过较低的蓝色 line/lower 范围(条件 4)时,它们是预期的)。
在你的脚本中,确定范围的公式混淆了,你有这样
upperRange = ((highestHigh - lowestLow)/range) + lowestLow
lowerRange = highestHigh - ((highestHigh - lowestLow)/range)
但应该是这样的
lowerRange = ((highestHigh - lowestLow)/range) + lowestLow
upperRange = highestHigh - ((highestHigh - lowestLow)/range)
在你的脚本中添加调试行,你会看到很多有用的信息
plot(lowerRange,color=color.red)
plot(upperRange,color=color.green)
plot(low, color=color.black)
我不确定,但在我看来 crossunder(low, lowerRange)
这不是您要测试的条件。
祝你好运。