TOLAG APEX V1.3 - Precision Edition

TOLAG · study · 720 行 · 点赞 425 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("OLA APEX V1.3 - Precision Visual Edition", shorttitle="OLA APEX V1.3", overlay=true, max_boxes_count=300, max_lines_count=300, max_labels_count=150)
 
// Copyright (c) TOLAG Indicators.
// V1.3: Presentation refinement of OLA APEX V1.2.
// Original trading logic, signal calculations, and alerts preserved.
 
//====================================================
// 01 | PREMIUM VISUALS
//====================================================
g1 = "01 | Premium Visuals"
 
mode = input.string("Premium", "Visual Detail", options=["Minimal", "Balanced", "Premium"], group=g1)
showRibbon = input.bool(true, "Adaptive Trend Ribbon", group=g1)
showZones = input.bool(true, "Liquidity Zones", group=g1)
showFVG = input.bool(true, "Fair Value Gaps", group=g1)
showStructure = input.bool(true, "Market Structure Lines", group=g1)
showSignals = input.bool(true, "Directional Signals", group=g1)
showEvents = input.bool(true, "Liquidity and Structure Markers", group=g1)
colorBars = input.bool(true, "Adaptive Candle Colors", group=g1)
 
bullCol = input.color(color.rgb(0, 225, 165), "Bullish Color", group=g1)
bearCol = input.color(color.rgb(255, 65, 105), "Bearish Color", group=g1)
neutralCol = input.color(color.rgb(113, 137, 160), "Neutral Color", group=g1)
liqCol = input.color(color.rgb(245, 185, 65), "Liquidity Color", group=g1)
 
//====================================================
// 02 | ADAPTIVE TREND RIBBON
//====================================================
g2 = "02 | Adaptive Trend Ribbon"
 
fastLen = input.int(13, "Fast Length", minval=2, group=g2)
midLen = input.int(34, "Medium Length", minval=3, group=g2)
slowLen = input.int(89, "Slow Length", minval=5, group=g2)
adapt = input.float(1.0, "Volatility Adaptation", minval=0.1, maxval=3, step=0.1, group=g2)
trendThreshold = input.float(0.10, "Trend Separation / ATR", minval=0, step=0.05, group=g2)
 
//====================================================
// 03 | STRUCTURE AND LIQUIDITY
//====================================================
g3 = "03 | Structure and Liquidity"
 
pivotLen = input.int(4, "Structure Pivot Strength", minval=1, maxval=30, group=g3)
minSweep = input.float(0.03, "Minimum Sweep / ATR", minval=0, step=0.01, group=g3)
maxSweep = input.float(2.5, "Maximum Sweep / ATR", minval=0.1, step=0.1, group=g3)
reclaimMin = input.float(0.12, "Minimum Reclaim Strength", minval=0, maxval=1, step=0.01, group=g3)
zoneExtend = input.int(12, "Liquidity Zone Extension", minval=1, maxval=100, group=g3)
structureHistory = input.int(45, "Maximum Structure Lines", minval=5, maxval=150, group=g3)
zoneHistory = input.int(35, "Maximum Liquidity Zones", minval=5, maxval=100, group=g3)
 
//====================================================
// 04 | FAIR VALUE GAPS
//====================================================
g4 = "04 | FVG Intelligence"
 
gapMinATR = input.float(0.10, "Minimum Gap / ATR", minval=0, step=0.05, group=g4)
bodyMinATR = input.float(0.35, "Minimum Displacement / ATR", minval=0, step=0.05, group=g4)
gapLife = input.int(60, "FVG Maximum Age", minval=5, maxval=300, group=g4)
maxGaps = input.int(25, "Maximum Active FVG", minval=2, maxval=80, group=g4)
removeFilled = input.bool(true, "Remove Fully Filled FVG", group=g4)
 
//====================================================
// 05 | SIGNAL INTELLIGENCE
//====================================================
g5 = "05 | Signal Intelligence"
 
scoreThreshold = input.int(65, "Minimum Signal Score", minval=20, maxval=100, group=g5)
rsiLen = input.int(14, "Momentum Length", minval=2, group=g5)
eventWindow = input.int(5, "Event Validity Bars", minval=0, maxval=30, group=g5)
cooldown = input.int(8, "Signal Cooldown Bars", minval=0, maxval=100, group=g5)
requireTrend = input.bool(true, "Require Trend Alignment", group=g5)
 
//====================================================
// 06 | ENHANCED DASHBOARD
//====================================================
g6 = "06 | Enhanced Dashboard"
 
dashOn = input.bool(true, "Show Dashboard", group=g6)
dashPos = input.string("Top Right", "Dashboard Position", options=["Top Right", "Top Left", "Middle Right", "Middle Left", "Bottom Right", "Bottom Left"], group=g6)
dashSize = input.string("Small", "Dashboard Size", options=["Tiny", "Small", "Normal", "Large"], group=g6)
dashLayout = input.string("Detailed", "Dashboard Layout", options=["Compact", "Detailed"], group=g6)
dashOpacity = input.int(8, "Dashboard Transparency", minval=0, maxval=90, group=g6)
 
//====================================================
// 07 | PRECISION VISUAL REFINEMENT
//====================================================
g7 = "07 | Precision Visual Refinement"
 
visualStyle = input.string("Refined", "Visual Style", options=["Original", "Refined", "Signature"], group=g7)
 
ribbonDepth = input.bool(true, "Ribbon Depth Effect", group=g7)
structureLabels = input.bool(true, "BOS / MSS Text on Lines", group=g7)
fadeOldStructure = input.bool(true, "Fade Historical Structure", group=g7)
fvgAccent = input.bool(true, "Refined FVG Borders", group=g7)
dashGlow = input.bool(true, "Dashboard Accent Border", group=g7)
 
structureLineWidth = input.int(2, "Structure Line Width", minval=1, maxval=4, group=g7)
structureFade = input.int(35, "Structure Transparency", minval=0, maxval=95, group=g7)
oldStructureFade = input.int(80, "Historical Structure Transparency", minval=50, maxval=95, group=g7)
 
zoneTransparency = input.int(88, "Liquidity Zone Transparency", minval=60, maxval=98, group=g7)
fvgTransparency = input.int(88, "FVG Transparency", minval=60, maxval=98, group=g7)
 
//====================================================
// 08 | SELECTIVE LIQUIDITY DISPLAY
//====================================================
g8 = "08 | Selective Liquidity Display"
 
liquidityMode = input.string("Qualified", "Visible Liquidity", options=["All Original", "Qualified", "Major Only"], group=g8)
 
maxVisibleLiquidity = input.int(3, "Maximum Visible Zones", minval=1, maxval=5, group=g8)
 
minProminenceATR = input.float(0.65, "Minimum Swing Prominence / ATR", minval=0.1, maxval=5, step=0.05, group=g8)
 
minQualifiedScore = input.float(55, "Qualified Liquidity Score", minval=0, maxval=100, step=5, group=g8)
 
minMajorScore = input.float(75, "Major Liquidity Score", minval=0, maxval=100, step=5, group=g8)
 
liquidityLife = input.int(80, "Visible Liquidity Maximum Age", minval=5, maxval=500, group=g8)
 
hideInvalidated = input.bool(true, "Hide Invalidated Visible Zones", group=g8)
 
//====================================================
// HELPERS
//====================================================
clamp(float x, float a, float b) =>
    math.max(a, math.min(b, x))
 
confirmed = barstate.isconfirmed
 
atr = ta.atr(14)
safeATR = math.max(nz(atr, syminfo.mintick), syminfo.mintick)
rng = math.max(high - low, syminfo.mintick)
rsi = ta.rsi(close, rsiLen)
 
originalVisual = visualStyle == "Original"
signatureVisual = visualStyle == "Signature"
premiumVisual = not originalVisual
 
//====================================================
// ORIGINAL ADAPTIVE RIBBON ENGINE
//====================================================
relativeVol = safeATR / math.max(math.abs(close), syminfo.mintick)
meanVol = ta.sma(relativeVol, 100)
ratio = na(meanVol) or meanVol <= 0 ? 1.0 : relativeVol / meanVol
factor = clamp(ratio * adapt, 0.5, 2.0)
 
aFast = math.min(1.0, 2.0 / (fastLen + 1.0) * factor)
aMid = math.min(1.0, 2.0 / (midLen + 1.0) * factor)
aSlow = math.min(1.0, 2.0 / (slowLen + 1.0) * factor)
 
var float fast = na
var float mid = na
var float slow = na
 
fast := na(fast[1]) ? close : fast[1] + aFast * (close - fast[1])
mid := na(mid[1]) ? close : mid[1] + aMid * (close - mid[1])
slow := na(slow[1]) ? close : slow[1] + aSlow * (close - slow[1])
 
bullAligned = fast > mid and mid > slow
bearAligned = fast < mid and mid < slow
 
separation = math.abs(fast - slow) / safeATR
 
bullTrend = bullAligned and separation >= trendThreshold
bearTrend = bearAligned and separation >= trendThreshold
 
trend = bullTrend ? 1 : bearTrend ? -1 : 0
tColor = trend == 1 ? bullCol : trend == -1 ? bearCol : neutralCol
 
//====================================================
// REFINED RIBBON PRESENTATION
//====================================================
pFast = plot(showRibbon ? fast : na, "Adaptive Fast", color=tColor, linewidth=2)
pMid = plot(showRibbon ? mid : na, "Adaptive Medium", color=color.new(tColor, 35), linewidth=1)
pSlow = plot(showRibbon ? slow : na, "Adaptive Slow", color=color.new(tColor, 65), linewidth=2)
 
fill(
     pFast, pMid,
     color=mode == "Minimal" ? na : color.new(tColor, originalVisual ? (mode == "Premium" ? 78 : 88) : (signatureVisual ? 73 : 82)),
     title="Inner Ribbon")
 
fill(
     pMid, pSlow,
     color=mode == "Premium" ? color.new(tColor, originalVisual ? 91 : 94) : na,
     title="Outer Ribbon")
 
ribbonCenter = (fast + mid) / 2.0
 
pCenter = plot(
     showRibbon and premiumVisual and ribbonDepth ? ribbonCenter : na,
     "Ribbon Light Core",
     color=color.new(tColor, 100))
 
fill(
     pFast, pCenter,
     color=showRibbon and premiumVisual and ribbonDepth ? color.new(tColor, signatureVisual ? 87 : 92) : na,
     title="Ribbon Depth")
 
barcolor(colorBars ? color.new(tColor, trend == 0 ? 55 : 12) : na)
 
//====================================================
// ORIGINAL CONFIRMED MARKET STRUCTURE
//====================================================
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
 
var float structureHigh = na
var float structureLow = na
 
var int highOrigin = na
var int lowOrigin = na
 
var bool highBroken = false
var bool lowBroken = false
var bool highSwept = false
var bool lowSwept = false
 
var int structureDirection = 0
 
// Presentation-only prominence values.
var float highProminence = 0.0
var float lowProminence = 0.0
 
if confirmed
    if not na(ph)
        structureHigh := ph
        highOrigin := bar_index - pivotLen
        highBroken := false
        highSwept := false
        highProminence := math.max(0, (ph - ta.lowest(low, pivotLen * 2 + 1)) / safeATR)
 
    if not na(pl)
        structureLow := pl
        lowOrigin := bar_index - pivotLen
        lowBroken := false
        lowSwept := false
        lowProminence := math.max(0, (ta.highest(high, pivotLen * 2 + 1) - pl) / safeATR)
 
bullBreak = confirmed and not na(structureHigh) and not highBroken and close > structureHigh
bearBreak = confirmed and not na(structureLow) and not lowBroken and close < structureLow
 
bullShift = bullBreak and structureDirection == -1
bearShift = bearBreak and structureDirection == 1
 
//====================================================
// PRECISION STRUCTURE PRESENTATION
//====================================================
var array<line> structureLines = array.new<line>()
var array<label> structureTags = array.new<label>()
var array<color> structureColors = array.new<color>()
 
if bullBreak
    highBroken := true
    structureDirection := 1
 
    if showStructure
        color c = premiumVisual ? color.new(bullCol, structureFade) : bullCol
 
        line l = line.new(
             highOrigin, structureHigh,
             bar_index, structureHigh,
             color=c,
             width=premiumVisual ? structureLineWidth : (bullShift ? 2 : 1),
             style=bullShift ? line.style_solid : line.style_dashed)
 
        array.push(structureLines, l)
        array.push(structureColors, bullCol)
 
        if premiumVisual and structureLabels
            int midBar = int(math.round((highOrigin + bar_index) / 2.0))
 
            label tag = label.new(
                 midBar, structureHigh,
                 bullShift ? "MSS" : "BOS",
                 style=label.style_none,
                 textcolor=color.new(bullCol, 5),
                 color=color.new(bullCol, 100),
                 size=size.tiny)
 
            array.push(structureTags, tag)
 
if bearBreak
    lowBroken := true
    structureDirection := -1
 
    if showStructure
        color c = premiumVisual ? color.new(bearCol, structureFade) : bearCol
 
        line l = line.new(
             lowOrigin, structureLow,
             bar_index, structureLow,
             color=c,
             width=premiumVisual ? structureLineWidth : (bearShift ? 2 : 1),
             style=bearShift ? line.style_solid : line.style_dashed)
 
        array.push(structureLines, l)
        array.push(structureColors, bearCol)
 
        if premiumVisual and structureLabels
            int midBar = int(math.round((lowOrigin + bar_index) / 2.0))
 
            label tag = label.new(
                 midBar, structureLow,
                 bearShift ? "MSS" : "BOS",
                 style=label.style_none,
                 textcolor=color.new(bearCol, 5),
                 color=color.new(bearCol, 100),
                 size=size.tiny)
 
            array.push(structureTags, tag)
 
// Fade older structure drawings without changing events.
if premiumVisual and fadeOldStructure and array.size(structureLines) > 0
    int total = array.size(structureLines)
    int recentCount = math.min(total, 6)
 
    for i = 0 to total - 1
        line l = array.get(structureLines, i)
        color base = array.get(structureColors, i)
 
        bool recent = i >= total - recentCount
 
        line.set_color(
             l,
             color.new(base, recent ? structureFade : oldStructureFade))
 
if array.size(structureLines) > structureHistory
    line.delete(array.shift(structureLines))
    array.shift(structureColors)
 
if array.size(structureTags) > structureHistory
    label.delete(array.shift(structureTags))
 
//====================================================
// ORIGINAL LIQUIDITY SWEEP ENGINE
//====================================================
bullDepth = not na(structureLow) ? (structureLow - low) / safeATR : 0.0
bearDepth = not na(structureHigh) ? (high - structureHigh) / safeATR : 0.0
 
bullReclaim = not na(structureLow) ? clamp((close - structureLow) / rng, 0, 1) : 0.0
bearReclaim = not na(structureHigh) ? clamp((structureHigh - close) / rng, 0, 1) : 0.0
 
bullSweepRaw = confirmed and not na(structureLow) and not lowBroken and not lowSwept and low < structureLow and close > structureLow
bearSweepRaw = confirmed and not na(structureHigh) and not highBroken and not highSwept and high > structureHigh and close < structureHigh
 
bullSweep = bullSweepRaw and not bearSweepRaw and bullDepth >= minSweep and bullDepth <= maxSweep and bullReclaim >= reclaimMin
bearSweep = bearSweepRaw and not bullSweepRaw and bearDepth >= minSweep and bearDepth <= maxSweep and bearReclaim >= reclaimMin
 
bullSweepQuality = bullSweep ? 100 * (0.4 * clamp(bullDepth / 0.8, 0, 1) + 0.6 * bullReclaim) : 0.0
bearSweepQuality = bearSweep ? 100 * (0.4 * clamp(bearDepth / 0.8, 0, 1) + 0.6 * bearReclaim) : 0.0
 
if bullSweep
    lowSwept := true
 
if bearSweep
    highSwept := true
 
//====================================================
// LIQUIDITY SIGNIFICANCE - DISPLAY ONLY
//====================================================
bullProminencePoints = 35.0 * clamp(lowProminence / math.max(minProminenceATR * 2, 0.1), 0, 1)
bearProminencePoints = 35.0 * clamp(highProminence / math.max(minProminenceATR * 2, 0.1), 0, 1)
 
bullReclaimPoints = 35.0 * bullReclaim
bearReclaimPoints = 35.0 * bearReclaim
 
bullDepthPoints = 20.0 * clamp(bullDepth / 0.8, 0, 1)
bearDepthPoints = 20.0 * clamp(bearDepth / 0.8, 0, 1)
 
bullContextPoints = structureDirection == 1 ? 10.0 : 0.0
bearContextPoints = structureDirection == -1 ? 10.0 : 0.0
 
bullLiquidityScore = clamp(bullProminencePoints + bullReclaimPoints + bullDepthPoints + bullContextPoints, 0, 100)
bearLiquidityScore = clamp(bearProminencePoints + bearReclaimPoints + bearDepthPoints + bearContextPoints, 0, 100)
 
bullQualified = bullSweep and lowProminence >= minProminenceATR and bullLiquidityScore >= minQualifiedScore
bearQualified = bearSweep and highProminence >= minProminenceATR and bearLiquidityScore >= minQualifiedScore
 
bullMajor = bullQualified and bullLiquidityScore >= minMajorScore
bearMajor = bearQualified and bearLiquidityScore >= minMajorScore
 
bullVisible = bullSweep and (
     liquidityMode == "All Original" or
     (liquidityMode == "Qualified" and bullQualified) or
     (liquidityMode == "Major Only" and bullMajor))
 
bearVisible = bearSweep and (
     liquidityMode == "All Original" or
     (liquidityMode == "Qualified" and bearQualified) or
     (liquidityMode == "Major Only" and bearMajor))
 
//====================================================
// SELECTIVE LIQUIDITY ZONES
//====================================================
var array<box> liquidityZones = array.new<box>()
var array<float> liquidityScores = array.new<float>()
var array<int> liquidityDirections = array.new<int>()
var array<int> liquidityBirths = array.new<int>()
var array<float> liquidityBounds = array.new<float>()
 
if confirmed and array.size(liquidityZones) > 0
    for i = array.size(liquidityZones) - 1 to 0
        box b = array.get(liquidityZones, i)
        int direction = array.get(liquidityDirections, i)
        int birth = array.get(liquidityBirths, i)
        float bound = array.get(liquidityBounds, i)
 
        bool expired = premiumVisual and bar_index - birth > liquidityLife
 
        bool invalidated = premiumVisual and hideInvalidated and bar_index > birth and (
             direction == 1 ? close < bound : close > bound)
 
        if expired or invalidated
            box.delete(b)
            array.remove(liquidityZones, i)
            array.remove(liquidityScores, i)
            array.remove(liquidityDirections, i)
            array.remove(liquidityBirths, i)
            array.remove(liquidityBounds, i)
 
if showZones and bullVisible
    color c = bullMajor ? bullCol : color.new(bullCol, 20)
 
    box b = box.new(
         bar_index - 1, structureLow,
         bar_index + zoneExtend, low,
         bgcolor=color.new(c, originalVisual ? 86 : zoneTransparency),
         border_color=color.new(c, originalVisual ? 20 : 48),
         border_width=bullMajor and premiumVisual ? 2 : 1)
 
    array.push(liquidityZones, b)
    array.push(liquidityScores, bullLiquidityScore)
    array.push(liquidityDirections, 1)
    array.push(liquidityBirths, bar_index)
    array.push(liquidityBounds, low)
 
if showZones and bearVisible
    color c = bearMajor ? bearCol : color.new(bearCol, 20)
 
    box b = box.new(
         bar_index - 1, high,
         bar_index + zoneExtend, structureHigh,
         bgcolor=color.new(c, originalVisual ? 86 : zoneTransparency),
         border_color=color.new(c, originalVisual ? 20 : 48),
         border_width=bearMajor and premiumVisual ? 2 : 1)
 
    array.push(liquidityZones, b)
    array.push(liquidityScores, bearLiquidityScore)
    array.push(liquidityDirections, -1)
    array.push(liquidityBirths, bar_index)
    array.push(liquidityBounds, high)
 
int liquidityLimit = originalVisual and liquidityMode == "All Original" ? zoneHistory : maxVisibleLiquidity
 
while array.size(liquidityZones) > liquidityLimit
    int removeIndex = 0
 
    if liquidityLimit != zoneHistory
        float lowestScore = array.get(liquidityScores, 0)
 
        for j = 1 to array.size(liquidityZones) - 1
            float candidate = array.get(liquidityScores, j)
 
            if candidate < lowestScore
                lowestScore := candidate
                removeIndex := j
 
    box.delete(array.remove(liquidityZones, removeIndex))
    array.remove(liquidityScores, removeIndex)
    array.remove(liquidityDirections, removeIndex)
    array.remove(liquidityBirths, removeIndex)
    array.remove(liquidityBounds, removeIndex)
 
//====================================================
// ORIGINAL FVG DETECTION
//====================================================
bodyATR = math.abs(close - open) / safeATR
 
bullFVG = confirmed and low > high[2] and (low - high[2]) / safeATR >= gapMinATR and bodyATR >= bodyMinATR and close > open
bearFVG = confirmed and high < low[2] and (low[2] - high) / safeATR >= gapMinATR and bodyATR >= bodyMinATR and close < open
 
var array<box> fvgBoxes = array.new<box>()
var array<int> fvgDirs = array.new<int>()
var array<float> fvgTops = array.new<float>()
var array<float> fvgBottoms = array.new<float>()
var array<float> fvgFill = array.new<float>()
var array<int> fvgBirth = array.new<int>()
 
//====================================================
// REFINED FVG PRESENTATION
//====================================================
if confirmed and array.size(fvgBoxes) > 0
    for i = array.size(fvgBoxes) - 1 to 0
        box b = array.get(fvgBoxes, i)
        int d = array.get(fvgDirs, i)
        float top = array.get(fvgTops, i)
        float bottom = array.get(fvgBottoms, i)
 
        float width = math.max(top - bottom, syminfo.mintick)
        float oldFill = array.get(fvgFill, i)
 
        float newFill = d == 1 ? clamp((top - low) / width, 0, 1) : clamp((high - bottom) / width, 0, 1)
        float filled = math.max(oldFill, newFill)
 
        array.set(fvgFill, i, filled)
 
        bool expired = bar_index - array.get(fvgBirth, i) >= gapLife
        bool complete = filled >= 1.0
 
        if expired or (complete and removeFilled)
            box.delete(b)
 
            array.remove(fvgBoxes, i)
            array.remove(fvgDirs, i)
            array.remove(fvgTops, i)
            array.remove(fvgBottoms, i)
            array.remove(fvgFill, i)
            array.remove(fvgBirth, i)
        else
            box.set_right(b, bar_index + 1)
            box.set_top(b, d == 1 ? top - width * filled : top)
            box.set_bottom(b, d == -1 ? bottom + width * filled : bottom)
 
            color c = d == 1 ? bullCol : bearCol
 
            int transparency = originalVisual ? int(clamp(84 + filled * 12, 0, 100)) : int(clamp(fvgTransparency + filled * 10, 0, 100))
 
            box.set_bgcolor(b, color.new(c, transparency))
 
            if premiumVisual and fvgAccent
                box.set_border_color(b, color.new(c, int(clamp(48 + filled * 45, 0, 100))))
 
if showFVG and (bullFVG or bearFVG)
    int d = bullFVG ? 1 : -1
 
    float top = bullFVG ? low : low[2]
    float bottom = bullFVG ? high[2] : high
 
    color c = d == 1 ? bullCol : bearCol
 
    box b = box.new(
         bar_index - 2, top,
         bar_index + 1, bottom,
         bgcolor=color.new(c, originalVisual ? 84 : fvgTransparency),
         border_color=color.new(c, originalVisual ? 35 : 50))
 
    array.push(fvgBoxes, b)
    array.push(fvgDirs, d)
    array.push(fvgTops, top)
    array.push(fvgBottoms, bottom)
    array.push(fvgFill, 0.0)
    array.push(fvgBirth, bar_index)
 
    if array.size(fvgBoxes) > maxGaps
        box.delete(array.shift(fvgBoxes))
        array.shift(fvgDirs)
        array.shift(fvgTops)
        array.shift(fvgBottoms)
        array.shift(fvgFill)
        array.shift(fvgBirth)
 
//====================================================
// ORIGINAL SIGNAL QUALITY ENGINE
//====================================================
bullEvent = bullBreak or bullSweep or bullFVG
bearEvent = bearBreak or bearSweep or bearFVG
 
var int bullEventBar = na
var int bearEventBar = na
 
var float bullEventStrength = 0.0
var float bearEventStrength = 0.0
 
if bullEvent
    bullEventBar := bar_index
    bullEventStrength := bullSweep ? bullSweepQuality : bullFVG ? 70.0 : 65.0
 
if bearEvent
    bearEventBar := bar_index
    bearEventStrength := bearSweep ? bearSweepQuality : bearFVG ? 70.0 : 65.0
 
bullRecent = not na(bullEventBar) and bar_index - bullEventBar <= eventWindow
bearRecent = not na(bearEventBar) and bar_index - bearEventBar <= eventWindow
 
bullStructurePoints = structureDirection == 1 ? 30.0 : structureDirection == 0 ? 15.0 : 0.0
bearStructurePoints = structureDirection == -1 ? 30.0 : structureDirection == 0 ? 15.0 : 0.0
 
bullTrendPoints = bullTrend ? 25.0 : bullAligned ? 12.5 : 0.0
bearTrendPoints = bearTrend ? 25.0 : bearAligned ? 12.5 : 0.0
 
bullMomentumPoints = 20.0 * clamp((rsi - 45.0) / 25.0, 0, 1)
bearMomentumPoints = 20.0 * clamp((55.0 - rsi) / 25.0, 0, 1)
 
bullEventPoints = bullRecent ? 15.0 + 10.0 * clamp(bullEventStrength / 100, 0, 1) : 0.0
bearEventPoints = bearRecent ? 15.0 + 10.0 * clamp(bearEventStrength / 100, 0, 1) : 0.0
 
bullScore = clamp(bullStructurePoints + bullTrendPoints + bullMomentumPoints + bullEventPoints, 0, 100)
bearScore = clamp(bearStructurePoints + bearTrendPoints + bearMomentumPoints + bearEventPoints, 0, 100)
 
var int lastSignal = na
 
cooldownOK = na(lastSignal) or bar_index - lastSignal > cooldown
 
longCandidate = confirmed and bullRecent and bullScore >= scoreThreshold and (not requireTrend or bullTrend) and cooldownOK
shortCandidate = confirmed and bearRecent and bearScore >= scoreThreshold and (not requireTrend or bearTrend) and cooldownOK
 
longSignal = longCandidate and not shortCandidate
shortSignal = shortCandidate and not longCandidate
 
if longSignal or shortSignal
    lastSignal := bar_index
 
//====================================================
// CLEAN SIGNAL AND EVENT MARKERS
//====================================================
// Minor liquidity events remain internal.
// Oversized signal halos have been removed.
 
showBullSweepMarker = showEvents and bullSweep and (originalVisual or bullVisible)
showBearSweepMarker = showEvents and bearSweep and (originalVisual or bearVisible)
 
plotshape(showBullSweepMarker, "Bullish Liquidity", shape.triangleup, location.belowbar, liqCol, size=size.tiny)
plotshape(showBearSweepMarker, "Bearish Liquidity", shape.triangledown, location.abovebar, liqCol, size=size.tiny)
 
plotshape(showEvents and bullShift, "Bullish Structure Shift", shape.diamond, location.belowbar, bullCol, size=size.tiny)
plotshape(showEvents and bearShift, "Bearish Structure Shift", shape.diamond, location.abovebar, bearCol, size=size.tiny)
 
// Original directional markers, unchanged.
plotshape(showSignals and longSignal, "Bullish Confluence", shape.triangleup, location.belowbar, bullCol, size=size.normal)
plotshape(showSignals and shortSignal, "Bearish Confluence", shape.triangledown, location.abovebar, bearCol, size=size.normal)
 
//====================================================
// DASHBOARD POSITION AND SIZE
//====================================================
panelPosition = switch dashPos
    "Top Left" => position.top_left
    "Middle Right" => position.middle_right
    "Middle Left" => position.middle_left
    "Bottom Right" => position.bottom_right
    "Bottom Left" => position.middle_left
    => position.top_right
 
panelSize = switch dashSize
    "Tiny" => size.tiny
    "Normal" => size.normal
    "Large" => size.large
    => size.small
 
//====================================================
// DASHBOARD
//====================================================
panelBackground = color.new(color.rgb(15, 22, 35), dashOpacity)
 
var table dash = table.new(
     panelPosition, 2, 7,
     bgcolor=panelBackground,
     frame_color=color.new(neutralCol, 65),
     frame_width=1)
 
dashRow(int row, string title, string value, color valueColor, color bg) =>
    table.cell(dash, 0, row, title, text_color=color.rgb(220, 230, 240), bgcolor=bg, text_size=panelSize, text_halign=text.align_left)
    table.cell(dash, 1, row, value, text_color=valueColor, bgcolor=bg, text_size=panelSize, text_halign=text.align_right)
 
//====================================================
// ORIGINAL DASHBOARD DATA
//====================================================
trendText = trend == 1 ? "BULLISH" : trend == -1 ? "BEARISH" : "NEUTRAL"
structureText = structureDirection == 1 ? "BULLISH" : structureDirection == -1 ? "BEARISH" : "NEUTRAL"
momentumText = rsi > 55 ? "BULLISH" : rsi < 45 ? "BEARISH" : "NEUTRAL"
 
volRatio = safeATR / math.max(nz(ta.sma(atr, 50), safeATR), syminfo.mintick)
volText = volRatio > 1.35 ? "HIGH" : volRatio < 0.75 ? "LOW" : "NORMAL"
 
biasText = bullScore > bearScore ? "BULLISH" : bearScore > bullScore ? "BEARISH" : "NEUTRAL"
dominantScore = math.max(bullScore, bearScore)
 
activeFVG = array.size(fvgBoxes)
 
//====================================================
// DASHBOARD RENDER
//====================================================
if barstate.islast
    table.clear(dash, 0, 0, 1, 6)
 
    if dashOn
        color bg = color.new(color.rgb(15, 22, 35), dashOpacity)
        color header = premiumVisual ? color.new(color.rgb(29, 54, 72), dashOpacity) : color.new(color.rgb(34, 51, 75), dashOpacity)
 
        color accent = premiumVisual ? (trend == 1 ? bullCol : trend == -1 ? bearCol : liqCol) : color.rgb(245, 190, 65)
 
        table.set_frame_color(dash, premiumVisual and dashGlow ? color.new(accent, 35) : color.new(neutralCol, 65))
        table.set_frame_width(dash, premiumVisual and dashGlow ? 2 : 1)
 
        dashRow(0, "OLA APEX", "V1.3", accent, header)
        dashRow(1, "TREND", trendText, trend == 1 ? bullCol : trend == -1 ? bearCol : neutralCol, bg)
        dashRow(2, "STRUCTURE", structureText, structureDirection == 1 ? bullCol : structureDirection == -1 ? bearCol : neutralCol, bg)
        dashRow(3, "MOMENTUM", momentumText, rsi > 55 ? bullCol : rsi < 45 ? bearCol : neutralCol, bg)
 
        if dashLayout == "Detailed"
            dashRow(4, "VOLATILITY", volText, volRatio > 1.35 ? liqCol : neutralCol, bg)
            dashRow(5, "BIAS / QUALITY", biasText + " " + str.tostring(math.round(dominantScore)), biasText == "BULLISH" ? bullCol : biasText == "BEARISH" ? bearCol : neutralCol, bg)
            dashRow(6, "ACTIVE FVG", str.tostring(activeFVG), liqCol, bg)
        else
            dashRow(4, "QUALITY", str.tostring(math.round(dominantScore)) + "/100", liqCol, bg)
 
//====================================================
// ORIGINAL ALERT CONDITIONS
//====================================================
alertcondition(longSignal, "APEX Bullish Signal", "OLA APEX bullish confluence confirmed")
alertcondition(shortSignal, "APEX Bearish Signal", "OLA APEX bearish confluence confirmed")
 
alertcondition(bullSweep, "APEX Bullish Sweep", "OLA APEX bullish liquidity sweep")
alertcondition(bearSweep, "APEX Bearish Sweep", "OLA APEX bearish liquidity sweep")
 
alertcondition(bullShift, "APEX Bullish Structure Shift", "OLA APEX bullish structure shift")
alertcondition(bearShift, "APEX Bearish Structure Shift", "OLA APEX bearish structure shift")
 
alertcondition(bullFVG, "APEX Bullish FVG", "OLA APEX bullish fair value gap")
alertcondition(bearFVG, "APEX Bearish FVG", "OLA APEX bearish fair value gap")

← 返回列表