Strategy · Pine Script v5 · On the chart

WKL v2 — Prior Week Low Retest (Locked Spec)

by Grahamovernightly

This strategy trades long when an M15 bar's low comes within a tolerance of the prior week's low and the bar closes above that level.

View on GitHub

GitHub stars5on the repository
Pine versionv5runs as is
Lines of code116
Settings6inputs
LicenceMIT
Last update4 months ago1 Jun 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

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

WKL_v2_locked.pine
//@version=5
strategy("WKL v2 — Prior Week Low Retest (Locked Spec)", overlay=true, 
     default_qty_type=strategy.percent_of_equity, default_qty_value=2,
     initial_capital=100000, commission_type=strategy.commission.cash_per_order, commission_value=0.5)

// ═══════════════════════════════════════════════════════════════════
// WKL v2 LOCKED SPEC — All params pinned from Python backtesting
// 114 trades | 87% WR | PF 9.83 | Net 2,057 pts
// With 15:00 cutoff: 88 trades | 92% WR | PF 14.32
// ═══════════════════════════════════════════════════════════════════

// ── PARAMETERS (all validated, do not tune without Python) ───────
tolerance   = input.float(5.0,  "Tolerance (USD pts)", tooltip="M15 bar low must be within this distance of PW low")
stopPts     = input.float(20.0, "Stop Loss (USD pts)", tooltip="Fixed 20 pts below entry. ~3.3x ATR14. Tested 15-25, 20 is PF peak.")
targetR     = input.float(2.25, "Target R-multiple", tooltip="TP = 45 pts (20 x 2.25). R=2.25 is PF peak. R=2.5 drops to 9.62.")
killHour    = input.int(20,     "Kill Hour (UTC)", minval=16, maxval=23, tooltip="Close open trades at this hour. 20:00 UTC = PF 9.83.")
sessStart   = input.int(7,      "Session Start (UTC)", minval=0, maxval=12, tooltip="Earliest entry hour. 07:00 = London open.")
sessCutoff  = input.int(15,     "Entry Cutoff (UTC)", minval=12, maxval=20, tooltip="No entries after this hour. 15:00 = PF 14.32. 17:00 = more trades but lower PF.")

// ── PRIOR WEEK LOW ───────────────────────────────────────────────
// [1] = completed prior week (not current). lookahead_on is correct 
// for historical reference data on higher timeframe.
pwLow = request.security(syminfo.tickerid, "W", low[1], lookahead=barmerge.lookahead_on)

// ── TIME FILTERS ─────────────────────────────────────────────────
utcHour   = hour(time, "UTC")
utcDay    = dayofweek(time, "UTC")

// Entry window: sessStart to sessCutoff, UTC
inSession = utcHour >= sessStart and utcHour < sessCutoff

// Monday filter: No entries on Monday (weekday=2 in Pine, Monday)
// Pine: dayofweek.monday = 2
isMonday = utcDay == dayofweek.monday

// Friday late: close positions, no new entries after kill hour
isFridayLate = utcDay == dayofweek.friday and utcHour >= 21

// ── ENTRY TRIGGER ────────────────────────────────────────────────
// Signal: M15 bar where LOW comes within tolerance of prior week low
// AND bar CLOSES ABOVE the prior week low.
//
// What this IS:
//   - Price retests prior week's support level
//   - Bar low touches/nears PW low (within 5 pts)
//   - Bar closes above (confirmation of hold)
//   - Long only (gold secular bull bias)
//
// What this is NOT:
//   - NOT requiring a bullish candle (close > open) — tested, marginal
//   - NOT requiring wick-through — tested, wick-throughs are WORSE (65% vs 91% WR)
//   - NOT requiring RSI/MA confluence for entry — confluence is for SIZING, not filtering
//
// Data: 100% of backtested entries naturally close above PW low.
// Wick-throughs (low pierces below, close above) = 15% of entries, worse performance.

nearPWLow   = (low <= pwLow + tolerance) and (low >= pwLow - tolerance)
closesAbove = close > pwLow

longCondition = nearPWLow and closesAbove and inSession and not isMonday and not isFridayLate and strategy.position_size == 0

// ── EXECUTE ──────────────────────────────────────────────────────
if longCondition
    ep = close
    sl = ep - stopPts
    tp = ep + (stopPts * targetR)
    
    strategy.entry("WKL", strategy.long)
    strategy.exit("WKL_TP_SL", "WKL", stop=sl, limit=tp)

// ── TIME EXIT ────────────────────────────────────────────────────
// If neither SL nor TP hit by kill hour, close at market.
// Kill 20:00 UTC = PF 9.83. Earlier kills (18-19) cut winners.
if strategy.position_size > 0 and utcHour >= killHour
    strategy.close("WKL", comment="Kill")

// Friday end-of-week: force close by 21:00 UTC
if strategy.position_size > 0 and utcDay == dayofweek.friday and utcHour >= 21
    strategy.close("WKL", comment="FriClose")

// ── VISUALS ──────────────────────────────────────────────────────
plot(pwLow, "Prior Week Low", color=color.new(color.blue, 20), linewidth=2, style=plot.style_stepline)

// Entry markers
plotshape(longCondition, "Entry Signal", shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)

// Tolerance zone (light blue band around PW low)
pwUpper = pwLow + tolerance
pwLower = pwLow - tolerance
p1 = plot(pwUpper, "Tol Upper", color=color.new(color.blue, 90))
p2 = plot(pwLower, "Tol Lower", color=color.new(color.blue, 90))
fill(p1, p2, color=color.new(color.blue, 92), title="Tolerance Zone")

// Session background
bgcolor(inSession and not isMonday ? color.new(color.green, 96) : na, title="Active Session")
bgcolor(isMonday ? color.new(color.red, 96) : na, title="Monday (No Trade)")

// ═══════════════════════════════════════════════════════════════════
// SPEC REFERENCE (for future MQL5 port)
// ═══════════════════════════════════════════════════════════════════
// Level:         Prior completed week low
// Tolerance:     5 USD points
// Direction:     Long only
// Entry:         M15 close within tolerance above PW low
// Stop:          Fixed 20 USD pts below entry price
// Target:        Fixed 45 USD pts above entry (2.25R)
// Time exit:     20:00 UTC (close at market)
// Entry window:  07:00-15:00 UTC
// Day filter:    No Monday entries
// Trend filter:  None (long-only = embedded bull bias)
// Partial TP:    None in v1 (tested: half@1R works, save for v2)
//
// Confluence (for SIZING in v2, not entry filtering):
//   Size up when: RSI 60-70, Wednesday, low volume, huge Asian range
//   Size down when: RSI <30, 4+ consecutive down bars, after 15:00 UTC
// ═══════════════════════════════════════════════════════════════════

Overview

WKL v2 — Prior Week Low Retest (Locked Spec) places a fixed point stop below entry and a take-profit at a chosen R-multiple of that stop. Entries are limited to a UTC session window and blocked on Mondays; open trades are closed at a kill hour and late on Friday. Tolerance, stop distance, target multiple, and session hours are user inputs. It draws on the price chart and sizes positions as a percentage of equity.

Details

Published by

Grahamovernightly on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Sessions & time

Markets

Gold

Timeframes

M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingforexpythonquant-tradingtrading-strategies

Settings

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

SettingTypeDefaultVariable
Tolerance (USD pts)float5.0tolerance
Stop Loss (USD pts)float20.0stopPts
Target R-multiplefloat2.25targetR
Kill Hour (UTC)int20killHour
Session Start (UTC)int7sessStart
Entry Cutoff (UTC)int15sessCutoff
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

Daily Bias + FVG Strategy

by TradersPost
218 stars

This overlay strategy plots previous-day high and low, the daily open, and fair value gap zones on the price chart. It takes entries on a selectable timeframe when the FVG requirement and an optional session window allow them, then uses an ATR or fixed pip sto

Strategy v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Daily Bias + FVG Strategy
106 stars

This script monitors opening gap conditions and breakout behavior relative to the first candle's range across up to twenty configurable stock tickers. It detects whether following bars remain inside the opening range before breaking out, displaying the status

Strategy v4 Screeners & dashboardsBreakout Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 1St Bar GAP+BkOut Screener v2 by RM

ATOM 1m scalp HK

by dearvn
43 stars

This overlay strategy targets one-minute ATOM scalps. It tracks pivot highs and lows as resistance and support, compares a three-period EMA with a multi-stage smoothed close, and flags long or short when price crosses that curve in the matching direction. Dail

Strategy v5 ScalpingSupport & resistance Repaints
Updated 2 years ago · None stated GitHub repository of ATOM 1m scalp HK

P404 Smoke

by Musyimi97
16 stars

P404 Smoke is a price-chart strategy that sequences an optional higher-timeframe EMA bias, a liquidity range from recent pivots, a sweep of buy-side or sell-side liquidity, and a market structure shift within a set bar window. Comments state it then looks for

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 6 months ago · MIT GitHub repository of P404 Smoke

Fibonacci strategy

by JoelPasapera
11 stars

This strategy plots a Fibonacci retracement of the previous day's high-low range on the price chart. It places a single long limit order at that level when the bar hour matches the chosen entry hour and the close is below the level. Position size follows the l

Strategy v6 Support & resistanceSessions & time
Updated 5 months ago · Apache-2.0 GitHub repository of Fibonacci strategy

1-Min Gold Taylor Technique

by eddiebelaval
7 stars

This intraday strategy implements session-based trading rules tailored for gold on short timeframes. It tracks the Asian session price range, VWAP, 20-period EMA, and previous day high and low levels to identify liquidity sweeps during London and New York trad

Strategy v6 Sessions & timeSupport & resistance
Updated 3 months ago · None stated GitHub repository of 1-Min Gold Taylor Technique

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