0

When plotting the Stochastics K line, Pine chops off my peaks and valleys at 100 and 0. Is there a way to stretch beyond this scale and get true peaks and valleys? (How would I modify the 0 to 100?)

Plateaus

My code:

rsiLength = input(title="RSI Length", type=input.integer, defval=14)
lbLength = input(title="Look Back Length", type=input.integer, defval=5)
avgLength = input(title="Average Length", type=input.integer, defval=8)
drawSig = input(title="Signal On/Off?", type=input.bool, defval=false)
sigLength = input(title="Signal Length", type=input.integer, defval=6)
src = input(title="Source", type=input.source, defval=close)
ob = input(title="Over Bought", type=input.float, defval=50.0)
os = input(title="Over Sold", type=input.float, defval=30.0)


// Calculate Stochastics
rsi = rsi(src, rsiLength)
k = sma(stoch(rsi, rsi, rsi, lbLength), avgLength)


plot(series=k, title="Stochastics K", color=color.orange, linewidth=2)


h1 = hline(price=ob, title="Overbought", color=color.red)
h2 = hline(price=os, title="Oversold", color=color.green)
hline(price=(ob + os) / 2, title="Center", color=color.gray, linestyle=hline.style_dashed)

The picture shows different length inputs, but I don't remember what they were (I was playing around with them)

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

The stochastic oscillator is range-bound (0-100) by nature. It will always be within the 0-100 range.

Formula: 100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length))

ta.stoch(source, high, low, length) → series float
vitruvius
  • 15,740
  • 3
  • 16
  • 26