Reputation: 61
I can't see why this script is not finding anything to plot.
The idea is to plot the lowest low only if it fullfils a condition, and also plot the highest high only if it fullfills a different condition.
These conditions respectively are a retracement larger than the excursion of a mirror length prior to the lowest low, and likewise for the highest high, a retracement larger than the excursion of a mirror length prior to the highest high.
//@version=5
indicator(title="Highest Low Since Lowest Low", shorttitle='HLsLL', overlay=true)
length = input.int(defval = 500, title = "length")
var float lowestLow = na
lowestLow := ta.lowest(length)
var float highestHigh = na
highestHigh := ta.highest(length)
twiceLengthLL = 2 * ta.barssince(low == lowestLow)
twiceLengthHH = 2 * ta.barssince(high == highestHigh)
preLow = low[twiceLengthLL]
preHigh = high[twiceLengthHH]
bool retraceLL = low - lowestLow >= preLow - lowestLow
bool retraceHH = highestHigh - high >= highestHigh - preHigh
bool newLL = ta.barssince(lowestLow) < ta.barssince(highestHigh)
bool newHH = ta.barssince(lowestLow) > ta.barssince(highestHigh)
var float validLow = na
if retraceLL and newLL
validLow := math.min(validLow, low)
var float validHigh = na
if retraceHH and newHH
validHigh := math.max(validHigh, high)
colorVH = color.new(color.silver, 0)
plotVH = plot(series=validHigh, title='Highest High', color=colorVH, linewidth=1, style=plot.style_line, editable=true)
colorVL = color.new(color.yellow, 0)
plotVL = plot(series=validLow, title='Valid Low', color=colorVL, linewidth=1, style=plot.style_line, editable=true)
// end of script
Upvotes: 0
Views: 1159
Reputation: 21342
The following code does not make any sense.
bool newLL = ta.barssince(lowestLow) < ta.barssince(highestHigh)
bool newHH = ta.barssince(lowestLow) > ta.barssince(highestHigh)
ta.barssince()
expects a condition as an argument but you are just passing a variable of type series
.
lowestLow := ta.lowest(length)
highestHigh := ta.highest(length)
Since you are not passing a condition, both ta.barssince(lowestLow)
and ta.barssince(highestHigh)
return 0
. So, both newLL
and newHH
are false
. As a result, you never update validHigh
and validLow
and they remain as na
. So, no plots.
Upvotes: 0