// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=6
indicator("XAUUSD-Asia Reversion", shorttitle="XAUUSD-AR", overlay=true, max_boxes_count=500, max_lines_count=500, format=format.price, precision=2)
// ═══════════════════════════════════════════════════════════════════════════════
// RSI INPUTS
// ═══════════════════════════════════════════════════════════════════════════════
rsiLen = input.int(7, "RSI Length", minval=1, tooltip="Set 7 for 1-minute charts", group="RSI")
// ═══════════════════════════════════════════════════════════════════════════════
// FSI — FRACTAL SWEEP INPUTS
// ═══════════════════════════════════════════════════════════════════════════════
leftBars = input.int(2, "Left Bars", minval=1, group="FSI — Fractal Sweep")
rightBars = input.int(2, "Right Bars", minval=1, group="FSI — Fractal Sweep")
lookback = input.int(5, "Fractals to Track", minval=1, tooltip="How many past fractals to check for sweeps", group="FSI — Fractal Sweep")
// ═══════════════════════════════════════════════════════════════════════════════
// FSI — FVG INPUTS
// ═══════════════════════════════════════════════════════════════════════════════
fvgExt = input.int (0, "Extend FVGs", group="FSI — FVG Settings")
upcolor = input.color(color.new(color.teal, 50), "Bullish FVG Color", group="FSI — FVG Style")
downcolor = input.color(color.new(color.red, 50), "Bearish FVG Color", group="FSI — FVG Style")
fvgVolFilt = input.bool (false, "Volume Filter", group="FSI — FVG Filters")
fvgAtrFilt = input.bool (false, "ATR Filter", group="FSI — FVG Filters")
fvgTrndFilt = input.bool (false, "Trend Filter", group="FSI — FVG Filters")
// ═══════════════════════════════════════════════════════════════════════════════
// SHARED TIME HELPERS (PHT = Asia/Manila, UTC+8, no DST)
// ═══════════════════════════════════════════════════════════════════════════════
h = hour(time, "Asia/Manila")
m = minute(time, "Asia/Manila")
inTradingWindow = (h == 7 and m >= 30) or h == 8 or h == 9 or (h == 10 and m < 30)
// ═══════════════════════════════════════════════════════════════════════════════
// RSI LOGIC
// ═══════════════════════════════════════════════════════════════════════════════
rsi = ta.rsi(close, rsiLen)
// ═══════════════════════════════════════════════════════════════════════════════
// ANCHORED VWAP LOGIC (anchor 6:05 AM PHT, plots to 9:30 AM)
// ═══════════════════════════════════════════════════════════════════════════════
inVwapWindow = (h == 6 and m >= 5) or h == 7 or h == 8 or h == 9 or (h == 10 and m < 30)
isVwapAnchor = h == 6 and m >= 5 and (h[1] < 6 or (h[1] == 6 and m[1] < 5))
var float vwap_pv = 0.0
var float vwap_pv2 = 0.0
var float vwap_v = 0.0
if isVwapAnchor
vwap_pv := hlc3 * volume
vwap_pv2 := hlc3 * hlc3 * volume
vwap_v := volume
else if inVwapWindow
vwap_pv += hlc3 * volume
vwap_pv2 += hlc3 * hlc3 * volume
vwap_v += volume
avwap = inVwapWindow and vwap_v > 0 ? vwap_pv / vwap_v : na
avwapStd = inVwapWindow and vwap_v > 0 ? math.sqrt(math.max(vwap_pv2 / vwap_v - avwap * avwap, 0)) : na
// ═══════════════════════════════════════════════════════════════════════════════
// FSI — FRACTAL SWEEP LOGIC
// ═══════════════════════════════════════════════════════════════════════════════
fractHigh = ta.pivothigh(high, leftBars, rightBars)
fractLow = ta.pivotlow(low, leftBars, rightBars)
var highsArr = array.new_float()
var highsIdx = array.new_int()
var highsSwept = array.new_bool()
var lowsArr = array.new_float()
var lowsIdx = array.new_int()
var lowsSwept = array.new_bool()
if not na(fractHigh)
array.unshift(highsArr, fractHigh)
array.unshift(highsIdx, bar_index - rightBars)
array.unshift(highsSwept, false)
if array.size(highsArr) > lookback
array.pop(highsArr)
array.pop(highsIdx)
array.pop(highsSwept)
if not na(fractLow)
array.unshift(lowsArr, fractLow)
array.unshift(lowsIdx, bar_index - rightBars)
array.unshift(lowsSwept, false)
if array.size(lowsArr) > lookback
array.pop(lowsArr)
array.pop(lowsIdx)
array.pop(lowsSwept)
if array.size(highsArr) > 0
for i = 0 to array.size(highsArr) - 1
val = array.get(highsArr, i)
idx = array.get(highsIdx, i)
swept = array.get(highsSwept, i)
if not swept and high > val
line.new(x1=idx, y1=val, x2=bar_index, y2=val, color=color.rgb(0, 0, 0), style=line.style_dotted, width=1, extend=extend.none)
alert("Sweep Detected", alert.freq_once_per_bar_close)
array.set(highsSwept, i, true)
if array.size(lowsArr) > 0
for i = 0 to array.size(lowsArr) - 1
val = array.get(lowsArr, i)
idx = array.get(lowsIdx, i)
swept = array.get(lowsSwept, i)
if not swept and low < val
line.new(x1=idx, y1=val, x2=bar_index, y2=val, color=color.rgb(0, 0, 0), style=line.style_dotted, width=1, extend=extend.none)
alert("Sweep Detected", alert.freq_once_per_bar_close)
array.set(lowsSwept, i, true)
// ═══════════════════════════════════════════════════════════════════════════════
// FSI — FVG LOGIC
// ═══════════════════════════════════════════════════════════════════════════════
var float recentBullFVG_Low = na
var float recentBearFVG_High = na
var int bullFVG_start = na
var int bearFVG_start = na
var bool bullUsed = false
var bool bearUsed = false
f_fvg() =>
volfilt = fvgVolFilt ? volume[1] > ta.sma(volume, 9) * 1.5 : true
fvg_atr = ta.atr(20) / 1.5
atrfilt = fvgAtrFilt ? ((low - high[2] > fvg_atr) or (low[2] - high > fvg_atr)) : true
loc = ta.sma(close, 54)
loc2 = loc > loc[1]
locfiltb = fvgTrndFilt ? loc2 : true
locfilts = fvgTrndFilt ? not loc2 : true
bfvg = low > high[2] and volfilt and atrfilt and locfiltb
sfvg = high < low[2] and volfilt and atrfilt and locfilts
[bfvg, sfvg]
f_fvgcontrol(_tf) => request.security(syminfo.tickerid, _tf, f_fvg())
[bfvg1m, sfvg1m] = f_fvgcontrol("1")
if barstate.isconfirmed and bfvg1m
recentBullFVG_Low := high[2]
bullFVG_start := bar_index
box.new(left=bar_index-2, top=low, right=bar_index+fvgExt, bottom=high[2], border_color=color.new(color.gray, 100), bgcolor=color.new(upcolor, 90))
bullUsed := false
if barstate.isconfirmed and sfvg1m
recentBearFVG_High := low[2]
bearFVG_start := bar_index
box.new(left=bar_index-2, top=high, right=bar_index+fvgExt, bottom=low[2], border_color=color.new(color.gray, 100), bgcolor=color.new(downcolor, 90))
bearUsed := false
// Only FSI signals reverting toward AVWAP: red (sell) when price above AVWAP, green (buy) when price below
candleUnderBullFVG = barstate.isconfirmed and inTradingWindow and not na(recentBullFVG_Low) and close < recentBullFVG_Low and not bullUsed and not na(avwap) and close > avwap
candleOverBearFVG = barstate.isconfirmed and inTradingWindow and not na(recentBearFVG_High) and close > recentBearFVG_High and not bearUsed and not na(avwap) and close < avwap
if candleUnderBullFVG
bullUsed := true
alert("Sell Signal", alert.freq_once_per_bar_close)
line.new(x1=bullFVG_start, y1=recentBullFVG_Low, x2=bar_index, y2=recentBullFVG_Low, extend=extend.none, color=color.red, style=line.style_solid, width=1)
if candleOverBearFVG
bearUsed := true
alert("Buy Signal", alert.freq_once_per_bar_close)
line.new(x1=bearFVG_start, y1=recentBearFVG_High, x2=bar_index, y2=recentBearFVG_High, extend=extend.none, color=color.orange, style=line.style_solid, width=1)
// ═══════════════════════════════════════════════════════════════════════════════
// RSI OVEREXTENSION CANDLE COLORING (orange → red as RSI stretches from 50)
// ═══════════════════════════════════════════════════════════════════════════════
rsi_dist = math.abs(rsi - 50)
rsi_color = rsi_dist < 25 ? na : color.from_gradient(rsi_dist, 25, 50, color.orange, color.red)
oeActive = inTradingWindow and not na(rsi_color)
barcolor(oeActive ? rsi_color : na, title="RSI Overextension")
plotcandle(oeActive ? open : na, oeActive ? high : na, oeActive ? low : na, oeActive ? close : na, title="RSI OE Candles", color=rsi_color, wickcolor=rsi_color, bordercolor=rsi_color)
// ═══════════════════════════════════════════════════════════════════════════════
// ANCHORED VWAP PLOTS
// ═══════════════════════════════════════════════════════════════════════════════
borderHalf = ta.atr(14) * 1 / 2
avwap2u = na(avwapStd) ? na : avwap + avwapStd * 2
avwap2l = na(avwapStd) ? na : avwap - avwapStd * 2
avwap3u = na(avwapStd) ? na : avwap + avwapStd * 3
avwap3l = na(avwapStd) ? na : avwap - avwapStd * 3
pAvwap = plot(avwap, title="AVWAP (6:05AM)", color=color.new(color.white, 50), linewidth=1, style=plot.style_linebr)
p2u = plot(avwap2u, title="AVWAP +2σ", color=color.new(color.orange, 50), linewidth=1, style=plot.style_linebr)
p2l = plot(avwap2l, title="AVWAP -2σ", color=color.new(color.orange, 50), linewidth=1, style=plot.style_linebr)
p3u = plot(avwap3u, title="AVWAP +3σ", color=color.new(color.red, 50), linewidth=1, style=plot.style_linebr)
p3l = plot(avwap3l, title="AVWAP -3σ", color=color.new(color.red, 50), linewidth=1, style=plot.style_linebr)
// Transparent border (thickness = 1.5×ATR) around each line via offset edge plots + fill
pAvwapU = plot(avwap + borderHalf, title="AVWAP border+", color=na, display=display.none)
pAvwapD = plot(avwap - borderHalf, title="AVWAP border-", color=na, display=display.none)
p2uU = plot(avwap2u + borderHalf, title="+2σ border+", color=na, display=display.none)
p2uD = plot(avwap2u - borderHalf, title="+2σ border-", color=na, display=display.none)
p2lU = plot(avwap2l + borderHalf, title="-2σ border+", color=na, display=display.none)
p2lD = plot(avwap2l - borderHalf, title="-2σ border-", color=na, display=display.none)
p3uU = plot(avwap3u + borderHalf, title="+3σ border+", color=na, display=display.none)
p3uD = plot(avwap3u - borderHalf, title="+3σ border-", color=na, display=display.none)
p3lU = plot(avwap3l + borderHalf, title="-3σ border+", color=na, display=display.none)
p3lD = plot(avwap3l - borderHalf, title="-3σ border-", color=na, display=display.none)
fill(pAvwapU, pAvwapD, color=color.new(color.white, 90), title="AVWAP border")
fill(p2uU, p2uD, color=color.new(color.orange, 90), title="+2σ border")
fill(p2lU, p2lD, color=color.new(color.orange, 90), title="-2σ border")
fill(p3uU, p3uD, color=color.new(color.red, 90), title="+3σ border")
fill(p3lU, p3lD, color=color.new(color.red, 90), title="-3σ border")
Overview
XAUUSD-Asia Reversion combines a short-period RSI with fractal sweep detection, where price takes out recent fractal highs or lows, and fair value gap boxes with optional volume, ATR and trend filters. Settings cover RSI length, fractal bar counts, how many fractals to track, gap extension and gap colours. Fractals confirm only after their right-side bars. The input is thin on exact signal rules, so it is best read as a context overlay.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
RSI Length
int
7
rsiLen
Left Bars
int
2
leftBars
Right Bars
int
2
rightBars
Fractals to Track
int
5
lookback
Extend FVGs
int
0
fvgExt
Bullish FVG Color
color
color.new(color.teal, 50)
upcolor
Bearish FVG Color
color
color.new(color.red, 50)
downcolor
Volume Filter
bool
false
fvgVolFilt
ATR Filter
bool
false
fvgAtrFilt
Trend Filter
bool
false
fvgTrndFilt
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 indicator plots a session VWAP that resets daily plus pivot-anchored VWAP highs and lows. It marks price crosses of those VWAPs, crosses between session and anchored VWAPs, and clusters where several VWAP lines sit close together. Display mode, cl
A price-chart indicator that looks for fade setups after price raids the edge of a completed session or prior-day range and closes back inside. It requires the Gann half-range level to sit at least a set number of R away, sizes the stop beyond the raid using A
This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds
The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh
Indicatorv6SMC / ICT / price actionSessions & time
This indicator overlays options gamma-exposure levels, session VWAP bands, and intraday market structure tools directly on the price chart. It provides three modular components: strike walls with standard deviation bands and opening ranges, a gamma regime engi
This indicator draws ICT killzone boxes on the price chart for Asia, London, New York AM, New York lunch, and New York PM sessions. Each session can be toggled, renamed, and recolored, with optional labels and adjustable box transparency. A session drawing lim
Indicatorv5SMC / ICT / price actionSessions & time