Pine editor, RSI + Bollinger Bands

The entry script done in Pine Editor (trading view)

//@version=3
strategy(shorttitle=”joapenBB”, title=”joapen Bollinger Bands”, overlay=true)
/////////// inputs //////////
// RSI
length = input(14, minval=1)
overSold = input(25, minval=1)
overBought = input(75, minval=1)
price = close
// Bollinger Bands
src = input(close, title=”Source”)
mult = input(2.0, minval=0.001, maxval=50)
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis – dev
/////////// long and short conditions //////////
bbLongCondition = crossover(close, lower)
vrsi = rsi(price, length)
if (not na(vrsi))
if (crossover(vrsi, overSold) and bbLongCondition)
strategy.entry(“Long”, strategy.long, comment=”Long”)
if (crossunder(vrsi, overBought))
strategy.entry(“Short”, strategy.short, comment=”Short”)

plot(basis, color=red)
p1 = plot(upper, color=blue)
p2 = plot(lower, color=blue)
fill(p1, p2)

The outputs of the sample backtest:

LTCEUR (Coinbase):

  • share Ratio = 0.516 (1 minute)
  • share Ratio = 0.837 (7 minutes)
  • share Ratio = 0.808 (3 hours)
  • share Ratio = 0.814 (133 minutes)

ETHEUR (Coinbase):

  • share Ratio = 0.26 (1 minute)
  • share Ratio = 0.113 (7 minutes)
  • share Ratio = 0.88 (3 hours)
  • share Ratio = 0.634 (133 minutes)

Leave a Comment