Gain Alarm (multi-TF )369
Gain Alarm (multi-TF)
This script triggers an alert once the price candel body stays fully above a chosen line for a predefined period of time.
Select your own ticker, timeframe, and price level.
The alert is triggered only once per session.
A line is plotted on the chart with a label showing the selected timeframe, so you know which alert is active.
⚠️ Note: you must manually create a separate TradingView alert using the condition provided by the script.
Candlestick analysis
Bullish/Bearish Engulfing Candle ScannerFinds instances on any time frame of bullish or bearish engulfing candles, those with some increased average volume showing green arrows to highlight, otherwise red.
Bullish & Bearish Reversal Pattern with Sequential Bars20 Bollinger Bands and custom Stochasti_MTM Setup
Both long and short reversal signals.
FVG Donchian Channel strategy30min FVG + Donchian Channel strategy
buy sell by 30min fvg
and stoploss , take profit by Donchian Channel
Run the strategy on the 1min timeframe!
Loss Alarm (multi-TF)Loss Alarm (multi-TF)
This script triggers an alert once the price candel body stays fully under a chosen line for a predefined period of time.
Select your own ticker, timeframe, and price level.
The alert is triggered only once per session.
A line is plotted on the chart with a label showing the selected timeframe, so you know which alert is active.
⚠️ Note: you must manually create a separate TradingView alert using the condition provided by the script.
Cruce TEMA SMMA con Alarma a 12 Barras LLUCes un cruce de TEMA SMMA, luego del cruce contar 12 barras controladas por otros
3C FractalsIts based on Williams Fractals indicator, but instead of using 5 candles to mark the fractals, it uses only 3.
Gap Finder v6Detects unfilled price gaps with clean lines and labels with percentage size of the gap. Lines extend 16 bars and labels extend 14 bars past last bar.
Triple EMA (5, 8, 13) + Confirmed Alerts with SoundThis indicator uses three Exponential Moving Averages (EMA 5, 8, and 13) to generate buy and sell signals when the EMAs are properly aligned and not touching. Signals are confirmed on candle close and can trigger customizable sound alerts directly from the TradingView alert panel.
나의 strategy//@version=6
strategy("Jimb0ws Strategy + All Bubble Zones + Golden Candles + Limited Signals", overlay=true, calc_on_every_tick=true, max_bars_back=5000)
// ─── INPUTS ─────────────────────────────────────────────────────────────────
pipBodyTol = input.float(0, title="Pip Tolerance for Body Touch", step=0.0001)
pipWickTol = input.float(0.002, title="Pip Tolerance for Wick Touch", step=0.0001)
maxBodyDrive = input.float(0, title="Max Drive from EMA for Body", step=0.0001)
maxWickDrive = input.float(0.002, title="Max Drive from EMA for Wick", step=0.0001)
fractalSizeOpt = input.string("small", title="Fractal Size", options= )
minBodySize = input.float(0, title="Min Body Size for Golden Candle", step=0.0001)
longOffsetPips = input.int(25, title="Long Label Offset (pips)", minval=0)
shortOffsetPips = input.int(25, title="Short Label Offset (pips)", minval=0)
consolOffsetPips = input.int(25, title="Consolidation Label Offset (pips)", minval=0)
longSignType = input.string("Label Down", title="Long Bubble Sign Type", options= )
shortSignType = input.string("Label Up", title="Short Bubble Sign Type", options= )
consolSignType = input.string("Label Down", title="Consolidation Bubble Sign Type", options= )
enable1hEmaFilter = input.bool(true, title="Disable Signals beyond 1H EMA50")
showZones = input.bool(true, title="Show Bubble Zones")
showSigns = input.bool(true, title="Show Bubble Signs")
maxSignalsPerBubble = input.int(3, title="Max Signals Per Bubble", minval=1)
// Toggle for session filter
enableSessionFilter = input.bool(true, title="Enable Active Trading Session Filter")
sessionInput = input.session("0100-1900", title="Active Trading Session")
tzInput = input.string("Europe/London", title="Session Timezone",
options= )
actualTZ = tzInput == "Exchange" ? syminfo.timezone : tzInput
infoOffsetPips = input.int(5, title="Info Line Offset Above Price (pips)", minval=0)
warnOffsetPips = input.int(10, title="Warning Label Offset Above Infobar (pips)", minval=0)
show1HInfo = input.bool(true, title="Show 1H Bubble Info")
bufferLimit = 5000 - 1
enableProxFilter = input.bool(true, title="Disable Signals Near 1H EMA50")
proxRangePips = input.int(10, title="Proximity Range (pips)", minval=0)
enableWickFilter = input.bool(true, title="Filter Golden-Candle Wick Overdrive")
wickOverdrivePips = input.int(0, title="Wick Overdrive Range (pips)", minval=0)
// turn Robin candles on/off
enableRobin = input.bool(true, title="Enable Robin Candles")
// ATR panel attached to 4H info
showPrevDayATR = input.bool(true, title="Show Previous Day ATR Panel")
atrLenPrevDay = input.int(14, title="ATR Length (Daily)", minval=1)
atrPanelOffsetPips = input.int(3, title="ATR Panel Offset Above 4H Info (pips)", minval=0)
// ─── STRATEGY TRADES (EMA200 SL, RR=2 TP) ───────────────────────────────────
enableAutoTrades = input.bool(true, title="Enable Strategy Entries/Exits")
takeProfitRR = input.float(2.0, title="TP Risk:Reward (x)", step=0.1, minval=0.1)
// ─── SL/TP info label on signals ─────────────────────────────────────────────
showSLTPPanel = input.bool(true, title="Show SL/TP Info Above Signals")
sltpOffsetPips = input.int(4, title="SL/TP Label Offset (pips)", minval=0)
// Previous Day ATR (D1, lookahead OFF) -> lock to yesterday with
dailyATR = request.security(syminfo.tickerid, "D", ta.atr(atrLenPrevDay),
lookahead=barmerge.lookahead_off, gaps=barmerge.gaps_off)
prevDayATR = dailyATR
// Convert to pips (FX: pip ≈ mintick*10)
pipValueFX = syminfo.mintick * 10.0
prevATR_pips_1d = na(prevDayATR) ? na : math.round((prevDayATR / pipValueFX) * 10.0) / 10.0
// Create table once
var table atrPanel = na
if barstate.isfirst and na(atrPanel)
// columns=1, rows=2 (title row + value row)
atrPanel := table.new(position.top_right, 1, 2, border_width=1,
frame_color=color.new(color.gray, 0), border_color=color.new(color.gray, 0))
// Update cells each last bar
if barstate.islast and not na(atrPanel)
if showPrevDayATR
titleTxt = "Prev Day ATR (" + str.tostring(atrLenPrevDay) + ")"
valTxt = na(prevDayATR) ? "n/a"
: str.tostring(prevATR_pips_1d) + " pips (" + str.tostring(prevDayATR, format.mintick) + ")"
table.cell(atrPanel, 0, 0, titleTxt, text_color=color.white, bgcolor=color.new(color.blue, 25))
table.cell(atrPanel, 0, 1, valTxt, text_color=color.white, bgcolor=color.new(color.black, 0))
else
// Hide panel by writing empty strings
table.cell(atrPanel, 0, 0, "")
table.cell(atrPanel, 0, 1, "")
// Visuals for orders
showSLTP = input.bool(true, title="Show SL/TP Lines & Labels")
// ─── EMA CALCULATIONS & PLOTTING ──────────────────────────────────────────────
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
ema200 = ta.ema(close, 200)
ema50_1h = request.security(syminfo.tickerid, "60", ta.ema(close, 50), lookahead=barmerge.lookahead_on)
plot(ema20, color=color.white, linewidth=4, title="EMA20")
plot(ema50, color=color.yellow, linewidth=4, title="EMA50")
plot(ema100, color=color.blue, linewidth=4, title="EMA100")
plot(ema200, color=color.purple, linewidth=6, title="EMA200") // ← and this
plot(ema50_1h, title="EMA50 (1H)", color=color.yellow, linewidth=2)
// pip-unit helper
pipUnit1h = syminfo.mintick * proxRangePips * 10
upperBand1h = ema50_1h + pipUnit1h
lowerBand1h = ema50_1h - pipUnit1h
// draw top/bottom lines in one-liner plots, then fill the gap
p_top = plot(enableProxFilter ? upperBand1h : na, title="Prox Zone Top", color=color.new(color.yellow,90), linewidth=1)
p_bottom = plot(enableProxFilter ? lowerBand1h : na, title="Prox Zone Bottom", color=color.new(color.yellow,90), linewidth=1)
fill(p_top, p_bottom, color.new(color.yellow,90))
// ─── BUBBLE CONDITIONS & ZONES ───────────────────────────────────────────────
longBub = ema20 > ema50 and ema50 > ema100
shortBub = ema20 < ema50 and ema50 < ema100
consolOn = not longBub and not shortBub
longCol = color.new(color.green, 85)
shortCol = color.new(color.red, 85)
consCol = color.new(color.orange, 85)
bgcolor(showZones ? (longBub ? longCol : shortBub ? shortCol : consCol) : na)
// convert pips to price‐units
wickOverUnit = syminfo.mintick * wickOverdrivePips * 10
// detect when the wick “pierces” EMA50 by more than that amount
overdriveLong = low < ema50 - wickOverUnit // long bubble: wick dipped below EMA50
overdriveShort = high > ema50 + wickOverUnit // short bubble: wick rose above EMA50
// ─── GOLDEN-CANDLE LOGIC & COLORING ──────────────────────────────────────────
trendLong = longBub
trendShort = shortBub
bodySize = math.abs(close - open)
hasBigBody = bodySize >= minBodySize
bodyLow = math.min(open, close)
bodyHigh = math.max(open, close)
wickLow = low
wickHigh = high
bOK20_L = bodyLow <= ema20 + pipBodyTol and bodyLow >= ema20 - maxBodyDrive and close > ema20
bOK50_L = bodyLow <= ema50 + pipBodyTol and bodyLow >= ema50 - maxBodyDrive and close > ema50
wOK20_L = wickLow <= ema20 + pipWickTol and wickLow >= ema20 - maxWickDrive and close > ema20
wOK50_L = wickLow <= ema50 + pipWickTol and wickLow >= ema50 - maxWickDrive and close > ema50
isGoldenLong = trendLong and hasBigBody and (bOK20_L or bOK50_L or wOK20_L or wOK50_L)
bOK20_S = bodyHigh >= ema20 - pipBodyTol and bodyHigh <= ema20 + maxBodyDrive and close < ema20
bOK50_S = bodyHigh >= ema50 - pipBodyTol and bodyHigh <= ema50 + maxBodyDrive and close < ema50
wOK20_S = wickHigh >= ema20 - pipWickTol and wickHigh <= ema20 + maxWickDrive and close < ema20
wOK50_S = wickHigh >= ema50 - pipWickTol and wickHigh <= ema50 + maxWickDrive and close < ema50
isGoldenShort= trendShort and hasBigBody and (bOK20_S or bOK50_S or wOK20_S or wOK50_S)
// ─── WICK-OVERDRIVE VETO ────────────────────────────────────────────────────
if enableWickFilter
// veto any golden on which the wick over-drove the EMA50
isGoldenLong := isGoldenLong and not overdriveLong
isGoldenShort := isGoldenShort and not overdriveShort
barcolor((isGoldenLong or isGoldenShort) ? color.new(#FFD700, 0) : na)
// ─── ROBIN CANDLES ──────────────────────────────────────────────────────────
goldShort1 = isGoldenShort
goldLong1 = isGoldenLong
goldLow1 = math.min(open , close )
goldHigh1 = math.max(open , close )
robinShort = shortBub and goldShort1 and math.min(open, close) < goldLow1
robinLong = longBub and goldLong1 and math.max(open, close) > goldHigh1
barcolor(enableRobin and (robinShort or robinLong) ? color.purple : na)
// ─── FRACTALS ─────────────────────────────────────────────────────────────────
pL = ta.pivotlow(low, 2, 2)
pH = ta.pivothigh(high, 2, 2)
plotshape(not shortBub and not consolOn and not na(pL) and fractalSizeOpt == "tiny",
style=shape.triangleup, location=location.belowbar, offset=-2, color=color.green, size=size.tiny)
plotshape(not shortBub and not consolOn and not na(pL) and fractalSizeOpt == "small",
style=shape.triangleup, location=location.belowbar, offset=-2, color=color.green, size=size.small)
plotshape(not shortBub and not consolOn and not na(pL) and fractalSizeOpt == "normal",
style=shape.triangleup, location=location.belowbar, offset=-2, color=color.green, size=size.normal)
plotshape(not shortBub and not consolOn and not na(pL) and fractalSizeOpt == "large",
style=shape.triangleup, location=location.belowbar, offset=-2, color=color.green, size=size.large)
plotshape(not longBub and not consolOn and not na(pH) and fractalSizeOpt == "tiny",
style=shape.triangledown, location=location.abovebar, offset=-2, color=color.red, size=size.tiny)
plotshape(not longBub and not consolOn and not na(pH) and fractalSizeOpt == "small",
style=shape.triangledown, location=location.abovebar, offset=-2, color=color.red, size=size.small)
plotshape(not longBub and not consolOn and not na(pH) and fractalSizeOpt == "normal",
style=shape.triangledown, location=location.abovebar, offset=-2, color=color.red, size=size.normal)
plotshape(not longBub and not consolOn and not na(pH) and fractalSizeOpt == "large",
style=shape.triangledown, location=location.abovebar, offset=-2, color=color.red, size=size.large)
// ─── BUY/SELL SIGNALS & LIMIT ─────────────────────────────────────────────────
var int buyCount = 0
var int sellCount = 0
if longBub and not longBub
buyCount := 0
if shortBub and not shortBub
sellCount := 0
goldLong2 = isGoldenLong
goldShort2 = isGoldenShort
roofCheck = math.max(open , close ) >= math.max(open , close )
floorCheck = math.min(open , close ) <= math.min(open , close )
buySignal = goldLong2 and not na(pL) and roofCheck
sellSignal = goldShort2 and not na(pH) and floorCheck
// Original: inSession = not na(time(timeframe.period, sessionInput, actualTZ))
inSessionRaw = not na(time(timeframe.period, sessionInput, actualTZ))
sessionOK = enableSessionFilter ? inSessionRaw : true
// Apply 1H EMA50 filter
disableBy1h = enable1hEmaFilter and ((request.security(syminfo.tickerid, "60", ema20 ema50_1h) or (request.security(syminfo.tickerid, "60", ema20>ema50 and ema50>ema100) and close < ema50_1h))
// ─── PROXIMITY VETO ────────────────────────────────────────────────
near1hZone = enableProxFilter and close >= lowerBand1h and close <= upperBand1h
validBuy = buySignal and sessionOK and buyCount < maxSignalsPerBubble and not disableBy1h and not near1hZone
validSell = sellSignal and sessionOK and sellCount < maxSignalsPerBubble and not disableBy1h and not near1hZone
plotshape(validBuy, title="BUY", style=shape.labelup, location=location.belowbar,
color=color.green, text="BUY $", textcolor=color.white, size=size.large)
plotshape(validSell, title="SELL", style=shape.labeldown, location=location.abovebar,
color=color.red, text="SELL $", textcolor=color.white, size=size.large)
if validBuy
buyCount += 1
if validSell
sellCount += 1
// ─── 4H BUBBLE INFO LINE ──────────────────────────────────────────────────────
var line infoLine4h = na
var label infoLbl4h = na
var label atrPrevLbl = na // ATR label handle
var string bubble4hType = na
var int bubble4hStartTime = na
var int bubble4hStartIdx = na
time4h = request.security(syminfo.tickerid, "240", time, lookahead=barmerge.lookahead_on)
ema20_4h = request.security(syminfo.tickerid, "240", ta.ema(close, 20), lookahead=barmerge.lookahead_on)
ema50_4h = request.security(syminfo.tickerid, "240", ta.ema(close, 50), lookahead=barmerge.lookahead_on)
ema100_4h = request.security(syminfo.tickerid, "240", ta.ema(close,100), lookahead=barmerge.lookahead_on)
long4h = ema20_4h > ema50_4h and ema50_4h > ema100_4h
short4h = ema20_4h < ema50_4h and ema50_4h < ema100_4h
cons4h = not long4h and not short4h
if long4h and not long4h
bubble4hType := "LONG"
bubble4hStartTime := time4h
bubble4hStartIdx := bar_index
else if short4h and not short4h
bubble4hType := "SHORT"
bubble4hStartTime := time4h
bubble4hStartIdx := bar_index
else if cons4h and not cons4h
bubble4hType := "CONS"
bubble4hStartTime := time4h
bubble4hStartIdx := bar_index
active4h = ((bubble4hType=="LONG" and long4h) or (bubble4hType=="SHORT" and short4h) or (bubble4hType=="CONS" and cons4h)) and not na(bubble4hStartTime)
if active4h
durH4 = math.floor((time - bubble4hStartTime) / 3600000)
ts4 = str.format("{0,date,yyyy-MM-dd} {0,time,HH:mm}", bubble4hStartTime)
txt4 = "4H " + bubble4hType + " Bubble since " + ts4 + " Dur: " + str.tostring(durH4) + "h"
col4 = bubble4hType=="LONG" ? color.green : bubble4hType=="SHORT" ? color.red : color.orange
pipUnit4 = syminfo.mintick * 10
infoPrice4 = high + (infoOffsetPips + warnOffsetPips + 5) * pipUnit4
xStart4 = math.max(bubble4hStartIdx, bar_index - bufferLimit)
if na(infoLine4h)
infoLine4h := line.new(xStart4, infoPrice4, bar_index, infoPrice4, extend=extend.none, color=col4, width=2)
else
line.set_xy1(infoLine4h, xStart4, infoPrice4)
line.set_xy2(infoLine4h, bar_index, infoPrice4)
line.set_color(infoLine4h, col4)
if na(infoLbl4h)
infoLbl4h := label.new(bar_index, infoPrice4, txt4, xloc.bar_index, yloc.price, col4, label.style_label_left, color.white, size.small)
else
label.set_xy(infoLbl4h, bar_index, infoPrice4)
label.set_text(infoLbl4h, txt4)
label.set_color(infoLbl4h, col4)
// Prev Day ATR label just above the 4H info panel
if showPrevDayATR
atrValTxt = na(prevDayATR) ? "n/a" : str.tostring(prevATR_pips_1d) + " pips (" + str.tostring(prevDayATR, format.mintick) + ")"
atrTxt = "Prev Day ATR (" + str.tostring(atrLenPrevDay) + ") " + atrValTxt
atrY = infoPrice4 + pipUnit4 * atrPanelOffsetPips
if na(atrPrevLbl)
atrPrevLbl := label.new(bar_index, atrY, atrTxt, xloc.bar_index, yloc.price, color.new(color.blue, 25), label.style_label_left, color.white, size.small)
else
label.set_xy(atrPrevLbl, bar_index, atrY)
label.set_text(atrPrevLbl, atrTxt)
label.set_color(atrPrevLbl, color.new(color.blue, 25))
else
if not na(atrPrevLbl)
label.delete(atrPrevLbl)
atrPrevLbl := na
else
// Cleanup when 4H panel is not active
if not na(infoLine4h)
line.delete(infoLine4h)
infoLine4h := na
if not na(infoLbl4h)
label.delete(infoLbl4h)
infoLbl4h := na
bubble4hType := na
if not na(atrPrevLbl)
label.delete(atrPrevLbl)
atrPrevLbl := na
// ─── 1H BUBBLE INFO & WARNING PANEL ─────────────────────────────────────────
var line infoLine1h = na
var label infoLbl1h = na
var label warnLbl1h = na
var string bubble1hType = na
var int bubble1hStartTime = na
var int bubble1hStartIdx = na
var float pipUnit = na
var color col = na
var int xStart = na
var float infoPrice = na
var string txt = ""
// 1H trend state (kept same logic as your original)
long1h = request.security(syminfo.tickerid, "60", ema20>ema50 and ema50>ema100, lookahead=barmerge.lookahead_on)
short1h = request.security(syminfo.tickerid, "60", ema20 ema50_1h
warnY = infoPrice1h + warnOffsetPips * pipUnit1h
if na(warnLbl1h)
warnLbl1h := label.new(bar_index, warnY, "Potential Consolidation Warning",
xloc.bar_index, yloc.price, color.new(color.yellow,0),
label.style_label_up, color.black, size.small)
else
label.set_xy(warnLbl1h, bar_index, warnY)
label.set_text(warnLbl1h, "Potential Consolidation Warning")
else
if not na(warnLbl1h)
label.delete(warnLbl1h)
warnLbl1h := na
else
if not na(infoLine1h)
line.delete(infoLine1h)
infoLine1h := na
if not na(infoLbl1h)
label.delete(infoLbl1h)
infoLbl1h := na
if not na(warnLbl1h)
label.delete(warnLbl1h)
warnLbl1h := na
bubble1hType := na
// ─── ALERTS ─────────────────────────────────────────────────────────────────
alertcondition(validBuy, title="Jimb0ws Strategy – BUY", message="🔥 BUY signal on {{ticker}} at {{close}}")
alertcondition(validSell, title="Jimb0ws Strategy – SELL", message="🔻 SELL signal on {{ticker}} at {{close}}")
if validBuy
alert("🔥 BUY signal on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
if validSell
alert("🔻 SELL signal on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
// ─── SL/TP drawing handles (globals) ────────────────────────────────────────
var line slLine = na
var line tpLine = na
var label slLabel = na
var label tpLabel = na
var float slPrice = na
var float tpPrice = na
// Working vars so they exist on all bars
var float longEntry = na
var float longSL = na
var float longTP = na
var float riskL = na
var float shortEntry = na
var float shortSL = na
var float shortTP = na
var float riskS = na
// last SL/TP info label so we can replace it each time
var label sltpInfoLbl = na
// ─── Draw SL/TP info label exactly when a signal fires ──────────────────────
if showSLTPPanel and (validBuy or validSell)
// delete prior info label
if not na(sltpInfoLbl)
label.delete(sltpInfoLbl)
float pipUnit = syminfo.mintick * 10.0
float yAbove = high + sltpOffsetPips * pipUnit
// Entry is the close of the signal bar
float entry = close
// Choose SL by your rule:
// - LONG: if ema200 > ema100 -> SL = ema100, else SL = ema200
// - SHORT: if ema200 < ema100 -> SL = ema100, else SL = ema200
bool isLong = validBuy
float sl = isLong ? (ema200 > ema100 ? ema100 : ema200)
: (ema200 < ema100 ? ema100 : ema200)
// Compute TP using RR; guard for bad risk
float rr = takeProfitRR // your RR input (e.g., 2.0)
float risk = isLong ? (entry - sl) : (sl - entry)
float tp = na
if risk > syminfo.mintick
tp := isLong ? (entry + rr * risk) : (entry - rr * risk)
// Build label text (mintick formatting)
string slTxt = "SL " + str.tostring(sl, format.mintick)
string tpTxt = na(tp) ? "TP n/a" : "TP " + str.tostring(tp, format.mintick)
string txt = slTxt + " " + tpTxt
// Color by side and draw
color bgCol = isLong ? color.new(color.green, 10) : color.new(color.red, 10)
sltpInfoLbl := label.new(bar_index, yAbove, txt,
xloc.bar_index, yloc.price,
bgCol, label.style_label_left, color.white, size.small)
// ─── ORDERS: dynamic SL (EMA100 vs EMA200), TP = RR * risk + draw SL/TP ─────
if enableAutoTrades and barstate.isconfirmed and not na(ema100) and not na(ema200)
// LONGS — if EMA200 > EMA100 ⇒ SL = EMA100; else ⇒ SL = EMA200
if validBuy and strategy.position_size <= 0
longEntry := close
longSL := ema200 > ema100 ? ema100 : ema200
if longSL < longEntry - syminfo.mintick
riskL := longEntry - longSL
longTP := longEntry + takeProfitRR * riskL
if strategy.position_size < 0
strategy.close("Short", comment="Flip→Long")
strategy.entry("Long", strategy.long)
strategy.exit("Long-EXIT", from_entry="Long", stop=longSL, limit=longTP)
// store & draw
slPrice := longSL
tpPrice := longTP
if showSLTP
if not na(slLine)
line.delete(slLine)
if not na(tpLine)
line.delete(tpLine)
if not na(slLabel)
label.delete(slLabel)
if not na(tpLabel)
label.delete(tpLabel)
// lines
slLine := line.new(bar_index, slPrice, bar_index + 1, slPrice, extend=extend.right, color=color.red, width=2)
tpLine := line.new(bar_index, tpPrice, bar_index + 1, tpPrice, extend=extend.right, color=color.green, width=2)
// labels with exact prices
slLabel := label.new(bar_index + 1, slPrice, "SL " + str.tostring(slPrice, format.mintick), xloc.bar_index, yloc.price, color.new(color.red, 10), label.style_label_right, color.white, size.small)
tpLabel := label.new(bar_index + 1, tpPrice, "TP " + str.tostring(tpPrice, format.mintick), xloc.bar_index, yloc.price, color.new(color.green, 10), label.style_label_right, color.white, size.small)
// SHORTS — if EMA200 < EMA100 ⇒ SL = EMA100; else ⇒ SL = EMA200
if validSell and strategy.position_size >= 0
shortEntry := close
shortSL := ema200 < ema100 ? ema100 : ema200
if shortSL > shortEntry + syminfo.mintick
riskS := shortSL - shortEntry
shortTP := shortEntry - takeProfitRR * riskS
if strategy.position_size > 0
strategy.close("Long", comment="Flip→Short")
strategy.entry("Short", strategy.short)
strategy.exit("Short-EXIT", from_entry="Short", stop=shortSL, limit=shortTP)
// store & draw
slPrice := shortSL
tpPrice := shortTP
if showSLTP
if not na(slLine)
line.delete(slLine)
if not na(tpLine)
line.delete(tpLine)
if not na(slLabel)
label.delete(slLabel)
if not na(tpLabel)
label.delete(tpLabel)
slLine := line.new(bar_index, slPrice, bar_index + 1, slPrice, extend=extend.right, color=color.red, width=2)
tpLine := line.new(bar_index, tpPrice, bar_index + 1, tpPrice, extend=extend.right, color=color.green, width=2)
slLabel := label.new(bar_index + 1, slPrice, "SL " + str.tostring(slPrice, format.mintick), xloc.bar_index, yloc.price, color.new(color.red, 10), label.style_label_right, color.white, size.small)
tpLabel := label.new(bar_index + 1, tpPrice, "TP " + str.tostring(tpPrice, format.mintick), xloc.bar_index, yloc.price, color.new(color.green, 10), label.style_label_right, color.white, size.small)
// Keep labels pinned to the right of current bar while trade is open
if showSLTP and strategy.position_size != 0 and not na(slPrice) and not na(tpPrice)
label.set_xy(slLabel, bar_index + 1, slPrice)
label.set_text(slLabel, "SL " + str.tostring(slPrice, format.mintick))
label.set_xy(tpLabel, bar_index + 1, tpPrice)
label.set_text(tpLabel, "TP " + str.tostring(tpPrice, format.mintick))
// Clean up drawings when flat
if strategy.position_size == 0
slPrice := na
tpPrice := na
if not na(slLine)
line.delete(slLine)
slLine := na
if not na(tpLine)
line.delete(tpLine)
tpLine := na
if not na(slLabel)
label.delete(slLabel)
slLabel := na
if not na(tpLabel)
label.delete(tpLabel)
tpLabel := na
cd_correlation_analys_Cxcd_correlation_analys_Cx
General:
This indicator is designed for correlation analysis by classifying stocks (487 in total) and indices (14 in total) traded on Borsa İstanbul (BIST) on a sectoral basis.
Tradingview's sector classifications (20) have been strictly adhered to for sector grouping.
Depending on user preference, the analysis can be performed within sectors, between sectors, or manually (single asset).
Let me express my gratitude to the code author, @fikira, beforehand; you will find the reason for my thanks in the context.
Details:
First, let's briefly mention how this indicator could have been prepared using the classic method before going into details.
Classically, assets could be divided into groups of forty (40), and the analysis could be performed using the built-in function:
ta.correlation(source1, source2, length) → series float.
I chose sectoral classification because I believe there would be a higher probability of assets moving together, rather than using fixed-number classes.
In this case, 21 arrays were formed with the following number of elements:
(3, 11, 21, 60, 29, 20, 12, 3, 31, 5, 10, 11, 6, 48, 73, 62, 16, 19, 13, 34 and indices (14)).
However, you might have noticed that some arrays have more than 40 elements. This is exactly where @Fikira's indicator came to the rescue. When I examined their excellent indicator, I saw that it could process 120 assets in a single operation. (I believe this was the first limit overrun; thanks again.)
It was amazing to see that data for 3 pairs could be called in a single request using a special method.
You can find the details here:
When I adapted it for BIST, I found it sufficient to call data for 2 pairs instead of 3 in a single go. Since asset prices are regular and have 2 decimal places, I used a fixed multiplier of $10^8$ and a fixed decimal count of 2 in Fikira's formulas.
With this method, the (high, low, open, close) values became accessible for each asset.
The summary up to this point is that instead of the ready-made formula + groups of 40, I used variable-sized groups and the method I will detail now.
Correlation/harmony/co-movement between assets provides advantages to market participants. Coherent assets are expected to rise or fall simultaneously.
Therefore, to convert co-movement into a mathematical value, I defined the possible movements of the current candle relative to the previous candle bar over a certain period (user-defined). These are:
Up := high > high and low > low
Down := high < high and low < low
Inside := high <= high and low >= low
Outside := high >= high and low <= low and NOT Inside.
Ignore := high = low = open = close
If both assets performed the same movement, 1 was added to the tracking counter.
If (Up-Up), (Down-Down), (Inside-Inside), or (Outside-Outside), then counter := counter + 1.
If the period length is 100 and the counter is 75, it means there is 75% co-movement.
Corr = counter / period ($75/100$)
Average = ta.sma(Corr, 100) is obtained.
The highest coefficients recorded in the array are presented to the user in a table.
From the user menu options, the user can choose to compare:
• With assets in its own sector
• With assets in the selected sector
• By activating the confirmation box and manually entering a single asset for comparison.
Table display options can be adjusted from the Settings tab.
In the attached examples:
Results for AKBNK stock from the Finance sector compared with GARAN stock from the same sector:
Timeframe: Daily, Period: 50 => Harmony 76% (They performed the same movement in 38 out of 50 bars)
Comment: Opposite movements at swing high and low levels may indicate a change in the direction of the price flow (SMT).
Looking at ASELS from the Electronic Technology sector over the last 30 daily candles, they performed the same movements by 40% with XU100, 73.3% (22/30) with XUTEK (Technology Index), and 86.9% according to the averages.
Comment: It is more appropriate to follow ASELS stock with XUTEK (Technology index) instead of the general index (XU100). Opposite movements at swing high and low levels may indicate a change in the direction of the price flow (SMT).
Again, when ASELS stock is taken on H1 instead of daily, and the length is 100 instead of 30, the harmony rate is seen to be 87%.
Please share your thoughts and criticisms regarding the indicator, which I prepared with a bit of an educational purpose specifically for BIST.
Happy trading.
Liquidity & SMT Detector//@version=5
indicator("Liquidity & SMT Detector", overlay=true, max_lines_count=500, max_labels_count=500)
// ============================================
// INPUT SETTINGS
// ============================================
// Group 1: Liquidity Detection
swing_length = input.int(15, "Swing Length", minval=5, maxval=50, group="Liquidity Detection")
swing_strength = input.int(3, "Swing Strength (bars clear)", minval=1, maxval=10, group="Liquidity Detection")
max_lines = input.int(10, "Max Lines Displayed", minval=3, maxval=50, group="Liquidity Detection")
line_color_high = input.color(color.red, "High Line Color", group="Liquidity Detection")
line_color_low = input.color(color.green, "Low Line Color", group="Liquidity Detection")
line_width = input.int(2, "Line Width", minval=1, maxval=5, group="Liquidity Detection")
show_labels = input.bool(true, "Show H/L Labels", group="Liquidity Detection")
// Group 2: Displacement Detection
enable_displacement = input.bool(true, "Enable Displacement Detection", group="Displacement")
displacement_min_points = input.float(10.0, "Min Points Move", minval=1.0, maxval=100.0, step=1.0, group="Displacement")
displacement_multiplier = input.float(3.0, "Size Multiplier", minval=2.0, maxval=10.0, step=0.5, group="Displacement")
displacement_period = input.int(30, "Average Period", minval=10, maxval=100, group="Displacement")
displacement_color_bull = input.color(color.new(color.aqua, 70), "Bullish Color", group="Displacement")
displacement_color_bear = input.color(color.new(color.orange, 70), "Bearish Color", group="Displacement")
show_displacement_label = input.bool(true, "Show Labels", group="Displacement")
// Group 3: SMT Detection
enable_smt = input.bool(true, "Enable SMT Detection", group="SMT Divergence")
nq_symbol = input.string("NQ1!", "Nasdaq Symbol", group="SMT Divergence")
es_symbol = input.string("ES1!", "S&P500 Symbol", group="SMT Divergence")
smt_lookback = input.int(20, "Lookback Period", minval=5, maxval=100, group="SMT Divergence")
smt_line_color = input.color(color.yellow, "SMT Line Color", group="SMT Divergence")
smt_text_color = input.color(color.yellow, "SMT Text Color", group="SMT Divergence")
// Group 4: Consolidation Zone
enable_consolidation = input.bool(true, "Enable Consolidation Zone", group="Consolidation")
consol_lookback = input.int(10, "Lookback Period", minval=5, maxval=50, group="Consolidation")
consol_range_percent = input.float(0.5, "Max Range %", minval=0.1, maxval=2.0, step=0.1, group="Consolidation")
consol_vol_threshold = input.float(0.7, "Volume Threshold", minval=0.3, maxval=1.0, step=0.1, group="Consolidation")
consol_color = input.color(color.new(color.red, 85), "Zone Color", group="Consolidation")
// ============================================
// ARRAYS FOR LINE/LABEL MANAGEMENT
// ============================================
var line high_lines = array.new_line()
var line low_lines = array.new_line()
var label high_labels = array.new_label()
var label low_labels = array.new_label()
var float high_levels = array.new_float()
var float low_levels = array.new_float()
var line smt_lines = array.new_line()
var label smt_labels = array.new_label()
var float smt_nq_levels = array.new_float()
var float smt_es_levels = array.new_float()
var bool smt_nq_lower = array.new_bool()
// ============================================
// FUNCTION: DETECT SWING HIGHS (STRONGER)
// ============================================
isSwingHigh(len, strength) =>
is_pivot = true
pivot_high = high
for i = 1 to strength
if high >= pivot_high or high >= pivot_high
is_pivot := false
break
if is_pivot
for i = strength + 1 to len
if high > pivot_high or high > pivot_high
is_pivot := false
break
is_pivot
// ============================================
// FUNCTION: DETECT SWING LOWS (STRONGER)
// ============================================
isSwingLow(len, strength) =>
is_pivot = true
pivot_low = low
for i = 1 to strength
if low <= pivot_low or low <= pivot_low
is_pivot := false
break
if is_pivot
for i = strength + 1 to len
if low < pivot_low or low < pivot_low
is_pivot := false
break
is_pivot
// ============================================
// SWING HIGH DETECTION & LINE DRAWING
// ============================================
if isSwingHigh(swing_length, swing_strength)
swing_high = high
new_line = line.new(bar_index - swing_length, swing_high, bar_index, swing_high, color=line_color_high, width=line_width, style=line.style_dashed)
array.push(high_lines, new_line)
array.push(high_levels, swing_high)
if show_labels
new_label = label.new(bar_index - swing_length, swing_high, "H", color=color.new(line_color_high, 80), textcolor=line_color_high, style=label.style_label_down, size=size.small)
array.push(high_labels, new_label)
if array.size(high_lines) > max_lines
line.delete(array.shift(high_lines))
array.shift(high_levels)
if show_labels and array.size(high_labels) > 0
label.delete(array.shift(high_labels))
// ============================================
// SWING LOW DETECTION & LINE DRAWING
// ============================================
if isSwingLow(swing_length, swing_strength)
swing_low = low
new_line = line.new(bar_index - swing_length, swing_low, bar_index, swing_low, color=line_color_low, width=line_width, style=line.style_dashed)
array.push(low_lines, new_line)
array.push(low_levels, swing_low)
if show_labels
new_label = label.new(bar_index - swing_length, swing_low, "L", color=color.new(line_color_low, 80), textcolor=line_color_low, style=label.style_label_up, size=size.small)
array.push(low_labels, new_label)
if array.size(low_lines) > max_lines
line.delete(array.shift(low_lines))
array.shift(low_levels)
if show_labels and array.size(low_labels) > 0
label.delete(array.shift(low_labels))
// ============================================
// UPDATE EXISTING LINES & CHECK FOR SWEEPS
// ============================================
if array.size(high_lines) > 0
for i = array.size(high_lines) - 1 to 0
current_line = array.get(high_lines, i)
current_level = array.get(high_levels, i)
if close > current_level
line.delete(current_line)
array.remove(high_lines, i)
array.remove(high_levels, i)
if show_labels and i < array.size(high_labels)
label.delete(array.get(high_labels, i))
array.remove(high_labels, i)
else
line.set_x2(current_line, bar_index)
if array.size(low_lines) > 0
for i = array.size(low_lines) - 1 to 0
current_line = array.get(low_lines, i)
current_level = array.get(low_levels, i)
if close < current_level
line.delete(current_line)
array.remove(low_lines, i)
array.remove(low_levels, i)
if show_labels and i < array.size(low_labels)
label.delete(array.get(low_labels, i))
array.remove(low_labels, i)
else
line.set_x2(current_line, bar_index)
// ============================================
// DISPLACEMENT CANDLE DETECTION
// ============================================
body_size = math.abs(close - open)
avg_body = ta.sma(math.abs(close - open), displacement_period)
candle_range = high - low
points_moved = body_size
is_min_points = points_moved >= displacement_min_points
is_strong_body = body_size > (avg_body * displacement_multiplier)
is_impulsive = body_size > (candle_range * 0.6)
is_displacement = enable_displacement and is_min_points and is_strong_body and is_impulsive
is_bullish = close > open
bgcolor(is_displacement ? (is_bullish ? displacement_color_bull : displacement_color_bear) : na)
if is_displacement and show_displacement_label
label.new(bar_index, is_bullish ? low : low, "D", color=color.new(is_bullish ? color.aqua : color.orange, 50), textcolor=is_bullish ? color.aqua : color.orange, style=label.style_label_down, size=size.small, yloc=yloc.belowbar)
// ============================================
// CONSOLIDATION ZONE DETECTION
// ============================================
consol_highest = ta.highest(high, consol_lookback)
consol_lowest = ta.lowest(low, consol_lookback)
consol_range = consol_highest - consol_lowest
consol_range_pct = (consol_range / close) * 100
consol_avg_volume = ta.sma(volume, consol_lookback)
consol_current_vol = ta.sma(volume, math.min(consol_lookback, bar_index + 1))
consol_low_volume = consol_current_vol < (consol_avg_volume * consol_vol_threshold)
consol_body_sizes = array.new_float()
for i = 0 to math.min(consol_lookback - 1, bar_index)
array.push(consol_body_sizes, math.abs(close - open ))
consol_avg_body = array.avg(consol_body_sizes)
consol_overall_avg = ta.sma(math.abs(close - open), 50)
consol_small_candles = consol_avg_body < (consol_overall_avg * 0.7)
consol_tight_range = consol_range_pct <= consol_range_percent
is_consolidation = enable_consolidation and consol_tight_range and consol_low_volume and consol_small_candles
bgcolor(is_consolidation ? consol_color : na, title="Consolidation Zone")
// ============================================
// SMT DIVERGENCE DETECTION
// ============================================
current_symbol = syminfo.ticker
comparison_symbol = str.contains(current_symbol, "NQ") ? es_symbol : nq_symbol
comparison_high = request.security(comparison_symbol, timeframe.period, high, lookahead=barmerge.lookahead_off)
comparison_low = request.security(comparison_symbol, timeframe.period, low, lookahead=barmerge.lookahead_off)
var float prev_current_low = na
var float prev_comparison_low = na
var int prev_swing_bar = na
current_is_swing_low = isSwingLow(swing_length, swing_strength)
comparison_is_swing_low = ta.lowestbars(comparison_low, swing_length * 2 + 1) == -swing_length
if enable_smt and current_is_swing_low
current_swing_low = low
comparison_swing_low = comparison_low
if not na(prev_current_low) and not na(prev_comparison_low)
current_lower = current_swing_low < prev_current_low
comparison_lower = comparison_swing_low < prev_comparison_low
is_smt = (current_lower and not comparison_lower) or (not current_lower and comparison_lower)
if is_smt
smt_line = line.new(prev_swing_bar, prev_current_low, bar_index - swing_length, current_swing_low, color=smt_line_color, width=2, style=line.style_solid)
mid_bar = math.round((prev_swing_bar + bar_index - swing_length) / 2)
mid_price = (prev_current_low + current_swing_low) / 2
smt_label = label.new(mid_bar, mid_price, "SMT", color=color.new(smt_line_color, 80), textcolor=smt_text_color, style=label.style_label_center, size=size.normal)
array.push(smt_lines, smt_line)
array.push(smt_labels, smt_label)
array.push(smt_nq_levels, str.contains(current_symbol, "NQ") ? current_swing_low : comparison_swing_low)
array.push(smt_es_levels, str.contains(current_symbol, "NQ") ? comparison_swing_low : current_swing_low)
array.push(smt_nq_lower, str.contains(current_symbol, "NQ") ? current_lower : comparison_lower)
prev_current_low := current_swing_low
prev_comparison_low := comparison_swing_low
prev_swing_bar := bar_index - swing_length
if enable_smt and array.size(smt_lines) > 0
for i = array.size(smt_lines) - 1 to 0
nq_level = array.get(smt_nq_levels, i)
es_level = array.get(smt_es_levels, i)
nq_was_lower = array.get(smt_nq_lower, i)
current_nq_low = str.contains(current_symbol, "NQ") ? low : comparison_low
current_es_low = str.contains(current_symbol, "NQ") ? comparison_low : low
es_now_lower = current_es_low < es_level
nq_now_lower = current_nq_low < nq_level
smt_invalidated = (nq_was_lower and es_now_lower) or (not nq_was_lower and nq_now_lower)
if smt_invalidated
line.delete(array.get(smt_lines, i))
label.delete(array.get(smt_labels, i))
array.remove(smt_lines, i)
array.remove(smt_labels, i)
array.remove(smt_nq_levels, i)
array.remove(smt_es_levels, i)
array.remove(smt_nq_lower, i)
// ============================================
// ALERTS
// ============================================
alertcondition(array.size(high_lines) < array.size(high_lines) , title="Liquidity Sweep High", message="High liquidity swept at {{close}}")
alertcondition(array.size(low_lines) < array.size(low_lines) , title="Liquidity Sweep Low", message="Low liquidity swept at {{close}}")
alertcondition(is_displacement, title="Displacement Candle", message="Displacement candle detected at {{close}}")
alertcondition(is_consolidation, title="Consolidation Zone", message="Market entering consolidation at {{close}}")
Liquidity & SMT Detector//@version=5
indicator("Liquidity & SMT Detector", overlay=true, max_lines_count=500, max_labels_count=500)
// ============================================
// INPUT SETTINGS
// ============================================
// Group 1: Liquidity Detection
swing_length = input.int(15, "Swing Length", minval=5, maxval=50, group="Liquidity Detection")
swing_strength = input.int(3, "Swing Strength (bars clear)", minval=1, maxval=10, group="Liquidity Detection")
max_lines = input.int(10, "Max Lines Displayed", minval=3, maxval=50, group="Liquidity Detection")
line_color_high = input.color(color.red, "High Line Color", group="Liquidity Detection")
line_color_low = input.color(color.green, "Low Line Color", group="Liquidity Detection")
line_width = input.int(2, "Line Width", minval=1, maxval=5, group="Liquidity Detection")
show_labels = input.bool(true, "Show H/L Labels", group="Liquidity Detection")
// Group 2: Displacement Detection
enable_displacement = input.bool(true, "Enable Displacement Detection", group="Displacement")
displacement_multiplier = input.float(3.5, "Size Multiplier", minval=2.0, maxval=10.0, step=0.5, group="Displacement")
displacement_period = input.int(30, "Average Period", minval=10, maxval=100, group="Displacement")
displacement_min_percent = input.float(0.3, "Min Move %", minval=0.1, maxval=2.0, step=0.1, group="Displacement")
displacement_color_bull = input.color(color.new(color.aqua, 70), "Bullish Color", group="Displacement")
displacement_color_bear = input.color(color.new(color.orange, 70), "Bearish Color", group="Displacement")
show_displacement_label = input.bool(true, "Show Labels", group="Displacement")
// Group 3: SMT Detection
enable_smt = input.bool(true, "Enable SMT Detection", group="SMT Divergence")
nq_symbol = input.string("NQ1!", "Nasdaq Symbol", group="SMT Divergence")
es_symbol = input.string("ES1!", "S&P500 Symbol", group="SMT Divergence")
smt_lookback = input.int(20, "Lookback Period", minval=5, maxval=100, group="SMT Divergence")
smt_line_color = input.color(color.yellow, "SMT Line Color", group="SMT Divergence")
smt_text_color = input.color(color.yellow, "SMT Text Color", group="SMT Divergence")
// ============================================
// ARRAYS FOR LINE/LABEL MANAGEMENT
// ============================================
var line high_lines = array.new_line()
var line low_lines = array.new_line()
var label high_labels = array.new_label()
var label low_labels = array.new_label()
var float high_levels = array.new_float()
var float low_levels = array.new_float()
// ============================================
// FUNCTION: DETECT SWING HIGHS (STRONGER)
// ============================================
isSwingHigh(len, strength) =>
is_pivot = true
pivot_high = high
for i = 1 to strength
if high >= pivot_high or high >= pivot_high
is_pivot := false
break
if is_pivot
for i = strength + 1 to len
if high > pivot_high or high > pivot_high
is_pivot := false
break
is_pivot
// ============================================
// FUNCTION: DETECT SWING LOWS (STRONGER)
// ============================================
isSwingLow(len, strength) =>
is_pivot = true
pivot_low = low
for i = 1 to strength
if low <= pivot_low or low <= pivot_low
is_pivot := false
break
if is_pivot
for i = strength + 1 to len
if low < pivot_low or low < pivot_low
is_pivot := false
break
is_pivot
// ============================================
// SWING HIGH DETECTION & LINE DRAWING
// ============================================
if isSwingHigh(swing_length, swing_strength)
swing_high = high
new_line = line.new(bar_index - swing_length, swing_high, bar_index, swing_high, color=line_color_high, width=line_width, style=line.style_dashed)
array.push(high_lines, new_line)
array.push(high_levels, swing_high)
if show_labels
new_label = label.new(bar_index - swing_length, swing_high, "H", color=color.new(line_color_high, 80), textcolor=line_color_high, style=label.style_label_down, size=size.small)
array.push(high_labels, new_label)
// Limit number of lines
if array.size(high_lines) > max_lines
line.delete(array.shift(high_lines))
array.shift(high_levels)
if show_labels and array.size(high_labels) > 0
label.delete(array.shift(high_labels))
// ============================================
// SWING LOW DETECTION & LINE DRAWING
// ============================================
if isSwingLow(swing_length, swing_strength)
swing_low = low
new_line = line.new(bar_index - swing_length, swing_low, bar_index, swing_low, color=line_color_low, width=line_width, style=line.style_dashed)
array.push(low_lines, new_line)
array.push(low_levels, swing_low)
if show_labels
new_label = label.new(bar_index - swing_length, swing_low, "L", color=color.new(line_color_low, 80), textcolor=line_color_low, style=label.style_label_up, size=size.small)
array.push(low_labels, new_label)
// Limit number of lines
if array.size(low_lines) > max_lines
line.delete(array.shift(low_lines))
array.shift(low_levels)
if show_labels and array.size(low_labels) > 0
label.delete(array.shift(low_labels))
// ============================================
// UPDATE EXISTING LINES & CHECK FOR SWEEPS
// ============================================
if array.size(high_lines) > 0
for i = array.size(high_lines) - 1 to 0
current_line = array.get(high_lines, i)
current_level = array.get(high_levels, i)
if close > current_level
line.delete(current_line)
array.remove(high_lines, i)
array.remove(high_levels, i)
if show_labels and i < array.size(high_labels)
label.delete(array.get(high_labels, i))
array.remove(high_labels, i)
else
line.set_x2(current_line, bar_index)
if array.size(low_lines) > 0
for i = array.size(low_lines) - 1 to 0
current_line = array.get(low_lines, i)
current_level = array.get(low_levels, i)
if close < current_level
line.delete(current_line)
array.remove(low_lines, i)
array.remove(low_levels, i)
if show_labels and i < array.size(low_labels)
label.delete(array.get(low_labels, i))
array.remove(low_labels, i)
else
line.set_x2(current_line, bar_index)
// ============================================
// DISPLACEMENT CANDLE DETECTION
// ============================================
body_size = math.abs(close - open)
avg_body = ta.sma(math.abs(close - open), displacement_period)
candle_range = high - low
avg_range = ta.sma(high - low, displacement_period)
price_move_percent = (body_size / close) * 100
// Stricter criteria for true displacement
is_strong_body = body_size > (avg_body * displacement_multiplier)
is_strong_range = candle_range > (avg_range * displacement_multiplier)
is_significant_move = price_move_percent >= displacement_min_percent
is_impulsive = body_size > (candle_range * 0.6)
is_displacement = enable_displacement and is_strong_body and is_strong_range and is_significant_move and is_impulsive
is_bullish = close > open
bgcolor(is_displacement ? (is_bullish ? displacement_color_bull : displacement_color_bear) : na)
if is_displacement and show_displacement_label
label.new(bar_index, is_bullish ? high : low, "D", color=color.new(is_bullish ? color.aqua : color.orange, 50), textcolor=is_bullish ? color.aqua : color.orange, style=is_bullish ? label.style_label_up : label.style_label_down, size=size.tiny)
// ============================================
// SMT DIVERGENCE DETECTION
// ============================================
current_symbol = syminfo.ticker
comparison_symbol = str.contains(current_symbol, "NQ") ? es_symbol : nq_symbol
comparison_high = request.security(comparison_symbol, timeframe.period, high, lookahead=barmerge.lookahead_off)
comparison_low = request.security(comparison_symbol, timeframe.period, low, lookahead=barmerge.lookahead_off)
var float prev_current_low = na
var float prev_comparison_low = na
var int prev_swing_bar = na
current_is_swing_low = isSwingLow(swing_length, swing_strength)
comparison_is_swing_low = ta.lowestbars(comparison_low, swing_length * 2 + 1) == -swing_length
if enable_smt and current_is_swing_low
current_swing_low = low
comparison_swing_low = comparison_low
if not na(prev_current_low) and not na(prev_comparison_low)
current_lower = current_swing_low < prev_current_low
comparison_lower = comparison_swing_low < prev_comparison_low
is_smt = (current_lower and not comparison_lower) or (not current_lower and comparison_lower)
if is_smt
smt_line = line.new(prev_swing_bar, prev_current_low, bar_index - swing_length, current_swing_low, color=smt_line_color, width=2, style=line.style_solid)
mid_bar = math.round((prev_swing_bar + bar_index - swing_length) / 2)
mid_price = (prev_current_low + current_swing_low) / 2
label.new(mid_bar, mid_price, "SMT", color=color.new(smt_line_color, 80), textcolor=smt_text_color, style=label.style_label_center, size=size.normal)
prev_current_low := current_swing_low
prev_comparison_low := comparison_swing_low
prev_swing_bar := bar_index - swing_length
// ============================================
// ALERTS
// ============================================
alertcondition(array.size(high_lines) < array.size(high_lines) , title="Liquidity Sweep High", message="High liquidity swept at {{close}}")
alertcondition(array.size(low_lines) < array.size(low_lines) , title="Liquidity Sweep Low", message="Low liquidity swept at {{close}}")
alertcondition(is_displacement, title="Displacement Candle", message="Displacement candle detected at {{close}}")
Liquidity & SMT Detector//@version=5
indicator("Liquidity & SMT Detector", overlay=true, max_lines_count=500, max_labels_count=500)
// ============================================
// INPUT SETTINGS
// ============================================
// Group 1: Liquidity Detection
swing_length = input.int(10, "Swing Length", minval=3, maxval=50, group="Liquidity Detection")
max_lines = input.int(20, "Max Lines Displayed", minval=5, maxval=100, group="Liquidity Detection")
line_color_high = input.color(color.red, "High Line Color", group="Liquidity Detection")
line_color_low = input.color(color.green, "Low Line Color", group="Liquidity Detection")
line_width = input.int(2, "Line Width", minval=1, maxval=5, group="Liquidity Detection")
show_labels = input.bool(true, "Show H/L Labels", group="Liquidity Detection")
// Group 2: Displacement Detection
enable_displacement = input.bool(true, "Enable Displacement Detection", group="Displacement")
displacement_multiplier = input.float(2.0, "Size Multiplier", minval=1.5, maxval=5.0, step=0.1, group="Displacement")
displacement_period = input.int(20, "Average Period", minval=10, maxval=50, group="Displacement")
displacement_color_bull = input.color(color.new(color.aqua, 70), "Bullish Color", group="Displacement")
displacement_color_bear = input.color(color.new(color.orange, 70), "Bearish Color", group="Displacement")
show_displacement_label = input.bool(true, "Show Labels", group="Displacement")
// Group 3: SMT Detection
enable_smt = input.bool(true, "Enable SMT Detection", group="SMT Divergence")
nq_symbol = input.string("NQ1!", "Nasdaq Symbol", group="SMT Divergence")
es_symbol = input.string("ES1!", "S&P500 Symbol", group="SMT Divergence")
smt_lookback = input.int(20, "Lookback Period", minval=5, maxval=100, group="SMT Divergence")
smt_line_color = input.color(color.yellow, "SMT Line Color", group="SMT Divergence")
smt_text_color = input.color(color.yellow, "SMT Text Color", group="SMT Divergence")
// ============================================
// ARRAYS FOR LINE/LABEL MANAGEMENT
// ============================================
var line high_lines = array.new_line()
var line low_lines = array.new_line()
var label high_labels = array.new_label()
var label low_labels = array.new_label()
var float high_levels = array.new_float()
var float low_levels = array.new_float()
// ============================================
// FUNCTION: DETECT SWING HIGHS
// ============================================
isSwingHigh(len) =>
highestBar = ta.highestbars(high, len * 2 + 1)
highestBar == -len
// ============================================
// FUNCTION: DETECT SWING LOWS
// ============================================
isSwingLow(len) =>
lowestBar = ta.lowestbars(low, len * 2 + 1)
lowestBar == -len
// ============================================
// SWING HIGH DETECTION & LINE DRAWING
// ============================================
if isSwingHigh(swing_length)
swing_high = high
new_line = line.new(bar_index - swing_length, swing_high, bar_index, swing_high, color=line_color_high, width=line_width, style=line.style_dashed)
array.push(high_lines, new_line)
array.push(high_levels, swing_high)
if show_labels
new_label = label.new(bar_index - swing_length, swing_high, "H", color=color.new(line_color_high, 80), textcolor=line_color_high, style=label.style_label_down, size=size.small)
array.push(high_labels, new_label)
// Limit number of lines
if array.size(high_lines) > max_lines
line.delete(array.shift(high_lines))
array.shift(high_levels)
if show_labels and array.size(high_labels) > 0
label.delete(array.shift(high_labels))
// ============================================
// SWING LOW DETECTION & LINE DRAWING
// ============================================
if isSwingLow(swing_length)
swing_low = low
new_line = line.new(bar_index - swing_length, swing_low, bar_index, swing_low, color=line_color_low, width=line_width, style=line.style_dashed)
array.push(low_lines, new_line)
array.push(low_levels, swing_low)
if show_labels
new_label = label.new(bar_index - swing_length, swing_low, "L", color=color.new(line_color_low, 80), textcolor=line_color_low, style=label.style_label_up, size=size.small)
array.push(low_labels, new_label)
// Limit number of lines
if array.size(low_lines) > max_lines
line.delete(array.shift(low_lines))
array.shift(low_levels)
if show_labels and array.size(low_labels) > 0
label.delete(array.shift(low_labels))
// ============================================
// UPDATE EXISTING LINES & CHECK FOR SWEEPS
// ============================================
if array.size(high_lines) > 0
for i = array.size(high_lines) - 1 to 0
current_line = array.get(high_lines, i)
current_level = array.get(high_levels, i)
if close > current_level
line.delete(current_line)
array.remove(high_lines, i)
array.remove(high_levels, i)
if show_labels and i < array.size(high_labels)
label.delete(array.get(high_labels, i))
array.remove(high_labels, i)
else
line.set_x2(current_line, bar_index)
if array.size(low_lines) > 0
for i = array.size(low_lines) - 1 to 0
current_line = array.get(low_lines, i)
current_level = array.get(low_levels, i)
if close < current_level
line.delete(current_line)
array.remove(low_lines, i)
array.remove(low_levels, i)
if show_labels and i < array.size(low_labels)
label.delete(array.get(low_labels, i))
array.remove(low_labels, i)
else
line.set_x2(current_line, bar_index)
// ============================================
// DISPLACEMENT CANDLE DETECTION
// ============================================
body_size = math.abs(close - open)
avg_body = ta.sma(math.abs(close - open), displacement_period)
is_displacement = enable_displacement and body_size > (avg_body * displacement_multiplier)
is_bullish = close > open
bgcolor(is_displacement ? (is_bullish ? displacement_color_bull : displacement_color_bear) : na)
if is_displacement and show_displacement_label
label.new(bar_index, is_bullish ? high : low, "D", color=color.new(is_bullish ? color.aqua : color.orange, 50), textcolor=is_bullish ? color.aqua : color.orange, style=is_bullish ? label.style_label_up : label.style_label_down, size=size.tiny)
// ============================================
// SMT DIVERGENCE DETECTION
// ============================================
current_symbol = syminfo.ticker
comparison_symbol = str.contains(current_symbol, "NQ") ? es_symbol : nq_symbol
comparison_high = request.security(comparison_symbol, timeframe.period, high, lookahead=barmerge.lookahead_off)
comparison_low = request.security(comparison_symbol, timeframe.period, low, lookahead=barmerge.lookahead_off)
var float prev_current_low = na
var float prev_comparison_low = na
var int prev_swing_bar = na
current_is_swing_low = isSwingLow(swing_length)
comparison_is_swing_low = ta.lowestbars(comparison_low, swing_length * 2 + 1) == -swing_length
if enable_smt and current_is_swing_low
current_swing_low = low
comparison_swing_low = comparison_low
if not na(prev_current_low) and not na(prev_comparison_low)
current_lower = current_swing_low < prev_current_low
comparison_lower = comparison_swing_low < prev_comparison_low
is_smt = (current_lower and not comparison_lower) or (not current_lower and comparison_lower)
if is_smt
smt_line = line.new(prev_swing_bar, prev_current_low, bar_index - swing_length, current_swing_low, color=smt_line_color, width=2, style=line.style_solid)
mid_bar = math.round((prev_swing_bar + bar_index - swing_length) / 2)
mid_price = (prev_current_low + current_swing_low) / 2
label.new(mid_bar, mid_price, "SMT", color=color.new(smt_line_color, 80), textcolor=smt_text_color, style=label.style_label_center, size=size.normal)
prev_current_low := current_swing_low
prev_comparison_low := comparison_swing_low
prev_swing_bar := bar_index - swing_length
// ============================================
// ALERTS
// ============================================
alertcondition(array.size(high_lines) < array.size(high_lines) , title="Liquidity Sweep High", message="High liquidity swept at {{close}}")
alertcondition(array.size(low_lines) < array.size(low_lines) , title="Liquidity Sweep Low", message="Low liquidity swept at {{close}}")
alertcondition(is_displacement, title="Displacement Candle", message="Displacement candle detected at {{close}}")
Liquidity & SMT Detector//@version=5
indicator("Liquidity & SMT Detector", overlay=true, max_lines_count=500, max_labels_count=500)
// ============================================
// INPUT SETTINGS
// ============================================
// Group 1: Liquidity Detection
swing_length = input.int(10, "Swing Length", minval=3, maxval=50, group="Liquidity Detection")
line_color_high = input.color(color.red, "High Line Color", group="Liquidity Detection")
line_color_low = input.color(color.green, "Low Line Color", group="Liquidity Detection")
line_width = input.int(2, "Line Width", minval=1, maxval=5, group="Liquidity Detection")
show_labels = input.bool(true, "Show H/L Labels", group="Liquidity Detection")
// Group 2: Displacement Detection
enable_displacement = input.bool(true, "Enable Displacement Detection", group="Displacement")
displacement_multiplier = input.float(2.0, "Size Multiplier", minval=1.5, maxval=5.0, step=0.1, group="Displacement")
displacement_period = input.int(20, "Average Period", minval=10, maxval=50, group="Displacement")
displacement_color_bull = input.color(color.new(color.aqua, 70), "Bullish Color", group="Displacement")
displacement_color_bear = input.color(color.new(color.orange, 70), "Bearish Color", group="Displacement")
show_displacement_label = input.bool(true, "Show Labels", group="Displacement")
// Group 3: SMT Detection
enable_smt = input.bool(true, "Enable SMT Detection", group="SMT Divergence")
nq_symbol = input.string("NQ1!", "Nasdaq Symbol", group="SMT Divergence")
es_symbol = input.string("ES1!", "S&P500 Symbol", group="SMT Divergence")
smt_lookback = input.int(20, "Lookback Period", minval=5, maxval=100, group="SMT Divergence")
smt_line_color = input.color(color.yellow, "SMT Line Color", group="SMT Divergence")
smt_text_color = input.color(color.yellow, "SMT Text Color", group="SMT Divergence")
// ============================================
// ARRAYS FOR LINE/LABEL MANAGEMENT
// ============================================
var line high_lines = array.new_line()
var line low_lines = array.new_line()
var label high_labels = array.new_label()
var label low_labels = array.new_label()
var float high_levels = array.new_float()
var float low_levels = array.new_float()
// ============================================
// FUNCTION: DETECT SWING HIGHS
// ============================================
isSwingHigh(len) =>
highestBar = ta.highestbars(high, len * 2 + 1)
highestBar == -len
// ============================================
// FUNCTION: DETECT SWING LOWS
// ============================================
isSwingLow(len) =>
lowestBar = ta.lowestbars(low, len * 2 + 1)
lowestBar == -len
// ============================================
// SWING HIGH DETECTION & LINE DRAWING
// ============================================
if isSwingHigh(swing_length)
swing_high = high
new_line = line.new(bar_index - swing_length, swing_high, bar_index, swing_high, color=line_color_high, width=line_width, style=line.style_dashed)
array.push(high_lines, new_line)
array.push(high_levels, swing_high)
if show_labels
new_label = label.new(bar_index - swing_length, swing_high, "H", color=color.new(line_color_high, 80), textcolor=line_color_high, style=label.style_label_down, size=size.small)
array.push(high_labels, new_label)
// ============================================
// SWING LOW DETECTION & LINE DRAWING
// ============================================
if isSwingLow(swing_length)
swing_low = low
new_line = line.new(bar_index - swing_length, swing_low, bar_index, swing_low, color=line_color_low, width=line_width, style=line.style_dashed)
array.push(low_lines, new_line)
array.push(low_levels, swing_low)
if show_labels
new_label = label.new(bar_index - swing_length, swing_low, "L", color=color.new(line_color_low, 80), textcolor=line_color_low, style=label.style_label_up, size=size.small)
array.push(low_labels, new_label)
// ============================================
// UPDATE EXISTING LINES & CHECK FOR SWEEPS
// ============================================
if array.size(high_lines) > 0
for i = array.size(high_lines) - 1 to 0
current_line = array.get(high_lines, i)
current_level = array.get(high_levels, i)
if close > current_level
line.delete(current_line)
array.remove(high_lines, i)
array.remove(high_levels, i)
if show_labels and i < array.size(high_labels)
label.delete(array.get(high_labels, i))
array.remove(high_labels, i)
else
line.set_x2(current_line, bar_index)
if array.size(low_lines) > 0
for i = array.size(low_lines) - 1 to 0
current_line = array.get(low_lines, i)
current_level = array.get(low_levels, i)
if close < current_level
line.delete(current_line)
array.remove(low_lines, i)
array.remove(low_levels, i)
if show_labels and i < array.size(low_labels)
label.delete(array.get(low_labels, i))
array.remove(low_labels, i)
else
line.set_x2(current_line, bar_index)
// ============================================
// DISPLACEMENT CANDLE DETECTION
// ============================================
body_size = math.abs(close - open)
avg_body = ta.sma(math.abs(close - open), displacement_period)
is_displacement = enable_displacement and body_size > (avg_body * displacement_multiplier)
is_bullish = close > open
bgcolor(is_displacement ? (is_bullish ? displacement_color_bull : displacement_color_bear) : na)
if is_displacement and show_displacement_label
label.new(bar_index, is_bullish ? high : low, "D", color=color.new(is_bullish ? color.aqua : color.orange, 50), textcolor=is_bullish ? color.aqua : color.orange, style=is_bullish ? label.style_label_up : label.style_label_down, size=size.tiny)
// ============================================
// SMT DIVERGENCE DETECTION
// ============================================
current_symbol = syminfo.ticker
comparison_symbol = str.contains(current_symbol, "NQ") ? es_symbol : nq_symbol
comparison_high = request.security(comparison_symbol, timeframe.period, high, lookahead=barmerge.lookahead_off)
comparison_low = request.security(comparison_symbol, timeframe.period, low, lookahead=barmerge.lookahead_off)
var float prev_current_low = na
var float prev_comparison_low = na
var int prev_swing_bar = na
current_is_swing_low = isSwingLow(swing_length)
comparison_is_swing_low = ta.lowestbars(comparison_low, swing_length * 2 + 1) == -swing_length
if enable_smt and current_is_swing_low
current_swing_low = low
comparison_swing_low = comparison_low
if not na(prev_current_low) and not na(prev_comparison_low)
current_lower = current_swing_low < prev_current_low
comparison_lower = comparison_swing_low < prev_comparison_low
is_smt = (current_lower and not comparison_lower) or (not current_lower and comparison_lower)
if is_smt
smt_line = line.new(prev_swing_bar, prev_current_low, bar_index - swing_length, current_swing_low, color=smt_line_color, width=2, style=line.style_solid)
mid_bar = math.round((prev_swing_bar + bar_index - swing_length) / 2)
mid_price = (prev_current_low + current_swing_low) / 2
label.new(mid_bar, mid_price, "SMT", color=color.new(smt_line_color, 80), textcolor=smt_text_color, style=label.style_label_center, size=size.normal)
prev_current_low := current_swing_low
prev_comparison_low := comparison_swing_low
prev_swing_bar := bar_index - swing_length
// ============================================
// ALERTS
// ============================================
alertcondition(array.size(high_lines) < array.size(high_lines) , title="Liquidity Sweep High", message="High liquidity swept at {{close}}")
alertcondition(array.size(low_lines) < array.size(low_lines) , title="Liquidity Sweep Low", message="Low liquidity swept at {{close}}")
alertcondition(is_displacement, title="Displacement Candle", message="Displacement candle detected at {{close}}")
Displacement + Liquidity Levels//@version=5
indicator("Displacement + Liquidity Levels", overlay=true, max_lines_count=500)
// INPUTS
swingLeft = input.int(5, "Swing Left")
swingRight = input.int(5, "Swing Right")
rangeLen = input.int(10, "Range Lookback")
// SWINGS
relevantHigh = ta.pivothigh(high, swingLeft, swingRight)
relevantLow = ta.pivotlow(low, swingLeft, swingRight)
// ARRAYS
var line highLines = array.new_line()
var line lowLines = array.new_line()
// LIQUIDITY SWEEPS
sweepHigh = not na(relevantHigh) and high > relevantHigh and close < relevantHigh
sweepLow = not na(relevantLow) and low < relevantLow and close > relevantLow
// DISPLACEMENT
bodySize = math.abs(close - open)
candleRange = high - low
avgRange = ta.sma(candleRange, rangeLen)
displacementUp = close > open and bodySize > candleRange*0.6 and candleRange > avgRange
displacementDown = open > close and bodySize > candleRange*0.6 and candleRange > avgRange
// SIGNALS
bullishSignal = sweepLow and displacementUp
bearishSignal = sweepHigh and displacementDown
plotshape(bullishSignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.large, text="LONG")
plotshape(bearishSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.large, text="SHORT")
// NEUE LINIEN
if not na(relevantHigh)
l = line.new(bar_index, relevantHigh, bar_index + 500, relevantHigh, extend=extend.right, color=color.red, width=2)
array.push(highLines, l)
if not na(relevantLow)
l = line.new(bar_index, relevantLow, bar_index + 500, relevantLow, extend=extend.right, color=color.green, width=2)
array.push(lowLines, l)
// LINIEN LÖSCHEN, WENN GETOUCHT
for i = array.size(highLines)-1 to 0 by -1
l = array.get(highLines, i)
if high >= line.get_price(l, bar_index)
line.delete(l)
array.remove(highLines, i)
for i = array.size(lowLines)-1 to 0 by -1
l = array.get(lowLines, i)
if low <= line.get_price(l, bar_index)
line.delete(l)
array.remove(lowLines, i)
// High/Low-Relevanz sofort
liqHigh = ta.highest(high, 3)
liqLow = ta.lowest(low, 3)
if high == liqHigh
line.new(bar_index, high, bar_index + 500, high, extend=extend.right, color=color.red, width=2)
if low == liqLow
line.new(bar_index, low, bar_index + 500, low, extend=extend.right, color=color.green, width=2)
SMC Minimal Setup//@version=5
indicator("SMC Minimal Setup", overlay=true)
// === INPUTS ===
swingLeft = input.int(5, "Swing Left")
swingRight = input.int(5, "Swing Right")
structureLookback = input.int(20, "Structure Lookback")
// === MARKET STRUCTURE ===
var string structure = "neutral"
if high > ta.highest(high , structureLookback)
structure := "bullish"
if low < ta.lowest(low , structureLookback)
structure := "bearish"
// === SWING LEVELS ===
relevantHigh = ta.pivothigh(high, swingLeft, swingRight)
relevantLow = ta.pivotlow(low, swingLeft, swingRight)
// === LIQUIDITY SWEEPS ===
sweepHigh = not na(relevantHigh) and high > relevantHigh and close < relevantHigh
sweepLow = not na(relevantLow) and low < relevantLow and close > relevantLow
// === DISPLACEMENT CANDLES ===
bodySize = math.abs(close - open)
candleRange = high - low
avgRange = ta.sma(candleRange, 10)
displacementUp = close > open and bodySize > candleRange*0.6 and candleRange > avgRange
displacementDown = open > close and bodySize > candleRange*0.6 and candleRange > avgRange
// === SETUP ===
bullishSetup = sweepLow and displacementUp
bearishSetup = sweepHigh and displacementDown
plotshape(bullishSetup, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(bearishSetup, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// === FVG ===
bullishFVG = low > high
bearishFVG = high < low
if bullishFVG
box.new(left=bar_index-2, right=bar_index, top=low , bottom=high , bgcolor=color.new(color.green,85))
if bearishFVG
box.new(left=bar_index-2, right=bar_index, top=high , bottom=low , bgcolor=color.new(color.red,85))
// === BACKGROUND ===
bgcolor(structure=="bullish" ? color.new(color.green,80) : structure=="bearish" ? color.new(color.red,80) : na)
Higher Timeframe CandlesOverlay Higher Timeframe Candles on Lower Timeframes
Select any higher timeframe to overlay on your lower timeframe to easily see LTF market structure within HTF candles.
Please report any bugs or request improvements in the comments.
Confluence AutoEntry (1m/5m/15m) for Alertatron//@version=5
indicator("Confluence AutoEntry (1m/5m/15m) for Alertatron", overlay=true, max_lines_count=500, max_labels_count=500)
// =========================
// 参数
// =========================
tf1 = input.timeframe("1", "周期-1")
tf2 = input.timeframe("5", "周期-2")
tf3 = input.timeframe("15", "周期-3")
ema1 = input.int(10, "EMA1")
ema2 = input.int(30, "EMA2")
ema3 = input.int(60, "EMA3")
rLen = input.int(14, "RSI 长度")
thr1 = input.int(60, "阈值-周期1 (0~100)", minval=0, maxval=100)
thr2 = input.int(60, "阈值-周期2 (0~100)", minval=0, maxval=100)
thr3 = input.int(60, "阈值-周期3 (0~100)", minval=0, maxval=100)
// 下单资金(USDT)
usdtPerTrade = input.float(500, "每次下单金额(USDT)", step=5)
// 下单类型(市价/限价)
orderType = input.string("market", "下单类型", options= , tooltip="market=市价;limit=限价(使用 entry 作为限价)")
// 两步延续触发
useTwoStep = input.bool(true, "启用两步延续触发", tooltip="收盘仅“武装”,下一根或后续“延续突破”才真正发单;关闭=收盘即发一次信号")
bufferPct = input.float(0.08, "延续触发缓冲(%)", step=0.01, tooltip="突破需要超过武装价的百分比")
armBars = input.int(1, "武装有效bar数", minval=1, tooltip="超时未触发则自动取消武装")
// 可选:在 JSON 中附带 token
attachToken = input.bool(false, "在 JSON 中附带 token 字段")
longToken = input.string("", "多头 token(可留空)")
shortToken = input.string("", "空头 token(可留空)")
// 图形显示
showShapes = input.bool(true, "图表显示三角/武装/触发标记")
showTriggerLabel = input.bool(true, "触发时显示【入场/TP/SL/Qty】标签")
// 「平衡」展示用 TP/SL 百分比(仅用于标签展示,不发到 Alertatron)
tpPct = input.float(2.0, "展示用:TP百分比(%)")
slPct = input.float(1.0, "展示用:SL百分比(%)")
// =========================
// 工具函数
// =========================
f_score(tf) =>
_c = request.security(syminfo.tickerid, tf, close, barmerge.gaps_off, barmerge.lookahead_off)
_e1 = request.security(syminfo.tickerid, tf, ta.ema(close, ema1), barmerge.gaps_off, barmerge.lookahead_off)
_e2 = request.security(syminfo.tickerid, tf, ta.ema(close, ema2), barmerge.gaps_off, barmerge.lookahead_off)
_e3 = request.security(syminfo.tickerid, tf, ta.ema(close, ema3), barmerge.gaps_off, barmerge.lookahead_off)
_r = request.security(syminfo.tickerid, tf, ta.rsi(close, rLen), barmerge.gaps_off, barmerge.lookahead_off)
_m = request.security(syminfo.tickerid, tf, ta.sma(ta.change(close), 5), barmerge.gaps_off, barmerge.lookahead_off)
_ok1 = _c > _e1 ? 1 : 0
_ok2 = _e1 >= _e2 ? 1 : 0
_ok3 = _e2 >= _e3 ? 1 : 0
_ok4 = _r > 50 ? 1 : 0
_ok5 = _m >= 0 ? 1 : 0
(_ok1 + _ok2 + _ok3 + _ok4 + _ok5) / 5.0 * 100.0
// 价格按最小跳动取整
tickRound(x) =>
syminfo.mintick > 0 ? math.round(x / syminfo.mintick) * syminfo.mintick : x
// 数字 -> 价格串
sPrice(x) =>
str.tostring(x, format.mintick)
// 小数点四舍五入(用于数量展示)
roundN(x, n) =>
_f = math.pow(10.0, n)
math.round(x * _f) / _f
sQty(x) =>
str.tostring(roundN(x, 6))
// 去掉交易所前缀和 .P 后缀,得到 BASEQUOTE(如 ETHUSDC)
cleanSymbol() =>
_s = syminfo.ticker
_arr = str.split(_s, ":")
_last = array.get(_arr, array.size(_arr) - 1)
str.replace_all(_last, ".P", "")
// =========================
// 多周期评分 -> 一致方向
// =========================
score1 = f_score(tf1)
score2 = f_score(tf2)
score3 = f_score(tf3)
dir1 = score1 >= thr1 ? 1 : -1
dir2 = score2 >= thr2 ? 1 : -1
dir3 = score3 >= thr3 ? 1 : -1
conf_long = dir1 == 1 and dir2 == 1 and dir3 == 1
conf_short = dir1 == -1 and dir2 == -1 and dir3 == -1
// =========================
// 两步法:收盘“武装” + 下一根/后续“延续触发”
// =========================
var bool armLong = false
var float armLongPx = na
var int armLongUntil = na
var bool armShort = false
var float armShortPx = na
var int armShortUntil = na
if barstate.isconfirmed
if conf_long
armLong := true
armLongPx := close
armLongUntil := bar_index + armBars
if conf_short
armShort := true
armShortPx := close
armShortUntil := bar_index + armBars
longTrigPrice = armLong ? armLongPx * (1 + bufferPct/100.0) : na
shortTrigPrice = armShort ? armShortPx * (1 - bufferPct/100.0) : na
triggerLong = useTwoStep ? (armLong and high >= longTrigPrice) : (barstate.isconfirmed and conf_long)
triggerShort = useTwoStep ? (armShort and low <= shortTrigPrice) : (barstate.isconfirmed and conf_short)
// 触发后立刻卸载武装;超时未触发亦卸载
if triggerLong
armLong := false
if triggerShort
armShort := false
if bar_index > armLongUntil
armLong := false
if bar_index > armShortUntil
armShort := false
// =========================
// 发单用价位(在触发时会被使用)
// =========================
float entryL = tickRound(useTwoStep ? longTrigPrice : close)
float entryS = tickRound(useTwoStep ? shortTrigPrice : close)
float tpL = tickRound(entryL * (1 + tpPct/100.0))
float slL = tickRound(entryL * (1 - slPct/100.0))
float tpS = tickRound(entryS * (1 - tpPct/100.0))
float slS = tickRound(entryS * (1 + slPct/100.0))
// —— 展示标签直接使用上面算好的 entryL/entryS/tpL/slL/tpS/slS
if showTriggerLabel and barstate.isconfirmed
if triggerLong
_txt = "LONG Entry: " + sPrice(entryL) + " TP: " + sPrice(tpL) + " SL: " + sPrice(slL) + " EstQty: " + sQty(usdtPerTrade/entryL)
label.new(bar_index, low, text=_txt, style=label.style_label_up, textcolor=color.white, color=color.new(color.lime, 0))
if triggerShort
_txt = "SHORT Entry: " + sPrice(entryS) + " TP: " + sPrice(tpS) + " SL: " + sPrice(slS) + " EstQty: " + sQty(usdtPerTrade/entryS)
label.new(bar_index, high, text=_txt, style=label.style_label_down, textcolor=color.white, color=color.new(color.red, 0))
// ============ 构造 JSON(按方向用不同 signal 名,所有数值写入) ============
buildMsg(_side, _entry, _tp, _sl) =>
_sig = _side == "buy" ? "open_long" : "open_short"
_token = attachToken ? ',"token":"' + (_side == "buy" ? longToken : shortToken) + '"' : ""
_msg = '{"signal":"' + _sig + '"'
_msg := _msg + ',"side":"' + _side + '"'
_msg := _msg + ',"symbol":"' + cleanSymbol() + '"'
_msg := _msg + ',"order_type":"market"'
_msg := _msg + ',"usdt_per_trade":' + str.tostring(usdtPerTrade)
_msg := _msg + ',"entry":' + sPrice(_entry)
_msg := _msg + ',"tp":' + sPrice(_tp)
_msg := _msg + ',"sl":' + sPrice(_sl)
_msg := _msg + _token + "}"
_msg
msgLong = buildMsg("buy", entryL, tpL, slL)
msgShort = buildMsg("sell", entryS, tpS, slS)
// =========================
// 报警 & 发单(在 TradingView 里选择 Any alert() function call;Webhook 填机器人 URL;Message 留空)
// =========================
alertcondition(triggerLong, title="多仓开仓(…)", message="LONG")
alertcondition(triggerShort, title="空仓开仓(…)", message="SHORT")
if barstate.isconfirmed
if triggerLong
alert(message = msgLong, freq = alert.freq_once_per_bar_close)
if triggerShort
alert(message = msgShort, freq = alert.freq_once_per_bar_close)
// =========================
// 可视化:形态+触发线
// =========================
plotshape(showShapes and conf_long and barstate.isconfirmed, title="收盘-多武装", style=shape.triangleup, color=color.new(color.green, 0), size=size.tiny, text="ARM L", location=location.belowbar)
plotshape(showShapes and conf_short and barstate.isconfirmed, title="收盘-空武装", style=shape.triangledown, color=color.new(color.red, 0), size=size.tiny, text="ARM S", location=location.abovebar)
plotshape(showShapes and triggerLong, title="触发-开多", style=shape.labelup, color=color.new(color.lime, 0), text="▶ LONG", location=location.belowbar, size=size.tiny)
plotshape(showShapes and triggerShort, title="触发-开空", style=shape.labeldown, color=color.new(color.maroon,0), text="▶ SHORT", location=location.abovebar, size=size.tiny)
plot(useTwoStep and armLong ? armLongPx : na, "武装价-L", color=color.new(color.green, 70), style=plot.style_circles, linewidth=1)
plot(useTwoStep and armShort ? armShortPx : na, "武装价-S", color=color.new(color.red, 70), style=plot.style_circles, linewidth=1)
plot(useTwoStep ? longTrigPrice : na, "触发线-L", color=color.new(color.lime, 0), style=plot.style_linebr, linewidth=1)
plot(useTwoStep ? shortTrigPrice : na, "触发线-S", color=color.new(color.maroon, 0), style=plot.style_linebr, linewidth=1)
// =========================
// 可视化:触发时弹出【入场/TP/SL/Qty】标签(仅展示用)
// =========================
if showTriggerLabel and barstate.isconfirmed
if triggerLong
_qtyL = usdtPerTrade > 0 and entryL > 0 ? (usdtPerTrade / entryL) : na
_txtL = "LONG Entry: " + sPrice(entryL) + " TP: " + sPrice(tpL) + " SL: " + sPrice(slL) + " EstQty: " + sQty(_qtyL)
label.new(bar_index, low, text=_txtL, style=label.style_label_up, textcolor=color.white, color=color.new(color.lime, 0))
if triggerShort
_qtyS = usdtPerTrade > 0 and entryS > 0 ? (usdtPerTrade / entryS) : na
_txtS = "SHORT Entry: " + sPrice(entryS) + " TP: " + sPrice(tpS) + " SL: " + sPrice(slS) + " EstQty: " + sQty(_qtyS)
label.new(bar_index, high, text=_txtS, style=label.style_label_down, textcolor=color.white, color=color.new(color.red, 0))
Smart Money Concept: FVG Block Filter Smart Money Concept: FVG Block Filter (FVG Block Range vs N Range) with Candle Highlighter
Summary:
Smart Money Concept (SMC): An advanced indicator designed to visualize and filter Fair Value Gaps (FVG) blocks based on their size (Range) compared to the preceding N Range candle movement. It also includes a customizable Candle Highlighter function that marks the specific candle responsible for creating the FVG. The indicator allows full color customization for both blocks and the highlighter, and features clean, label-free charts by default.
Key Features:
FVG Block Detection: Automatically identifies and groups sequential FVG imbalances to form consolidated FVG blocks.
FVG Block Filtering (N Range): Filters blocks based on a user-defined rule, comparing the block's size (Range) to the range of the preceding N candles (e.g., requiring the FVG block to be larger than the range of the previous 6 candles).
Customizable Candle Highlighter: Marks the central candle (B) within the FVG structure (A-B-C) to highlight the source of the price imbalance. Highlighter colors are fully adjustable via inputs.
Visualization Control: Labels are turned OFF by default to keep the chart clean but can be easily enabled via the indicator settings.
Full Color Customization: Allows independent customization of Bullish and Bearish FVG Block colors, Block Transparency, and Bullish/Bearish Highlighter colors.
Keywords:
Smart Money Concept, SMC, Fair Value Gap, FVG, Imbalance, Block Filter, Candle Highlighter, Range.
Basic FVG Indicator by nacho-fx mod by evseevd2803Basic FVG Indicator by nacho-fx ( www.tradingview.com )
-Extends unfilled FVG boxes.
-Stops extending filled FVG boxes instead of removing them.
Liquidity Sweeps & Swings (SMC/ICT)Liquidity Sweeps & Swings (SMC/ICT) — TradingATH
Precision. Clarity. Structure.
This refined indicator automatically detects and displays Liquidity Sweeps and Liquidity Swings , highlighting the precise points where liquidity is taken and where structure shifts occur within price action.
Designed for traders applying Smart Money Concepts (SMC/ICT) , it offers a clear, data-driven visualization of market dynamics — providing structural context with professional accuracy and visual balance.
What You’ll See
Liquidity Sweeps represented as compact shaded zones, green for bullish sweeps and red for bearish ones, fading automatically once mitigated.
Liquidity Swings precisely labeled “ Swing High ” and “ Swing Low ” at major pivot points, cleanly positioned within structure.
Controlled-length zones that extend for a defined number of bars or dynamically until mitigation.
Optional real-time alerts when a new sweep forms or price re-enters an active zone.
Features
Sweep Detection Logic : Identifies liquidity grabs using Wick, Close, or Wick + Close validation for flexible precision across different market conditions.
Smart Mitigation : Zones dynamically fade or are removed once price mitigates the area, keeping your chart clean and relevant.
Swing Mapping : Highlights key pivot points to outline market structure shifts with precise and minimal labeling.
ATR Filtering : Optional volatility-based filter removes minor or insignificant sweeps to maintain clarity.
Elegant Design : Subtle colors, refined typography, and balanced spacing ensure a professional, unobtrusive presentation.
Alerts and Updates : Automated alerts for new sweep formations and live interaction with active zones.
Professional Architecture : Efficient execution, size-safe arrays, and optimized plotting for smooth performance on any timeframe.
ICT/SMC Ready : Fully compatible with advanced institutional concepts such as Fair Value Gaps, Order Blocks, and Market Structure Shifts.
Perfect For
Traders applying ICT or Smart Money Concepts methodologies to identify liquidity grabs and structural intent.
Intraday Traders seeking precise, uncluttered sweep and swing identification on volatile charts.
Swing Traders filtering high-probability setups based on liquidity structure and mitigation behavior.
Analysts requiring clarity, reliability, and technical precision in their liquidity mapping tools.
Recommended Settings
Pivot Lookback : 14 (balanced structural sensitivity).
Sweep Validation : Wick + Close (adaptive precision).
Zone Length : 150 bars (controlled visual reach).
ATR Filter : Minimum 0.25×, Maximum 3× (clean sweep selection).
Swing Labels : Enabled (for structural clarity).
In Short
Clean logic. Institutional precision. Professional clarity.
Liquidity Sweeps & Swings (SMC/ICT) delivers a disciplined and refined visualization of liquidity flow and structural shifts — crafted for traders who demand both analytical accuracy and visual sophistication.
Created by: TradingATH






















