Strategy · Pine Script v5 · On the chart

Williams Strategy - Alert

by dearvn· code credited to binancash

Williams Strategy - Alert is a Pine Script v5 strategy that plots three-bar simple moving averages of high and low prices directly on the price chart.

View on GitHub

GitHub stars257on the repository
Pine versionv5runs as is
Lines of code94
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update6 weeks ago11 Sep 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

94 lines of Pine Script v5 from nqu2023-1m.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

nqu2023-1m.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © binancash

//@version=5
strategy("Williams Strategy - Alert", overlay=true, pyramiding=1, default_qty_type = strategy.fixed, default_qty_value = 1 )


stopPerCall = input(0.05, title='Stop Loss Call %') / 100 
takePerCall = input(0.03, title='Take Profit Call %') / 100

stopPerPut = input(0.05, title='Stop Loss Put %') / 100 
takePerPut = input(0.03, title='Take Profit Put %') / 100

longStop = strategy.position_avg_price * (1 - stopPerCall)
shortStop = strategy.position_avg_price * (1 + stopPerPut)
shortTake = strategy.position_avg_price * (1 - takePerPut)
longTake = strategy.position_avg_price * (1 + takePerCall)


//Inputs
ma_length = input(3)

//Three Bar High/Low Moving Average
ma_high = ta.sma(high, ma_length)
ma_low = ta.sma(low, ma_length)
plot(ma_high, linewidth = 1)
plot(ma_low, linewidth = 1)

//Trend Reversal - Up
trend_reversal_up = low[2] > low[1] and low[1] < low and high > high[1]
plotshape(trend_reversal_up ? 1: na, color = color.orange, location = location.belowbar, style = shape.arrowup, text = 'U')

//Trend Reversal - Down
trend_reversal_down = high[2] < high[1] and high[1] > high and low < low[1]
plotshape(trend_reversal_down ? -1: na, color = color.navy, location = location.abovebar, style = shape.arrowdown, text = 'D')

//Short Term Low
short_term_low = low[2] > low[1] and low[1] < low and high[1] < high[2] and high > high[1]
plotshape(short_term_low ? 1: na, color = #00EEEE, location = location.belowbar, style = shape.arrowup)

//Short Term High
short_term_high = high[2] < high[1] and high[1] > high and low[1] > low[2] and low < low[1]
plotshape(short_term_high ? -1: na, color = #00EEEE, location = location.abovebar, style = shape.arrowdown)

//Trend Change Point - Up
float trend_change_up = na
trend_change_up := high > high[1] ? 1 : na
line1 = short_term_low and trend_change_up
color_up = #FFEB3B
color up = na
up := trend_change_up ? color_up : na
//plot(line1 ? high[1] : na, color = up, linewidth = 2)

//plotshape(line1 ? low : na, title="Buy", text="Buy", style=shape.triangleup, location=location.belowbar, color=color.white, size=size.normal)


//Trend Change Point - Down
float trend_change_down = na
trend_change_down := low < low[1] ? 1 : na
line2 = short_term_high and trend_change_down
color_down = #E040FB
color down = na
down := trend_change_down ? color_down : na
//plot(line2 ? low[1] : na, color=down, linewidth = 2)

//plotshape(line2 ? high : na, title="Sell", text="Sell", style=shape.triangledown, location=location.abovebar, color=color.blue, size=size.normal)


//Bar Color Trend Change
coloryellow = #FFEB3B
colorfuchsia = #E040FB
barcolor(line1 ? coloryellow : line2 ? colorfuchsia : na)


if trend_reversal_up and time>timestamp(2023, 08, 01, 09, 30)
    strategy.entry("call", strategy.long)

if trend_reversal_down and time>timestamp(2023, 08, 01, 09, 30)
    strategy.entry("put", strategy.short)


if(strategy.position_size > 0 and trend_change_down) and time>timestamp(2023, 08, 01, 09, 30)
    strategy.close(id="call")

if(strategy.position_size < 0 and trend_change_up) and time>timestamp(2023, 08, 01, 09, 30)
    strategy.close(id="put")


if(strategy.position_size > 0) and time>timestamp(2023, 08, 01, 09, 30)
    strategy.exit(id='call', limit=longTake,stop = longStop) 
    //call_price := 0.0

if(strategy.position_size < 0) and time>timestamp(2023, 08, 01, 09, 30)
    strategy.exit(id='put', limit=shortTake,stop = shortStop)

Overview

Williams Strategy - Alert detects upward and downward trend reversals by comparing the current bar's low and high with those from the prior two bars, along with short-term high and low points. The script enters long call positions on upward reversals and short put positions on downward reversals after a specified start time, with exits triggered on opposite reversals or at stop loss and take profit levels set as percentages of the average position price. The primary user setting adjusts the moving average length, defaulting to three bars. Bar color changes to indicate trend shifts.

Details

Published by

dearvn on GitHub

Code credit

binancash, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages

Markets

Indices

Timeframes

M15-H1

Risk Notes

  • The strategy can add several entries in the same direction

Topics

futures-markettradingviewtradovatetrading-futureses1best-indicator-tradingviewnq1trading-futurerus-stock-market

Settings

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

SettingTypeDefaultVariable
Stop Loss Call %float0.05stopPerCall
Take Profit Call %float0.03takePerCall
Stop Loss Put %float0.05stopPerPut
Take Profit Put %float0.03takePerPut
ma_lengthint3ma_length
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

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce

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