1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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
66 lines of Pine Script v5 from pine/WKL_v2_fixed.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
WKL_v2_fixed.pine
//@version=5
strategy("WKL v2 — Prior Week Low Retest (Fixed)", 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,
process_orders_on_close=false)
// ═══════════════════════════════════════════════════════════════════
// WKL v2 FIXED — SL/TP anchored to actual fill price
// ═══════════════════════════════════════════════════════════════════
tolerance = input.float(5.0, "Tolerance (USD pts)")
stopPts = input.float(20.0, "Stop Loss (USD pts)")
targetR = input.float(2.25, "Target R-multiple")
killHour = input.int(20, "Kill Hour (UTC)", minval=16, maxval=23)
sessStart = input.int(7, "Session Start (UTC)", minval=0, maxval=12)
sessCutoff = input.int(15, "Entry Cutoff (UTC)", minval=12, maxval=20)
// ── PRIOR WEEK LOW ───────────────────────────────────────────────
pwLow = request.security(syminfo.tickerid, "W", low[1], lookahead=barmerge.lookahead_on)
// ── TIME FILTERS ─────────────────────────────────────────────────
utcHour = hour(time, "UTC")
utcDay = dayofweek(time, "UTC")
inSession = utcHour >= sessStart and utcHour < sessCutoff
isMonday = utcDay == dayofweek.monday
isFridayLate = utcDay == dayofweek.friday and utcHour >= 21
// ── ENTRY TRIGGER ────────────────────────────────────────────────
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
// ── ENTRY ────────────────────────────────────────────────────────
if longCondition
strategy.entry("WKL", strategy.long)
// ── EXIT: Anchored to ACTUAL fill price ──────────────────────────
// This runs every bar. When we have a position, set SL/TP from
// the real average entry price, not from where the signal fired.
if strategy.position_size > 0
avgPrice = strategy.position_avg_price
sl = avgPrice - stopPts
tp = avgPrice + (stopPts * targetR)
strategy.exit("WKL_TP_SL", "WKL", stop=sl, limit=tp)
// ── TIME EXIT ────────────────────────────────────────────────────
if strategy.position_size > 0 and utcHour >= killHour
strategy.close("WKL", comment="Kill")
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)
plotshape(longCondition, "Entry Signal", shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)
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")
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)")
Overview
Entries are restricted to configurable UTC trading hours, excluding Mondays and late Friday sessions. Stop loss and take profit targets are calculated using fixed point distances and an R-multiple ratio anchored to the average fill price. Positions are automatically closed at a daily kill hour or prior to the weekend. The prior week's low level is plotted directly on the main price chart.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Tolerance (USD pts)
float
5.0
tolerance
Stop Loss (USD pts)
float
20.0
stopPts
Target R-multiple
float
2.25
targetR
Kill Hour (UTC)
int
20
killHour
Session Start (UTC)
int
7
sessStart
Entry Cutoff (UTC)
int
15
sessCutoff
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.
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
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
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
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
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
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