简体   繁体   中英

lowest low on a condition and highest high on another condition

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

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.

I changed the code in order to pass a condition to ta.barssince but the script is still not finding anything to plot:
bool newLL = ta.barssince(low == lowestLow) < ta.barssince(high == highestHigh)

bool newHH = ta.barssince(low == lowestLow) > ta.barssince(high == highestHigh)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM