OPEN-SOURCE SCRIPT
AMD FVG Trade

//version=6
// ============================================================================
// AMD FVG Trade — Accumulation → Manipulation → Distribution + FVG
// Settings mirror the reference indicator: AMD Logic, Trade Settings (ATR SL
// + Reward:Risk), EST session filter, and configurable colors.
// • Accumulation = tight consolidation base (gray)
// • Manipulation = false-breakout sweep of the base (red bear / green bull)
// • Distribution = reversal FVG in the opposite direction + "AMD" label
// • Trade levels = Entry / Stop (ATR × mult) / Target (R:R) zones
// ============================================================================
indicator("AMD FVG Trade", overlay = true, max_boxes_count = 500, max_labels_count = 200, max_lines_count = 500)
// ══════════════════════════════ AMD LOGIC ════════════════════════════════
gL = "AMD Logic"
accLength = input.int (30, "Accumulation Length", minval = 3, group = gL, tooltip = "Bars used to measure the consolidation (accumulation) range.")
accRangeMax = input.float(0.2, "Accumulation Range Max %", minval = 0.01, step = 0.05, group = gL, tooltip = "Max size of the accumulation range as a % of price. Smaller = a tighter base is required.")
maxSearch = input.int (10, "Max Search Window", minval = 1, group = gL, tooltip = "Bars allowed to find the manipulation sweep, then the distribution FVG, after accumulation.")
minFvgGap = input.float(0.1, "Min FVG Gap (ATR Multiplier)", minval = 0.0, step = 0.05, group = gL, tooltip = "Minimum size of the distribution FVG, measured in ATR multiples.")
// ═══════════════════════════════ TRADE SETTINGS ══════════════════════════
gT = "Trade Settings"
atrLength = input.int (14, "ATR Length", minval = 1, group = gT)
atrSLMult = input.float(2.0, "ATR SL Multiplier", minval = 0.1, step = 0.1, group = gT, tooltip = "Stop-loss distance = ATR × this multiplier.")
rrRatio = input.float(2.0, "Reward-to-Risk Ratio", minval = 0.1, step = 0.1, group = gT, tooltip = "Target distance = stop distance × this ratio.")
showTrade = input.bool (true, "Show trade levels (Entry / SL / TP)", group = gT)
// ═══════════════════════════ SESSIONS (EST · America/New_York) ═══════════
gS = "Sessions"
useSydney = input.bool(false, "Sydney Session (17:00-02:00 EST)", group = gS)
useTokyo = input.bool(false, "Tokyo Session (19:00-04:00 EST)", group = gS)
useLondon = input.bool(false, "London Session (03:00-12:00 EST)", group = gS)
useNY = input.bool(true, "New York Session (08:00-17:00 EST)", group = gS)
hiliteSess = input.bool(true, "Highlight Active Session Time", group = gS)
// ══════════════════════════════════ COLORS ══════════════════════════════
gC = "Colors"
colAcc = input.color(color.new(color.gray, 70), "Accumulation", group = gC)
colManBear = input.color(color.new(color.red, 65), "Manipulation (Bear)", group = gC)
colManBull = input.color(color.new(color.green, 65), "Manipulation (Bull)", group = gC)
colDisBear = input.color(color.new(color.red, 55), "Distribution (Bear)", group = gC)
colDisBull = input.color(color.new(color.green, 55), "Distribution (Bull)", group = gC)
// ───────────────────────────── SESSION FILTER ────────────────────────────
tz = "America/New_York"
inSyd = useSydney and not na(time(timeframe.period, "1700-0200", tz))
inTok = useTokyo and not na(time(timeframe.period, "1900-0400", tz))
inLon = useLondon and not na(time(timeframe.period, "0300-1200", tz))
inNY = useNY and not na(time(timeframe.period, "0800-1700", tz))
activeSession = inSyd or inTok or inLon or inNY
anySessOn = useSydney or useTokyo or useLondon or useNY
sessOK = anySessOn ? activeSession : true
bgcolor(hiliteSess and anySessOn and activeSession ? color.new(color.blue, 92) : na, title = "Active Session")
atr = ta.atr(atrLength)
// ───────────────────────────── FVG (3-candle) ────────────────────────────
bullFVG = low > high[2] and (low - high[2]) >= minFvgGap * atr
bearFVG = high < low[2] and (low[2] - high) >= minFvgGap * atr
// ───────────────────────────── AMD STATE MACHINE ─────────────────────────
// 0 = find accumulation base | 1 = wait manipulation breakout | 2 = wait distribution FVG
accHi = ta.highest(high, accLength)
accLo = ta.lowest(low, accLength)
rangePct = (accHi - accLo) / close * 100.0
isBase = rangePct <= accRangeMax
var int state = 0
var float lockHi = na
var float lockLo = na
var box accBox = na
var box manBox = na
var int dir = 0
var float manExt = na
var int t0 = na
// STATE 0 — lock a tight base during an active session
if state == 0 and isBase and sessOK
lockHi := accHi
lockLo := accLo
accBox := box.new(bar_index - accLength + 1, lockHi, bar_index, lockLo, border_color = color.new(color.gray, 30), bgcolor = colAcc, border_width = 1)
t0 := bar_index
state := 1
// STATE 1 — extend base, wait for the manipulation breakout
if state == 1
if not na(accBox)
box.set_right(accBox, bar_index)
if close > lockHi
dir := -1
manBox := box.new(bar_index, high, bar_index, lockHi, border_color = color.new(color.red, 30), bgcolor = colManBear, border_width = 1)
manExt := high
t0 := bar_index
state := 2
else if close < lockLo
dir := 1
manBox := box.new(bar_index, lockLo, bar_index, low, border_color = color.new(color.green, 30), bgcolor = colManBull, border_width = 1)
manExt := low
t0 := bar_index
state := 2
else if bar_index - t0 > maxSearch
state := 0
accBox := na
// STATE 2 — manipulation runs, wait for the reversal (distribution) FVG
if state == 2
if not na(manBox)
box.set_right(manBox, bar_index)
if dir == -1
manExt := math.max(manExt, high)
if not na(manBox)
box.set_top(manBox, manExt)
if bearFVG
box.new(bar_index - 2, low[2], bar_index + maxSearch, high, border_color = color.new(color.red, 0), bgcolor = colDisBear, border_width = 2)
label.new(bar_index, manExt, "AMD Bearish", style = label.style_label_down, color = color.new(color.red, 10), textcolor = color.white, size = size.normal)
if showTrade
entry = low[2]
sl = entry + atr * atrSLMult
tp = entry - atr * atrSLMult * rrRatio
rgt = bar_index + maxSearch
box.new(bar_index, sl, rgt, entry, border_color = color.new(color.red, 100), bgcolor = color.new(color.red, 82), border_width = 0)
box.new(bar_index, entry, rgt, tp, border_color = color.new(color.green, 100), bgcolor = color.new(color.green, 82), border_width = 0)
line.new(bar_index, entry, rgt, entry, color = color.white, style = line.style_dashed, width = 1)
state := 0
accBox := na
else if bar_index - t0 > maxSearch
state := 0
accBox := na
else if dir == 1
manExt := math.min(manExt, low)
if not na(manBox)
box.set_bottom(manBox, manExt)
if bullFVG
box.new(bar_index - 2, low, bar_index + maxSearch, high[2], border_color = color.new(color.green, 0), bgcolor = colDisBull, border_width = 2)
label.new(bar_index, manExt, "AMD Bullish", style = label.style_label_up, color = color.new(color.green, 10), textcolor = color.white, size = size.normal)
if showTrade
entry = high[2]
sl = entry - atr * atrSLMult
tp = entry + atr * atrSLMult * rrRatio
rgt = bar_index + maxSearch
box.new(bar_index, entry, rgt, sl, border_color = color.new(color.red, 100), bgcolor = color.new(color.red, 82), border_width = 0)
box.new(bar_index, tp, rgt, entry, border_color = color.new(color.green, 100), bgcolor = color.new(color.green, 82), border_width = 0)
line.new(bar_index, entry, rgt, entry, color = color.white, style = line.style_dashed, width = 1)
state := 0
accBox := na
else if bar_index - t0 > maxSearch
state := 0
accBox := na
// ───────────────────────────── ALERTS ─────────────────────────────────────
alertcondition(bullFVG, "Bullish FVG", "Bullish FVG")
alertcondition(bearFVG, "Bearish FVG", "Bearish FVG")
// ============================================================================
// AMD FVG Trade — Accumulation → Manipulation → Distribution + FVG
// Settings mirror the reference indicator: AMD Logic, Trade Settings (ATR SL
// + Reward:Risk), EST session filter, and configurable colors.
// • Accumulation = tight consolidation base (gray)
// • Manipulation = false-breakout sweep of the base (red bear / green bull)
// • Distribution = reversal FVG in the opposite direction + "AMD" label
// • Trade levels = Entry / Stop (ATR × mult) / Target (R:R) zones
// ============================================================================
indicator("AMD FVG Trade", overlay = true, max_boxes_count = 500, max_labels_count = 200, max_lines_count = 500)
// ══════════════════════════════ AMD LOGIC ════════════════════════════════
gL = "AMD Logic"
accLength = input.int (30, "Accumulation Length", minval = 3, group = gL, tooltip = "Bars used to measure the consolidation (accumulation) range.")
accRangeMax = input.float(0.2, "Accumulation Range Max %", minval = 0.01, step = 0.05, group = gL, tooltip = "Max size of the accumulation range as a % of price. Smaller = a tighter base is required.")
maxSearch = input.int (10, "Max Search Window", minval = 1, group = gL, tooltip = "Bars allowed to find the manipulation sweep, then the distribution FVG, after accumulation.")
minFvgGap = input.float(0.1, "Min FVG Gap (ATR Multiplier)", minval = 0.0, step = 0.05, group = gL, tooltip = "Minimum size of the distribution FVG, measured in ATR multiples.")
// ═══════════════════════════════ TRADE SETTINGS ══════════════════════════
gT = "Trade Settings"
atrLength = input.int (14, "ATR Length", minval = 1, group = gT)
atrSLMult = input.float(2.0, "ATR SL Multiplier", minval = 0.1, step = 0.1, group = gT, tooltip = "Stop-loss distance = ATR × this multiplier.")
rrRatio = input.float(2.0, "Reward-to-Risk Ratio", minval = 0.1, step = 0.1, group = gT, tooltip = "Target distance = stop distance × this ratio.")
showTrade = input.bool (true, "Show trade levels (Entry / SL / TP)", group = gT)
// ═══════════════════════════ SESSIONS (EST · America/New_York) ═══════════
gS = "Sessions"
useSydney = input.bool(false, "Sydney Session (17:00-02:00 EST)", group = gS)
useTokyo = input.bool(false, "Tokyo Session (19:00-04:00 EST)", group = gS)
useLondon = input.bool(false, "London Session (03:00-12:00 EST)", group = gS)
useNY = input.bool(true, "New York Session (08:00-17:00 EST)", group = gS)
hiliteSess = input.bool(true, "Highlight Active Session Time", group = gS)
// ══════════════════════════════════ COLORS ══════════════════════════════
gC = "Colors"
colAcc = input.color(color.new(color.gray, 70), "Accumulation", group = gC)
colManBear = input.color(color.new(color.red, 65), "Manipulation (Bear)", group = gC)
colManBull = input.color(color.new(color.green, 65), "Manipulation (Bull)", group = gC)
colDisBear = input.color(color.new(color.red, 55), "Distribution (Bear)", group = gC)
colDisBull = input.color(color.new(color.green, 55), "Distribution (Bull)", group = gC)
// ───────────────────────────── SESSION FILTER ────────────────────────────
tz = "America/New_York"
inSyd = useSydney and not na(time(timeframe.period, "1700-0200", tz))
inTok = useTokyo and not na(time(timeframe.period, "1900-0400", tz))
inLon = useLondon and not na(time(timeframe.period, "0300-1200", tz))
inNY = useNY and not na(time(timeframe.period, "0800-1700", tz))
activeSession = inSyd or inTok or inLon or inNY
anySessOn = useSydney or useTokyo or useLondon or useNY
sessOK = anySessOn ? activeSession : true
bgcolor(hiliteSess and anySessOn and activeSession ? color.new(color.blue, 92) : na, title = "Active Session")
atr = ta.atr(atrLength)
// ───────────────────────────── FVG (3-candle) ────────────────────────────
bullFVG = low > high[2] and (low - high[2]) >= minFvgGap * atr
bearFVG = high < low[2] and (low[2] - high) >= minFvgGap * atr
// ───────────────────────────── AMD STATE MACHINE ─────────────────────────
// 0 = find accumulation base | 1 = wait manipulation breakout | 2 = wait distribution FVG
accHi = ta.highest(high, accLength)
accLo = ta.lowest(low, accLength)
rangePct = (accHi - accLo) / close * 100.0
isBase = rangePct <= accRangeMax
var int state = 0
var float lockHi = na
var float lockLo = na
var box accBox = na
var box manBox = na
var int dir = 0
var float manExt = na
var int t0 = na
// STATE 0 — lock a tight base during an active session
if state == 0 and isBase and sessOK
lockHi := accHi
lockLo := accLo
accBox := box.new(bar_index - accLength + 1, lockHi, bar_index, lockLo, border_color = color.new(color.gray, 30), bgcolor = colAcc, border_width = 1)
t0 := bar_index
state := 1
// STATE 1 — extend base, wait for the manipulation breakout
if state == 1
if not na(accBox)
box.set_right(accBox, bar_index)
if close > lockHi
dir := -1
manBox := box.new(bar_index, high, bar_index, lockHi, border_color = color.new(color.red, 30), bgcolor = colManBear, border_width = 1)
manExt := high
t0 := bar_index
state := 2
else if close < lockLo
dir := 1
manBox := box.new(bar_index, lockLo, bar_index, low, border_color = color.new(color.green, 30), bgcolor = colManBull, border_width = 1)
manExt := low
t0 := bar_index
state := 2
else if bar_index - t0 > maxSearch
state := 0
accBox := na
// STATE 2 — manipulation runs, wait for the reversal (distribution) FVG
if state == 2
if not na(manBox)
box.set_right(manBox, bar_index)
if dir == -1
manExt := math.max(manExt, high)
if not na(manBox)
box.set_top(manBox, manExt)
if bearFVG
box.new(bar_index - 2, low[2], bar_index + maxSearch, high, border_color = color.new(color.red, 0), bgcolor = colDisBear, border_width = 2)
label.new(bar_index, manExt, "AMD Bearish", style = label.style_label_down, color = color.new(color.red, 10), textcolor = color.white, size = size.normal)
if showTrade
entry = low[2]
sl = entry + atr * atrSLMult
tp = entry - atr * atrSLMult * rrRatio
rgt = bar_index + maxSearch
box.new(bar_index, sl, rgt, entry, border_color = color.new(color.red, 100), bgcolor = color.new(color.red, 82), border_width = 0)
box.new(bar_index, entry, rgt, tp, border_color = color.new(color.green, 100), bgcolor = color.new(color.green, 82), border_width = 0)
line.new(bar_index, entry, rgt, entry, color = color.white, style = line.style_dashed, width = 1)
state := 0
accBox := na
else if bar_index - t0 > maxSearch
state := 0
accBox := na
else if dir == 1
manExt := math.min(manExt, low)
if not na(manBox)
box.set_bottom(manBox, manExt)
if bullFVG
box.new(bar_index - 2, low, bar_index + maxSearch, high[2], border_color = color.new(color.green, 0), bgcolor = colDisBull, border_width = 2)
label.new(bar_index, manExt, "AMD Bullish", style = label.style_label_up, color = color.new(color.green, 10), textcolor = color.white, size = size.normal)
if showTrade
entry = high[2]
sl = entry - atr * atrSLMult
tp = entry + atr * atrSLMult * rrRatio
rgt = bar_index + maxSearch
box.new(bar_index, entry, rgt, sl, border_color = color.new(color.red, 100), bgcolor = color.new(color.red, 82), border_width = 0)
box.new(bar_index, tp, rgt, entry, border_color = color.new(color.green, 100), bgcolor = color.new(color.green, 82), border_width = 0)
line.new(bar_index, entry, rgt, entry, color = color.white, style = line.style_dashed, width = 1)
state := 0
accBox := na
else if bar_index - t0 > maxSearch
state := 0
accBox := na
// ───────────────────────────── ALERTS ─────────────────────────────────────
alertcondition(bullFVG, "Bullish FVG", "Bullish FVG")
alertcondition(bearFVG, "Bearish FVG", "Bearish FVG")
Open-source script
In true PulseWire spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.
Open-source script
In true PulseWire spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.
