I wish to learn and complete the indicator. The attempt is that the indicator will detect the Long and Short signal in the condition that "Long" when the %R exceed Higher limit and return to cross -50 within (INPUT) bars. and "Short" when the %R is exceed the Lower Limit and return to cross -50 within (INPUT) bars. The problem is the part that "how to code the indi to detect cross -50 within (INPUT) bars".
//@version=4
study("Williams %R by Stamp", shorttitle="%R by stamp", format=format.price, overlay=true ,precision=2, resolution="")
length = input(title="Length", type=input.integer, defval=14)
src = input(close, "Source", type = input.source)
_pr(length) =>
max = highest(length)
min = lowest(length)
100 * (src - max) / (max - min)
percentR = _pr(length)
highlim = input(defval=-2.0, title="High Limit")
lowlim = input(defval=-98.0), title="Low Limit"
percentRhigh = percentR> highlim // %R higher than -2
highend = crossunder(percentR,highlim) // %R cross down -2
percentRlow = percentR< lowlim // %R lower than -98
lowend = crossover(percentR,lowlim) // %R cross up -98
crossing50 = cross(percentR,-50)
crossup = crossover(percentR,-50)
crossdown = crossunder(percentR,-50)
//
//
// <------- I HAVE BIG PROBLEM FROM THIS PART
//
quickdown = highend[5] or highend[4] or highend[3] or highend[2] or highend[1]
quickup = lowend[5] or lowend[4] or lowend[3] or lowend[4] or lowend[1]
quickdowna = quickdown and crossdown // signal condition for short
quickupa = quickup and crossup // signal condition for long
justquick = quickdowna or quickupa // signal whatever long or short
bgcolor(justquick ? color.yellow : na, transp=94)
//
//
bgcolor(highend ? color.red : na, transp=94)
bgcolor(lowend ? color.green : na, transp=94)
plotshape(crossup, title="Long", style=shape.triangleup, location=location.belowbar, color=color.green, transp=90, text="Long", textcolor=color.green, size=size.auto)
plotshape(crossdown, title="Short", style=shape.triangledown, location=location.abovebar, color=color.red, transp=90, text="Short", textcolor=color.red, size=size.auto)
///
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…