本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Daily Scalper Ultra", shorttitle="DS Ultra", overlay=true, max_labels_count=500, max_lines_count=500)
// ═════════════════════════════════════════════════════════════
// DAILY SCALPER ULTRA = Daily Scalper + Ultra Scalper Pro
//
// Module 1 – Daily Scalper
// Kalman-adapted Supertrend (BUY / SELL), VWMA overbought /
// oversold zones, "R" reversal labels, TP markers
//
// Module 2 – Ultra Scalper Pro
// ZLSMA + Chandelier Exit entries, optional confirmation
// filters (RSI, Volume, EMA, SuperTrend, MACD, Stochastic,
// Session), 4-mode TP1/TP2/TP3 + SL system, info table
// ═════════════════════════════════════════════════════════════
// ── Inputs: modules ──────────────────────────────────────────
var string GM = "Modules"
enDaily = input.bool(true, "Enable Daily Scalper module", group=GM)
enUltra = input.bool(true, "Enable Ultra Scalper Pro module", group=GM)
// ── Inputs: Daily Scalper ────────────────────────────────────
var string D1 = "Daily | Kalman Filter"
procNoise = input.float(0.01, "Process Noise (Q)", minval=0.0001, step=0.005, group=D1, tooltip="Higher = filter follows price faster (less smoothing).")
measNoise = input.float(1.0, "Measurement Noise (R)", minval=0.0001, step=0.1, group=D1, tooltip="Higher = smoother output, more lag.")
var string D2 = "Daily | Supertrend"
atrLen = input.int(10, "ATR Length", minval=1, group=D2)
stMult = input.float(2.5, "ATR Factor", minval=0.1, step=0.1, group=D2)
var string D3 = "Daily | VWMA Overbought / Oversold Zones"
vwLen = input.int(20, "VWMA / Lookback Length", minval=2, group=D3)
obMult = input.float(0.35, "Upper Zone Thickness (x range)", minval=0.05, step=0.05, group=D3)
osMult = input.float(0.35, "Lower Zone Thickness (x range)", minval=0.05, step=0.05, group=D3)
showZones = input.bool(true, "Show Zones", group=D3)
var string D4 = "Daily | Reversal (R) Labels"
showR = input.bool(true, "Show R Labels", group=D4)
rCooldown = input.int(5, "Min Bars Between R Labels", minval=0, group=D4)
var string D5 = "Daily | Take Profit Markers"
showDTP = input.bool(true, "Show TP Markers", group=D5)
dTpMult = input.float(1.5, "TP Distance (x ATR)", minval=0.1, step=0.1, group=D5)
var string D6 = "Daily | Style"
buyCol = input.color(#00b300, "Buy Color", group=D6)
sellCol = input.color(#b30000, "Sell Color", group=D6)
// ── Inputs: Ultra | General ──────────────────────────────────
var string U0 = "Ultra | General"
showEntry = input.bool(true, "Show Entry Signals (triangles)", group=U0)
showLevels = input.bool(true, "Show TP/SL Lines", group=U0)
showLabels = input.bool(true, "Show TP/SL Price Labels", group=U0)
bgMode = input.string("Trend", "Background Color", options=["Off", "Trend", "Position"], group=U0)
enLong = input.bool(true, "Enable Long Signals", group=U0)
enShort = input.bool(true, "Enable Short Signals", group=U0)
var string U1 = "Ultra | ZLSMA"
zlLen = input.int(32, "ZLSMA Length", minval=2, group=U1, tooltip="Lower = more responsive, higher = smoother.")
zlOff = input.int(0, "ZLSMA Offset", group=U1)
showZL = input.bool(true, "Show ZLSMA Line", group=U1)
var string U2 = "Ultra | Chandelier Exit"
ceLen = input.int(22, "ATR Period", minval=1, group=U2)
ceMult = input.float(3.0, "ATR Multiplier", minval=0.1, step=0.1, group=U2, tooltip="Distance from high/low. Higher = wider stops.")
showCE = input.bool(true, "Show Chandelier Stops", group=U2)
var string U3 = "Ultra | Filters"
useRSI = input.bool(true, "RSI Filter", group=U3)
rsiLen = input.int(14, " RSI Period", minval=1, group=U3)
rsiOB = input.int(70, " Overbought (no longs above)", group=U3)
rsiOS = input.int(30, " Oversold (no shorts below)", group=U3)
useVol = input.bool(true, "Volume Filter", group=U3)
volLen = input.int(20, " Volume MA Period", minval=1, group=U3)
volMult = input.float(1.0, " Volume Multiplier", minval=0.1, step=0.1, group=U3)
useEMA = input.bool(true, "EMA Crossover Filter", group=U3)
emaFast = input.int(9, " Fast EMA", minval=1, group=U3)
emaSlow = input.int(21, " Slow EMA", minval=1, group=U3)
useST = input.bool(false, "SuperTrend Filter", group=U3)
ultStLen = input.int(10, " ATR Period", minval=1, group=U3)
ultStMul = input.float(3.0, " Factor", minval=0.1, step=0.1, group=U3)
useMACD = input.bool(false, "MACD Filter", group=U3)
macdFast = input.int(12, " Fast", minval=1, group=U3)
macdSlow = input.int(26, " Slow", minval=1, group=U3)
macdSig = input.int(9, " Signal", minval=1, group=U3)
useStoch = input.bool(false, "Stochastic Filter", group=U3)
stochLen = input.int(14, " %K Length", minval=1, group=U3)
stochSm = input.int(3, " %K Smoothing", minval=1, group=U3)
stochDSm = input.int(3, " %D Smoothing", minval=1, group=U3)
useKalST = input.bool(false, "Daily Scalper Trend Filter (Kalman Supertrend must agree)", group=U3)
var string U4 = "Ultra | Session Filter"
useSess = input.bool(false, "Enable Session Filter", group=U4)
sessTz = input.string("UTC", "Session Timezone", group=U4)
useAsia = input.bool(true, "Asia", inline="a", group=U4)
asiaSess = input.session("0000-0800", "", inline="a", group=U4)
useEU = input.bool(true, "Europe", inline="e", group=U4)
euSess = input.session("0700-1600", "", inline="e", group=U4)
useUS = input.bool(true, "US", inline="u", group=U4)
usSess = input.session("1300-2200", "", inline="u", group=U4)
var string U5 = "Ultra | Signal Strength"
strongWin = input.int(2, "Strong Signal Window (bars)", minval=0, group=U5, tooltip="ZLSMA cross and Chandelier flip must both occur within this many bars, with high volume, for a Strong (large) triangle.")
var string U6 = "Ultra | TP / SL"
tpMode = input.string("ATR Based", "TP/SL Mode", options=["ATR Based", "Fixed %", "R:R Ratio", "Chandelier Based"], group=U6)
tpAtrLen = input.int(14, "ATR Period (TP/SL)", minval=1, group=U6)
slAtr = input.float(1.5, "ATR: SL Multiplier", minval=0.1, step=0.1, group=U6)
tp1Atr = input.float(1.0, "ATR: TP1 Multiplier", minval=0.1, step=0.1, group=U6)
tp2Atr = input.float(2.0, "ATR: TP2 Multiplier", minval=0.1, step=0.1, group=U6)
tp3Atr = input.float(3.0, "ATR: TP3 Multiplier", minval=0.1, step=0.1, group=U6)
slPct = input.float(1.0, "Fixed %: SL", minval=0.01, step=0.1, group=U6)
tp1Pct = input.float(0.5, "Fixed %: TP1", minval=0.01, step=0.1, group=U6)
tp2Pct = input.float(1.0, "Fixed %: TP2", minval=0.01, step=0.1, group=U6)
tp3Pct = input.float(1.5, "Fixed %: TP3", minval=0.01, step=0.1, group=U6)
rr1 = input.float(1.0, "R:R / Chandelier: TP1 (x risk)", minval=0.1, step=0.1, group=U6)
rr2 = input.float(2.0, "R:R / Chandelier: TP2 (x risk)", minval=0.1, step=0.1, group=U6)
rr3 = input.float(3.0, "R:R / Chandelier: TP3 (x risk)", minval=0.1, step=0.1, group=U6)
exitOnCE = input.bool(true, "Close position on opposite Chandelier flip", group=U6)
lblOff = input.int(3, "Label Offset (bars)", minval=0, group=U6)
var string U7 = "Ultra | Info Table"
showTbl = input.bool(true, "Show Info Table", group=U7)
tblPosS = input.string("Top Right", "Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left", "Middle Right", "Middle Left"], group=U7)
tblSize = input.string(size.small, "Size", options=[size.tiny, size.small, size.normal], group=U7)
// ═════════════════════════════════════════════════════════════
// MODULE 1 – DAILY SCALPER
// ═════════════════════════════════════════════════════════════
kalman(float src, float q, float r) =>
var float x = na
var float p = 1.0
x := na(x) ? src : x
float pPred = p + q
float k = pPred / (pPred + r)
x := x + k * (src - x)
p := (1.0 - k) * pPred
x
kH = kalman(high, procNoise, measNoise)
kL = kalman(low, procNoise, measNoise)
kC = kalman(close, procNoise, measNoise)
kSrc = (kH + kL) / 2.0
float kTR = math.max(kH - kL, math.max(math.abs(kH - nz(kC[1], kC)), math.abs(kL - nz(kC[1], kC))))
float kATR = ta.rma(kTR, atrLen)
float upBand = kSrc - stMult * kATR
float dnBand = kSrc + stMult * kATR
float finalUp = na
float finalDn = na
float prevUp = nz(finalUp[1], upBand)
float prevDn = nz(finalDn[1], dnBand)
finalUp := nz(kC[1], kC) > prevUp ? math.max(upBand, prevUp) : upBand
finalDn := nz(kC[1], kC) < prevDn ? math.min(dnBand, prevDn) : dnBand
var int dir = 1
dir := kC > prevDn ? 1 : kC < prevUp ? -1 : dir
bool buySig = enDaily and dir == 1 and dir[1] == -1
bool sellSig = enDaily and dir == -1 and dir[1] == 1
// VWMA zones
float hh = ta.highest(high, vwLen)
float ll = ta.lowest(low, vwLen)
float vwHigh = ta.vwma(hh, vwLen)
float vwLow = ta.vwma(ll, vwLen)
float rng = vwHigh - vwLow
float obOuter = vwHigh
float obInner = vwHigh - rng * obMult
float osOuter = vwLow
float osInner = vwLow + rng * osMult
// Reversal (R)
bool kalTurnDown = kC < kC[1] and kC[1] >= kC[2]
bool kalTurnUp = kC > kC[1] and kC[1] <= kC[2]
bool rawRevDown = high >= obInner and close < open and kalTurnDown
bool rawRevUp = low <= osInner and close > open and kalTurnUp
var int lastR = -1000
bool revDown = enDaily and showR and rawRevDown and (bar_index - lastR > rCooldown)
bool revUp = enDaily and showR and rawRevUp and (bar_index - lastR > rCooldown)
if revDown or revUp
lastR := bar_index
// Daily TP markers
var float dTpPx = na
var int dSide = 0
bool dTpHit = false
if dSide == 1 and not na(dTpPx) and high >= dTpPx
dTpHit := true
dSide := 0
else if dSide == -1 and not na(dTpPx) and low <= dTpPx
dTpHit := true
dSide := 0
if buySig
dSide := 1
dTpPx := close + dTpMult * kATR
else if sellSig
dSide := -1
dTpPx := close - dTpMult * kATR
// ═════════════════════════════════════════════════════════════
// MODULE 2 – ULTRA SCALPER PRO
// ═════════════════════════════════════════════════════════════
float atrTP = ta.atr(tpAtrLen)
// ZLSMA
float lsma1 = ta.linreg(close, zlLen, zlOff)
float lsma2 = ta.linreg(lsma1, zlLen, zlOff)
float zlsma = 2.0 * lsma1 - lsma2
bool zlBull = close > zlsma
bool zlBear = close < zlsma
bool zlCrossUp = ta.crossover(close, zlsma)
bool zlCrossDn = ta.crossunder(close, zlsma)
// Chandelier Exit
float ceRange = ceMult * ta.atr(ceLen)
float ceLong = ta.highest(high, ceLen) - ceRange
float ceShort = ta.lowest(low, ceLen) + ceRange
float ceLongPrev = nz(ceLong[1], ceLong)
float ceShortPrev = nz(ceShort[1], ceShort)
ceLong := close[1] > ceLongPrev ? math.max(ceLong, ceLongPrev) : ceLong
ceShort := close[1] < ceShortPrev ? math.min(ceShort, ceShortPrev) : ceShort
var int ceDir = 1
ceDir := close > ceShortPrev ? 1 : close < ceLongPrev ? -1 : ceDir
bool ceBuy = ceDir == 1 and ceDir[1] == -1
bool ceSell = ceDir == -1 and ceDir[1] == 1
// Filters
float rsiV = ta.rsi(close, rsiLen)
float volMA = ta.sma(volume, volLen)
float emaF = ta.ema(close, emaFast)
float emaS = ta.ema(close, emaSlow)
[stLineU, stDirU] = ta.supertrend(ultStMul, ultStLen)
[macdL, macdS, macdH] = ta.macd(close, macdFast, macdSlow, macdSig)
float stochK = ta.sma(ta.stoch(close, high, low, stochLen), stochSm)
float stochD = ta.sma(stochK, stochDSm)
bool inAsia = not na(time(timeframe.period, asiaSess + ":1234567", sessTz))
bool inEU = not na(time(timeframe.period, euSess + ":1234567", sessTz))
bool inUS = not na(time(timeframe.period, usSess + ":1234567", sessTz))
bool sessAny = (useAsia and inAsia) or (useEU and inEU) or (useUS and inUS)
bool sessOk = not useSess or sessAny
bool volHigh = not na(volMA) and volume > volMA * volMult
bool volOk = not useVol or na(volMA) or volHigh
bool longOk = (not useRSI or rsiV < rsiOB) and volOk and (not useEMA or emaF > emaS) and (not useST or stDirU < 0) and (not useMACD or macdL > macdS) and (not useStoch or stochK > stochD) and (not useKalST or dir == 1) and sessOk
bool shortOk = (not useRSI or rsiV > rsiOS) and volOk and (not useEMA or emaF < emaS) and (not useST or stDirU > 0) and (not useMACD or macdL < macdS) and (not useStoch or stochK < stochD) and (not useKalST or dir == -1) and sessOk
bool rawLong = enUltra and enLong and zlBull and ceDir == 1 and longOk
bool rawShort = enUltra and enShort and zlBear and ceDir == -1 and shortOk
bool longSig = rawLong and not rawLong[1]
bool shortSig = rawShort and not rawShort[1]
int bsZlUp = ta.barssince(zlCrossUp)
int bsZlDn = ta.barssince(zlCrossDn)
int bsCeUp = ta.barssince(ceBuy)
int bsCeDn = ta.barssince(ceSell)
bool strongLCond = bsZlUp <= strongWin and bsCeUp <= strongWin and volHigh
bool strongSCond = bsZlDn <= strongWin and bsCeDn <= strongWin and volHigh
// TP/SL level calculation
f_levels(string mode, float entry, int side, float atrV, float ceStop) =>
float slD = atrV * slAtr
float d1 = atrV * tp1Atr
float d2 = atrV * tp2Atr
float d3 = atrV * tp3Atr
if mode == "Fixed %"
slD := entry * slPct / 100.0
d1 := entry * tp1Pct / 100.0
d2 := entry * tp2Pct / 100.0
d3 := entry * tp3Pct / 100.0
else if mode == "R:R Ratio"
d1 := slD * rr1
d2 := slD * rr2
d3 := slD * rr3
else if mode == "Chandelier Based"
slD := math.max(math.abs(entry - ceStop), atrV * 0.25)
d1 := slD * rr1
d2 := slD * rr2
d3 := slD * rr3
[entry - side * slD, entry + side * d1, entry + side * d2, entry + side * d3]
// Position state
var int pos = 0
var float entryPx = na
var float slPx = na
var float tp1Px = na
var float tp2Px = na
var float tp3Px = na
var bool t1Done = false
var bool t2Done = false
var bool t3Done = false
var line lnEntry = na
var line lnSL = na
var line lnTP1 = na
var line lnTP2 = na
var line lnTP3 = na
var label lbEntry = na
var label lbSL = na
var label lbTP1 = na
var label lbTP2 = na
var label lbTP3 = na
bool newLong = false
bool newShort = false
bool slNow = false
bool tp1Now = false
bool tp2Now = false
bool tp3Now = false
color cTP = color.new(#00c853, 0)
color cSL = color.new(#ff1744, 0)
// 1) extend active drawings to the current bar
if enUltra and pos != 0
if not na(lnSL)
line.set_x2(lnEntry, bar_index)
line.set_x2(lnSL, bar_index)
line.set_x2(lnTP1, bar_index)
line.set_x2(lnTP2, bar_index)
line.set_x2(lnTP3, bar_index)
if not na(lbSL)
label.set_x(lbEntry, bar_index + lblOff)
label.set_x(lbSL, bar_index + lblOff)
label.set_x(lbTP1, bar_index + lblOff)
label.set_x(lbTP2, bar_index + lblOff)
label.set_x(lbTP3, bar_index + lblOff)
// 2) manage open position (stop first, conservative)
if enUltra and pos != 0
bool hitSL = pos == 1 ? low <= slPx : high >= slPx
if hitSL
slNow := true
pos := 0
else
if not t1Done and (pos == 1 ? high >= tp1Px : low <= tp1Px)
t1Done := true
tp1Now := true
if not na(lbTP1)
label.set_color(lbTP1, color.new(cTP, 75))
if not t2Done and (pos == 1 ? high >= tp2Px : low <= tp2Px)
t2Done := true
tp2Now := true
if not na(lbTP2)
label.set_color(lbTP2, color.new(cTP, 75))
if not t3Done and (pos == 1 ? high >= tp3Px : low <= tp3Px)
t3Done := true
tp3Now := true
if not na(lbTP3)
label.set_color(lbTP3, color.new(cTP, 75))
pos := 0
if pos != 0 and exitOnCE and ((pos == 1 and ceSell) or (pos == -1 and ceBuy))
pos := 0
// 3) open a new position on a fresh signal
if enUltra and (longSig or shortSig) and ((longSig and pos != 1) or (shortSig and pos != -1))
int sd = longSig ? 1 : -1
[nSL, nTP1, nTP2, nTP3] = f_levels(tpMode, close, sd, atrTP, sd == 1 ? ceLong : ceShort)
pos := sd
newLong := sd == 1
newShort := sd == -1
entryPx := close
slPx := nSL
tp1Px := nTP1
tp2Px := nTP2
tp3Px := nTP3
t1Done := false
t2Done := false
t3Done := false
lnEntry := na
lnSL := na
lnTP1 := na
lnTP2 := na
lnTP3 := na
lbEntry := na
lbSL := na
lbTP1 := na
lbTP2 := na
lbTP3 := na
if showLevels
lnEntry := line.new(bar_index, entryPx, bar_index + 1, entryPx, color=color.new(color.yellow, 0), style=line.style_dotted)
lnSL := line.new(bar_index, slPx, bar_index + 1, slPx, color=cSL, style=line.style_solid)
lnTP1 := line.new(bar_index, tp1Px, bar_index + 1, tp1Px, color=cTP, style=line.style_solid)
lnTP2 := line.new(bar_index, tp2Px, bar_index + 1, tp2Px, color=cTP, style=line.style_solid)
lnTP3 := line.new(bar_index, tp3Px, bar_index + 1, tp3Px, color=cTP, style=line.style_solid)
if showLabels
lbEntry := label.new(bar_index + lblOff, entryPx, "ENTRY: " + str.tostring(entryPx, format.mintick), style=label.style_label_left, color=color.new(color.yellow, 10), textcolor=color.black, size=size.tiny)
lbSL := label.new(bar_index + lblOff, slPx, "SL: " + str.tostring(slPx, format.mintick), style=label.style_label_left, color=cSL, textcolor=color.white, size=size.tiny)
lbTP1 := label.new(bar_index + lblOff, tp1Px, "TP1: " + str.tostring(tp1Px, format.mintick), style=label.style_label_left, color=cTP, textcolor=color.white, size=size.tiny)
lbTP2 := label.new(bar_index + lblOff, tp2Px, "TP2: " + str.tostring(tp2Px, format.mintick), style=label.style_label_left, color=cTP, textcolor=color.white, size=size.tiny)
lbTP3 := label.new(bar_index + lblOff, tp3Px, "TP3: " + str.tostring(tp3Px, format.mintick), style=label.style_label_left, color=cTP, textcolor=color.white, size=size.tiny)
bool strongL = newLong and strongLCond
bool strongS = newShort and strongSCond
float pnlPct = pos != 0 ? (close - entryPx) / entryPx * 100.0 * pos : na
// ═════════════════════════════════════════════════════════════
// PLOTS
// ═════════════════════════════════════════════════════════════
// Daily Scalper
pObOuter = plot(enDaily and showZones ? obOuter : na, "OB Outer", color=color.new(sellCol, 100))
pObInner = plot(enDaily and showZones ? obInner : na, "OB Inner", color=color.new(sellCol, 100))
pOsOuter = plot(enDaily and showZones ? osOuter : na, "OS Outer", color=color.new(buyCol, 100))
pOsInner = plot(enDaily and showZones ? osInner : na, "OS Inner", color=color.new(buyCol, 100))
fill(pObOuter, pObInner, color=color.new(sellCol, 82), title="Overbought Zone")
fill(pOsOuter, pOsInner, color=color.new(buyCol, 82), title="Oversold Zone")
plotshape(buySig, "BUY", shape.labelup, location.belowbar, buyCol, textcolor=color.white, text="BUY", size=size.small)
plotshape(sellSig, "SELL", shape.labeldown, location.abovebar, sellCol, textcolor=color.white, text="SELL", size=size.small)
plotshape(revUp, "R Long", shape.labelup, location.belowbar, color.new(color.teal, 0), textcolor=color.white, text="R", size=size.tiny)
plotshape(revDown, "R Short", shape.labeldown, location.abovebar, color.new(color.orange, 0), textcolor=color.white, text="R", size=size.tiny)
plotshape(showDTP and dTpHit ? dTpPx : na, "Daily TP", shape.xcross, location.absolute, color.new(color.lime, 0), textcolor=color.white, text="TP", size=size.tiny)
bgcolor(showDTP and dTpHit ? color.new(color.green, 80) : na, title="Daily TP Highlight")
// Ultra Scalper Pro
plot(enUltra and showZL ? zlsma : na, "ZLSMA", color=zlsma >= nz(zlsma[1], zlsma) ? color.new(#00e676, 0) : color.new(#ff5252, 0), linewidth=2)
plot(enUltra and showCE and ceDir == 1 ? ceLong : na, "CE Long Stop", color=color.new(#00e676, 0), linewidth=2, style=plot.style_linebr)
plot(enUltra and showCE and ceDir == -1 ? ceShort : na, "CE Short Stop", color=color.new(#ff5252, 0), linewidth=2, style=plot.style_linebr)
plotshape(showEntry and newLong and not strongL, "Long", shape.triangleup, location.belowbar, color.new(#00e676, 0), size=size.small)
plotshape(showEntry and newShort and not strongS, "Short", shape.triangledown, location.abovebar, color.new(#ff5252, 0), size=size.small)
plotshape(showEntry and strongL, "Strong Long", shape.triangleup, location.belowbar, color.new(#00e676, 0), size=size.normal)
plotshape(showEntry and strongS, "Strong Short", shape.triangledown, location.abovebar, color.new(#ff5252, 0), size=size.normal)
plotshape(tp1Now ? tp1Px : na, "TP1 Hit", shape.xcross, location.absolute, color.new(#00e676, 0), textcolor=color.white, text="TP1", size=size.tiny)
plotshape(tp2Now ? tp2Px : na, "TP2 Hit", shape.xcross, location.absolute, color.new(#00e676, 0), textcolor=color.white, text="TP2", size=size.tiny)
plotshape(tp3Now ? tp3Px : na, "TP3 Hit", shape.xcross, location.absolute, color.new(#00e676, 0), textcolor=color.white, text="TP3", size=size.tiny)
plotshape(slNow ? slPx : na, "SL Hit", shape.xcross, location.absolute, color.new(#ff1744, 0), textcolor=color.white, text="SL", size=size.tiny)
color bgCol = na
if enUltra
if bgMode == "Trend"
bgCol := ceDir == 1 ? color.new(color.green, 92) : color.new(color.red, 92)
else if bgMode == "Position"
bgCol := pos == 1 ? color.new(color.green, 90) : pos == -1 ? color.new(color.red, 90) : na
bgcolor(bgCol, title="Ultra Background")
// ═════════════════════════════════════════════════════════════
// INFO TABLE
// ═════════════════════════════════════════════════════════════
var table tbl = table.new(
tblPosS == "Top Right" ? position.top_right : tblPosS == "Top Left" ? position.top_left : tblPosS == "Bottom Right" ? position.bottom_right : tblPosS == "Bottom Left" ? position.bottom_left : tblPosS == "Middle Right" ? position.middle_right : position.middle_left,
2, 16, bgcolor=color.new(#1e222d, 0), border_width=1, border_color=color.new(color.gray, 70))
cGreen = color.new(#00e676, 0)
cRed = color.new(#ff5252, 0)
f_row(int r, string name, string val, color vc) =>
table.cell(tbl, 0, r, name, text_color=color.new(color.gray, 0), text_size=tblSize, text_halign=text.align_left, bgcolor=color.new(#1e222d, 0))
table.cell(tbl, 1, r, val, text_color=vc, text_size=tblSize, text_halign=text.align_left, bgcolor=color.new(#1e222d, 0))
f_bb(bool on, bool bull) => not on ? "OFF" : bull ? "BULLISH" : "BEARISH"
f_bc(bool on, bool bull) => not on ? color.gray : bull ? cGreen : cRed
if showTbl and barstate.islast
table.cell(tbl, 0, 0, "INDICATOR", text_color=color.white, text_size=tblSize, text_halign=text.align_left, bgcolor=color.new(#2a2e39, 0))
table.cell(tbl, 1, 0, "STATUS", text_color=color.white, text_size=tblSize, text_halign=text.align_left, bgcolor=color.new(#2a2e39, 0))
f_row(1, "Daily ST", f_bb(enDaily, dir == 1), f_bc(enDaily, dir == 1))
f_row(2, "ZLSMA", f_bb(enUltra, zlBull), f_bc(enUltra, zlBull))
f_row(3, "Chandelier", ceDir == 1 ? "LONG" : "SHORT", ceDir == 1 ? cGreen : cRed)
bool rsiMid = rsiV < rsiOB and rsiV > rsiOS
f_row(4, "RSI", not useRSI ? "OFF" : str.tostring(rsiV, "0.0") + (rsiMid ? " OK" : rsiV >= rsiOB ? " OB" : " OS"), not useRSI ? color.gray : rsiMid ? cGreen : color.orange)
f_row(5, "Volume", not useVol ? "OFF" : volHigh ? "HIGH" : "LOW", not useVol ? color.gray : volHigh ? cGreen : color.orange)
f_row(6, "EMA Cross", f_bb(useEMA, emaF > emaS), f_bc(useEMA, emaF > emaS))
f_row(7, "SuperTrend", f_bb(useST, stDirU < 0), f_bc(useST, stDirU < 0))
f_row(8, "MACD", f_bb(useMACD, macdL > macdS), f_bc(useMACD, macdL > macdS))
f_row(9, "Stochastic", f_bb(useStoch, stochK > stochD), f_bc(useStoch, stochK > stochD))
f_row(10, "Session", not useSess ? "OFF" : sessAny ? "ACTIVE" : "CLOSED", not useSess ? color.gray : sessAny ? cGreen : color.orange)
f_row(11, "", "", color.gray)
f_row(12, "ATR", str.tostring(atrTP, "0.000"), color.white)
f_row(13, "Position", pos == 1 ? "LONG" : pos == -1 ? "SHORT" : "NONE", pos == 1 ? cGreen : pos == -1 ? cRed : color.gray)
f_row(14, "Entry", pos != 0 ? str.tostring(entryPx, format.mintick) : "-", color.white)
f_row(15, "P&L", pos != 0 ? str.tostring(pnlPct, "0.00") + "%" : "-", pos == 0 ? color.gray : pnlPct >= 0 ? cGreen : cRed)
// ═════════════════════════════════════════════════════════════
// ALERTS
// ═════════════════════════════════════════════════════════════
alertcondition(buySig, "DS: BUY", "Daily Scalper: BUY on {{ticker}} @ {{close}}")
alertcondition(sellSig, "DS: SELL", "Daily Scalper: SELL on {{ticker}} @ {{close}}")
alertcondition(revUp, "DS: R Long", "Daily Scalper: possible bullish reversal on {{ticker}} @ {{close}}")
alertcondition(revDown, "DS: R Short", "Daily Scalper: possible bearish reversal on {{ticker}} @ {{close}}")
alertcondition(dTpHit, "DS: TP", "Daily Scalper: TP reached on {{ticker}} @ {{close}}")
alertcondition(newLong, "Ultra: Long Signal", "Ultra Scalper: LONG on {{ticker}} @ {{close}}")
alertcondition(newShort, "Ultra: Short Signal", "Ultra Scalper: SHORT on {{ticker}} @ {{close}}")
alertcondition(strongL, "Ultra: Strong Long", "Ultra Scalper: STRONG LONG on {{ticker}} @ {{close}}")
alertcondition(strongS, "Ultra: Strong Short", "Ultra Scalper: STRONG SHORT on {{ticker}} @ {{close}}")
alertcondition(enUltra and ceBuy, "Ultra: CE Buy", "Chandelier Exit flipped bullish on {{ticker}} @ {{close}}")
alertcondition(enUltra and ceSell, "Ultra: CE Sell", "Chandelier Exit flipped bearish on {{ticker}} @ {{close}}")
alertcondition(enUltra and zlCrossUp, "Ultra: ZLSMA Bullish Cross", "Price crossed above ZLSMA on {{ticker}} @ {{close}}")
alertcondition(enUltra and zlCrossDn, "Ultra: ZLSMA Bearish Cross", "Price crossed below ZLSMA on {{ticker}} @ {{close}}")
alertcondition(newLong or newShort, "Ultra: Any Entry", "Ultra Scalper: entry signal on {{ticker}} @ {{close}}")
alertcondition(strongL or strongS, "Ultra: Any Strong", "Ultra Scalper: strong signal on {{ticker}} @ {{close}}")
alertcondition(tp1Now, "Ultra: TP1 Hit", "Ultra Scalper: TP1 hit on {{ticker}} @ {{close}}")
alertcondition(tp2Now, "Ultra: TP2 Hit", "Ultra Scalper: TP2 hit on {{ticker}} @ {{close}}")
alertcondition(tp3Now, "Ultra: TP3 Hit", "Ultra Scalper: TP3 hit on {{ticker}} @ {{close}}")
alertcondition(slNow, "Ultra: SL Hit", "Ultra Scalper: stop loss hit on {{ticker}} @ {{close}}")