Strategy · Pine Script v5 · Own pane

Williams %R Reversal - Eterna MCP

by EternaHybridExchange

This strategy tracks the Williams %R oscillator to trade mean-reversion bounces from overbought and oversold extremes.

View on GitHub

GitHub stars9on the repository
Pine versionv5runs as is
Lines of code84
Settings6inputs
LicenceMIT
Last update7 months ago12 Mar 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

84 lines of Pine Script v5 from strategies/momentum/williams_r_reversal.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

williams_r_reversal.pine
//@version=5
strategy("Williams %R Reversal - Eterna MCP", 
         shorttitle="Williams %R",
         overlay=false,
         default_qty_type=strategy.percent_of_equity,
         default_qty_value=100,
         initial_capital=1000)

// ============================================
// PARAMETERS
// ============================================
wrLength = input.int(14, "Williams %R Length", minval=1)
overboughtLevel = input.int(-20, "Overbought Level", minval=-50, maxval=0)
oversoldLevel = input.int(-80, "Oversold Level", minval=-100, maxval=-50)
confirmBars = input.int(2, "Confirmation Bars", minval=1, maxval=5)
leverageSize = input.float(5.0, "Leverage", minval=1, maxval=100)
positionSize = input.float(0.01, "Position Size", minval=0.001, maxval=1)

// ============================================
// WILLIAMS %R CALCULATION
// ============================================
upper = ta.highest(high, wrLength)
lower = ta.lowest(low, wrLength)
wr = -100 * (upper - close) / (upper - lower)

// ============================================
// REVERSAL DETECTION
// ============================================
// Bullish reversal: WR crosses above oversold level
bullishReversal = ta.crossover(wr, oversoldLevel)

// Bearish reversal: WR crosses below overbought level
bearishReversal = ta.crossunder(wr, overboughtLevel)

// Confirmation: price action supports reversal
var int bullishConfirm = 0
var int bearishConfirm = 0

if bullishReversal
    bullishConfirm := confirmBars
if bearishReversal
    bearishConfirm := confirmBars

if bullishConfirm > 0
    bullishConfirm := bullishConfirm - 1
if bearishConfirm > 0
    bearishConfirm := bearishConfirm - 1

// Strong signals: reversal with momentum
strongBullish = bullishReversal and wr < oversoldLevel and close > close[1]
strongBearish = bearishReversal and wr > overboughtLevel and close < close[1]

// ============================================
// STRATEGY LOGIC
// ============================================
if strongBullish and strategy.position_size == 0
    strategy.entry("Long", strategy.long)
    alert('{"action":"buy","symbol":"' + syminfo.ticker + '","size":' + str.tostring(positionSize) + ',"leverage":' + str.tostring(leverageSize) + '}', alert.freq_once_per_bar_close)

if strongBearish and strategy.position_size == 0
    strategy.entry("Short", strategy.short)
    alert('{"action":"sell","symbol":"' + syminfo.ticker + '","size":' + str.tostring(positionSize) + ',"leverage":' + str.tostring(leverageSize) + '}', alert.freq_once_per_bar_close)

// Exit on opposite reversal
if strongBearish and strategy.position_size > 0
    strategy.close("Long")

if strongBullish and strategy.position_size < 0
    strategy.close("Short")

// ============================================
// PLOTTING
// ============================================
plot(wr, "Williams %R", color=color.blue, linewidth=2)
hline(overboughtLevel, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(oversoldLevel, "Oversold", color=color.green, linestyle=hline.style_dashed)
hline(-50, "Midline", color=color.gray, linestyle=hline.style_dotted)

// Color zones
bgcolor(wr > overboughtLevel ? color.new(color.red, 95) : na)
bgcolor(wr < oversoldLevel ? color.new(color.green, 95) : na)

plotshape(strongBullish, "Buy", shape.triangleup, location.bottom, color.green, size=size.normal)
plotshape(strongBearish, "Sell", shape.triangledown, location.top, color.red, size=size.normal)

Overview

Williams %R Reversal - Eterna MCP opens long or short positions when a reversal signal occurs alongside confirming price direction, while generating JSON-formatted alert payloads for automated execution. Positions are closed when an opposing reversal signal appears. Displayed in a separate pane below the chart, it plots the oscillator line, reference levels, and signal markers. It does not include hard stop-loss or take-profit orders.

Details

Published by

EternaHybridExchange on GitHub

Type

Strategy, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Mean reversion

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingautomated-tradingbacktestingbybitcrypto-tradingeternamcppine-scripttrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Williams %R Lengthint14wrLength
Overbought Levelint-20overboughtLevel
Oversold Levelint-80oversoldLevel
Confirmation Barsint2confirmBars
Leveragefloat5.0leverageSize
Position Sizefloat0.01positionSize
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This strategy combines Larry Williams' Vix Fix synthetic volatility indicator with Bollinger Bands. It calculates standard and inverted Williams Vix Fix metrics, displaying them as histogram columns with standard deviation bands in a separate pane. Long entrie

Strategy v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Williams Vix Fix Strategy [Alorse]

2xTP, SL to Entry

by hasnocool
106 stars

This strategy executes mean-reversion trades based on Bollinger Bands and the Stochastic Oscillator. Long orders trigger when price dips below the lower band alongside a bullish Stochastic crossover, with an optional oversold threshold. Short orders execute on

Strategy v5 Mean reversionOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 2xTP, SL to Entry

Greeffer BB Strategy

by SammyEnigma
18 stars

This strategy fades Bollinger Band extremes using the close. It enters short when price crosses above the upper band and the 14-period RSI is above 70, and enters long when price crosses below the lower band and RSI is below 30. It closes half of an open short

Strategy v4 Volatility & bandsOscillators & momentum
Updated 6 years ago · None stated GitHub repository of Greeffer BB Strategy
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
104 stars

This strategy combines Bollinger Bands with a short RSI to fade moves that leave the bands and then return. A long requires the prior bar below the lower band and oversold, then a close back inside the band while RSI is between 30 and 50. Shorts mirror that at

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 years ago · MIT GitHub repository of Bollinger Bands and RSI Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers