本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheTrendSniper
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheTrendSniper
//@version=6
indicator("FTS • Neon Session Sniper", overlay=true, max_boxes_count=150, max_bars_back=500)
length = input.int(18, "Structure pivot length", minval=1, maxval=100, group="Structure")
emaLength = input.int(7, "EMA length", minval=1, group="EMA")
window = input.int(30, "Reclaim / confirmation window (bars)", minval=1, group="Signals")
tz = input.string("America/New_York", "Session timezone", group="Sessions")
asia = input.session("1900-0300", "Tokyo / Asia", group="Sessions")
london = input.session("0300-1100", "London", group="Sessions")
ny = input.session("0800-1700", "New York", group="Sessions")
showBoxes = input.bool(true, "Session chambers", group="Style")
showDots = input.bool(true, "Swing dots", group="Style")
showSweeps = input.bool(true, "Reclaim markers", group="Style")
glow = input.bool(true, "EMA glow", group="Style")
bull = color.rgb(0, 245, 160)
bear = color.rgb(255, 55, 90)
ema = ta.ema(close, emaLength)
emaColor = close >= ema ? bull : bear
plot(glow ? ema : na, "EMA outer glow", color.new(emaColor, 90), 9)
plot(glow ? ema : na, "EMA inner glow", color.new(emaColor, 75), 5)
plot(ema, "EMA core", emaColor, 2)
type Chamber
string title
string hours
color tint
bool active = false
float hi = na
float lo = na
float lastHi = na
float lastLo = na
int ended = na
bool highTaken = false
bool lowTaken = false
int lowBreachBar = na
int highBreachBar = na
float lowExtreme = na
float highExtreme = na
box drawing = na
method update(Chamber s) =>
bool inside = not na(time(timeframe.period, s.hours, tz))
bool sweepLow = false
bool sweepHigh = false
if inside and not s.active
s.hi := high
s.lo := low
if showBoxes
s.drawing := box.new(
time, high, time_close, low,
xloc=xloc.bar_time,
border_color=color.new(s.tint, 35),
border_width=1,
bgcolor=color.new(s.tint, 93),
text=s.title,
text_color=s.tint,
text_size=size.small,
text_halign=text.align_left,
text_valign=text.align_top)
if inside
s.hi := math.max(s.hi, high)
s.lo := math.min(s.lo, low)
if showBoxes and not na(s.drawing)
box.set_top(s.drawing, s.hi)
box.set_bottom(s.drawing, s.lo)
box.set_right(s.drawing, time_close)
if not inside and s.active
s.lastHi := s.hi
s.lastLo := s.lo
s.ended := time
s.highTaken := false
s.lowTaken := false
s.lowBreachBar := na
s.highBreachBar := na
s.lowExtreme := na
s.highExtreme := na
// Monitor completed session ranges for 24 hours.
// A breach can reclaim the level several candles later.
if barstate.isconfirmed and not inside and not na(s.ended) and time - s.ended < 86400000
if not s.lowTaken
if low < s.lastLo
if na(s.lowBreachBar)
s.lowBreachBar := bar_index
s.lowExtreme := low
else
s.lowExtreme := math.min(s.lowExtreme, low)
if not na(s.lowBreachBar)
if bar_index - s.lowBreachBar > window
s.lowTaken := true
else if close > s.lastLo and close < s.lastHi
sweepLow := true
s.lowTaken := true
if not s.highTaken
if high > s.lastHi
if na(s.highBreachBar)
s.highBreachBar := bar_index
s.highExtreme := high
else
s.highExtreme := math.max(s.highExtreme, high)
if not na(s.highBreachBar)
if bar_index - s.highBreachBar > window
s.highTaken := true
else if close < s.lastHi and close > s.lastLo
sweepHigh := true
s.highTaken := true
s.active := inside
[sweepLow, sweepHigh]
var Chamber a = Chamber.new("TOKYO // ASIA", asia, color.rgb(154, 105, 255))
var Chamber l = Chamber.new("LONDON", london, color.rgb(45, 150, 255))
var Chamber n = Chamber.new("NEW YORK", ny, color.rgb(255, 190, 55))
[aLow, aHigh] = a.update()
[lLow, lHigh] = l.update()
[nLow, nHigh] = n.update()
isOneMinute = timeframe.isminutes and timeframe.multiplier == 1
lowSweep = isOneMinute and (aLow or lLow or nLow)
highSweep = isOneMinute and (aHigh or lHigh or nHigh)
// Confirmed market-structure swings.
ph = ta.pivothigh(high, length, length)
pl = ta.pivotlow(low, length, length)
var float swingHigh = na
var float swingLow = na
var bool highBroken = false
var bool lowBroken = false
var int structure = 0
if barstate.isconfirmed
if not na(ph)
swingHigh := ph
highBroken := false
if not na(pl)
swingLow := pl
lowBroken := false
if not highBroken and not na(swingHigh) and close > swingHigh
structure := 1
highBroken := true
if not lowBroken and not na(swingLow) and close < swingLow
structure := -1
lowBroken := true
// Only swing dots. Plotted back after pivot confirmation.
plotshape(
showDots and barstate.isconfirmed ? pl : na,
"Swing low",
shape.circle,
location.absolute,
bull,
offset=-length,
size=size.tiny)
plotshape(
showDots and barstate.isconfirmed ? ph : na,
"Swing high",
shape.circle,
location.absolute,
bear,
offset=-length,
size=size.tiny)
// Pending structure confirmation.
var int pending = 0
var int setupBar = na
var float trigger = na
var float extreme = na
bool buy = false
bool sell = false
if isOneMinute and barstate.isconfirmed
if pending != 0
bool expired = bar_index - setupBar > window
bool invalid = pending == 1 ? close < extreme : close > extreme
if expired or invalid
pending := 0
else if bar_index > setupBar
buy := pending == 1 and close > trigger and close[1] <= trigger and close > ema
sell := pending == -1 and close < trigger and close[1] >= trigger and close < ema
if buy or sell
pending := 0
// Reject ambiguous simultaneous reclaim directions.
if lowSweep and highSweep
pending := 0
else if not buy and not sell
if lowSweep and not na(swingHigh[1])
pending := 1
setupBar := bar_index
trigger := swingHigh[1]
extreme := aLow ? a.lowExtreme : lLow ? l.lowExtreme : n.lowExtreme
int breachedAt = aLow ? a.lowBreachBar : lLow ? l.lowBreachBar : n.lowBreachBar
// A multi-candle reclaim can also be the structure-break candle.
buy := bar_index > breachedAt and close > trigger and close[1] <= trigger and close > ema
if buy
pending := 0
else if highSweep and not na(swingLow[1])
pending := -1
setupBar := bar_index
trigger := swingLow[1]
extreme := aHigh ? a.highExtreme : lHigh ? l.highExtreme : n.highExtreme
int breachedAt = aHigh ? a.highBreachBar : lHigh ? l.highBreachBar : n.highBreachBar
sell := bar_index > breachedAt and close < trigger and close[1] >= trigger and close < ema
if sell
pending := 0
plotshape(
showSweeps and lowSweep,
"Low reclaimed",
shape.diamond,
location.belowbar,
color.new(bull, 35),
size=size.tiny)
plotshape(
showSweeps and highSweep,
"High reclaimed",
shape.diamond,
location.abovebar,
color.new(bear, 35),
size=size.tiny)
plotshape(
buy,
"BUY",
shape.labelup,
location.belowbar,
bull,
text="BUY",
textcolor=color.black,
size=size.small)
plotshape(
sell,
"SELL",
shape.labeldown,
location.abovebar,
bear,
text="SELL",
textcolor=color.white,
size=size.small)
alertcondition(
buy,
"FTS BUY",
"FTS BUY: session low reclaim + 1m structure break + close above EMA. {{ticker}} {{close}}")
alertcondition(
sell,
"FTS SELL",
"FTS SELL: session high reclaim + 1m structure break + close below EMA. {{ticker}} {{close}}")
var table status = table.new(
position.top_right, 1, 2,
bgcolor=color.rgb(15, 18, 25),
frame_color=color.new(color.gray, 65),
frame_width=1)
if barstate.islast
table.cell(
status, 0, 0,
"FTS // SESSION SNIPER",
text_color=color.rgb(255, 190, 55),
text_size=size.small)
string state = not isOneMinute ? "USE 1m FOR SIGNALS" : pending == 1 ? "LOW RECLAIMED // WAITING BUY" : pending == -1 ? "HIGH RECLAIMED // WAITING SELL" : "SCANNING SESSION LIQUIDITY"
table.cell(
status, 0, 1,
state,
text_color=pending == 1 ? bull : pending == -1 ? bear : color.silver,
text_size=size.tiny)