At first, I was reading about popular indicators and playing around with them. I noticed that if Willy and RSI are plotted on the same chart, their crossovers can produce quite valid signals. I also noticed that overbought and oversold, adjusted to the volatility, can indicate where a position should be closed.
The problem, though, was making it work for different data sets. I tried it on several which appeared to be similar, but what gave massive gains on one set generated loss on another.
Finally, this is the best I managed to make:
//@version=4
strategy(title="WillyRSI", shorttitle="WRSI", initial_capital=2000, default_qty_type=strategy.percent_of_equity, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.2)
fromMonth = input (defval = 4, title = "From month", minval = 1)
fromDay = input (defval = 1, title = "From day", minval = 1)
fromYear = input (defval = 2020, title = "From year", minval = 2014)
toMonth = input (defval = 12, title = "To month", minval = 1)
toDay = input (defval = 1, title = "To day", minval = 1)
toYear = input (defval = 2020, title = "To year", minval = 2014)
timeInRange = (time > timestamp(fromYear, fromMonth, fromDay, 00, 00)) and (time < timestamp(toYear, toMonth, toDay, 23, 59))
len = input(14, minval=1, title="RSI length")
src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#ffff00)
length = input (defval=70, title="Willy length")
willy = 100*(lowest(length) - close)/(lowest(length) - highest(length))
plot(willy, "Willy", color=#3399ff)
ob1 = input (defval=80, title="Green overbought")
ob2 = input (defval=95, title="Blue overbought")
os1 = input (defval=20, title="Orange oversold")
os2 = input (defval=5, title="Red oversold")
plot(ob1, color=#009900)
plot(ob2, color=#005ce6)
plot(os1, color= #b35900)
plot(os2, color=#b32400)
longEntry=crossover(willy, rsi) and timeInRange
longExit=crossover(rsi, ob1) and timeInRange
longExit2=crossover(rsi, ob1) and timeInRange
shortEntry=crossover(rsi, willy) and timeInRange
shortExit=crossover(os2, willy) and timeInRange
shortExit2=crossover(os1, rsi) and timeInRange
strategy.entry(id="long", long=true, when=longEntry or shortExit)
strategy.close(id="long", when=longExit or longExit2)
//strategy.entry(id="shortn", long=false, when=shortEntry or longExit)
//strategy.close(id="short", when=shortExit or shortExit2)
I tried to keep it symmetric, but the shorts kept reducing profits. So my idea is that in a general bull market only the longs should be opened, closed when overbought and then opened again. In a bear market that would be done only with shorts.
Here’s what it looks like on the chart: