Skip to content

Instantly share code, notes, and snippets.

@Jordan-Hall
Last active June 1, 2026 11:37
Show Gist options
  • Select an option

  • Save Jordan-Hall/081cbd009b45169c0c0553f77c633d59 to your computer and use it in GitHub Desktop.

Select an option

Save Jordan-Hall/081cbd009b45169c0c0553f77c633d59 to your computer and use it in GitHub Desktop.
AurumEdge Mega
//@version=6
indicator("AurumEdge Mega XAUUSD SMC Scalper v1.4.4 Clean UI Zones + Score Guide", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500, dynamic_requests=true)
src = input.source(close, "Source")
groupHelp = "00. Collapsible Help - How To Read"
showHelpPanel = input.bool(false, "Show Help Panel", group=groupHelp, tooltip="Shows a compact guide on the chart. This group is collapsible in settings.")
helpMode = input.string("Compact", "Help Detail", options=["Off", "Compact", "Full"], group=groupHelp, tooltip="Compact shows the minimum. Full explains each engine.")
showConfluenceReasons = input.bool(true, "Show Reasons", group=groupHelp, tooltip="Shows why BUY/SELL/WAIT is being suggested.")
showActionOnly = input.bool(false, "Only Show Actionable BUY/SELL", group=groupHelp, tooltip="When enabled, forming areas still calculate but the dashboard stays WAIT until a valid entry triggers.")
labelStyle = input.string("Plain + Terms", "Label Style", options=["Plain + Terms", "Plain Only", "Pro Terms"], group=groupHelp, tooltip="Plain + Terms shows newcomer wording while keeping the trading term, e.g. Upper half - sell area (PREMIUM), Bigger charts (MTF), Buy zone (DEMAND).")
groupCore = "01. Core Engine"
tradeSide = input.string("Both", "Trade Side", options=["Both", "Long only", "Short only"], group=groupCore)
confirmSignalsOnClose = input.bool(true, "Confirm BUY/SELL On Candle Close", group=groupCore, tooltip="Best for avoiding repaint-like intrabar entries. Advice/dashboard can still update intrabar.")
allowIntrabarAdvice = input.bool(true, "Allow Advice To Change Mid-Candle", group=groupCore, tooltip="Dashboard bias can change intrabar when price materially changes.")
minScoreAction = input.int(68, "Minimum Action Score", minval=1, maxval=100, group=groupCore)
minEdgeAction = input.int(8, "Minimum Long/Short Edge", minval=0, maxval=50, group=groupCore)
minBarsBetweenSignals = input.int(5, "Bars Between Same Direction Signals", minval=1, maxval=100, group=groupCore)
groupRibbon = "02. Gold MA Ribbon"
showRibbon = input.bool(true, "Show Fibonacci EMA Ribbon", group=groupRibbon)
ribbonTightAtr = input.float(0.55, "Ribbon Compression ATR", minval=0.05, step=0.05, group=groupRibbon)
ema1Len = input.int(5, "EMA 1", minval=1, group=groupRibbon, inline="e1")
ema2Len = input.int(8, "EMA 2", minval=1, group=groupRibbon, inline="e1")
ema3Len = input.int(13, "EMA 3", minval=1, group=groupRibbon, inline="e2")
ema4Len = input.int(21, "EMA 4", minval=1, group=groupRibbon, inline="e2")
ema5Len = input.int(34, "EMA 5", minval=1, group=groupRibbon, inline="e3")
ema6Len = input.int(55, "EMA 6", minval=1, group=groupRibbon, inline="e3")
ema7Len = input.int(89, "EMA 7", minval=1, group=groupRibbon, inline="e4")
ema8Len = input.int(144, "EMA 8", minval=1, group=groupRibbon, inline="e4")
useVwap = input.bool(true, "Use VWAP Filter", group=groupRibbon)
groupSMC = "03. Smart Money Concepts"
pivotLeft = input.int(4, "Swing Left", minval=1, group=groupSMC)
pivotRight = input.int(4, "Swing Right", minval=1, group=groupSMC)
internalLeft = input.int(2, "Internal Left", minval=1, group=groupSMC)
internalRight = input.int(2, "Internal Right", minval=1, group=groupSMC)
equalToleranceAtr = input.float(0.18, "Equal High/Low ATR Tolerance", minval=0.01, step=0.01, group=groupSMC)
sweepCloseBack = input.bool(true, "Sweep Must Close Back Inside", group=groupSMC)
showStructure = input.bool(true, "Show BOS / CHoCH", group=groupSMC)
showEqualLevels = input.bool(true, "Show Equal Highs/Lows", group=groupSMC)
showPremiumDiscount = input.bool(true, "Show Premium / Discount", group=groupSMC)
groupFVG = "04. Fair Value Gaps"
useFvg = input.bool(true, "Use FVG", group=groupFVG)
showFvg = input.bool(true, "Show FVG Boxes", group=groupFVG)
fvgMinAtr = input.float(0.18, "Minimum FVG Size ATR", minval=0.01, step=0.01, group=groupFVG)
fvgLifeBars = input.int(90, "FVG Life Bars", minval=5, maxval=500, group=groupFVG)
fvgMitigation = input.string("Wick", "Mitigation", options=["Wick", "Close"], group=groupFVG)
groupOB = "05. Order Blocks"
useOb = input.bool(true, "Use Order Blocks", group=groupOB)
showOb = input.bool(true, "Show OB Boxes", group=groupOB)
obLookback = input.int(12, "OB Search Bars", minval=2, maxval=50, group=groupOB)
displacementAtr = input.float(1.0, "Displacement ATR", minval=0.2, step=0.1, group=groupOB)
obLifeBars = input.int(120, "OB Life Bars", minval=10, maxval=500, group=groupOB)
obTouchAtr = input.float(0.15, "OB Touch ATR", minval=0.0, step=0.05, group=groupOB)
groupMTF = "06. Multi-Timeframe Bias"
useMtf = input.bool(true, "Use MTF Bias", group=groupMTF)
mtf1 = input.timeframe("15", "HTF 1", group=groupMTF)
mtf2 = input.timeframe("60", "HTF 2", group=groupMTF)
mtf3 = input.timeframe("240", "HTF 3", group=groupMTF)
mtf4 = input.timeframe("D", "HTF 4", group=groupMTF)
mtfFastLen = input.int(21, "MTF Fast EMA", minval=1, group=groupMTF)
mtfSlowLen = input.int(55, "MTF Slow EMA", minval=1, group=groupMTF)
groupMacro = "07. Macro Pressure"
useMacro = input.bool(true, "Use DXY / Yields / Silver / Oil", group=groupMacro)
macroTf = input.timeframe("60", "Macro TF", group=groupMacro)
dxySym = input.symbol("TVC:DXY", "DXY", group=groupMacro)
us10ySym = input.symbol("TVC:US10Y", "US10Y", group=groupMacro)
silverSym = input.symbol("OANDA:XAGUSD", "Silver", group=groupMacro)
oilSym = input.symbol("TVC:USOIL", "Oil", group=groupMacro)
macroLen = input.int(21, "Macro EMA Length", minval=1, group=groupMacro)
groupSessions = "08. XAUUSD Sessions"
showSessions = input.bool(true, "Show Kill Zones", group=groupSessions)
sessionTz = input.string("America/New_York", "Session Timezone", group=groupSessions)
asiaSession = input.session("1800-0000", "Asia Range", group=groupSessions)
londonSession = input.session("0200-0500", "London Kill Zone", group=groupSessions)
nySession = input.session("0700-1100", "NY Kill Zone", group=groupSessions)
tradeOnlyKillzones = input.bool(false, "Trade Only London / NY", group=groupSessions)
groupRisk = "09. Risk / TP Model"
atrLen = input.int(14, "ATR Length", minval=1, group=groupRisk)
fallbackStopAtr = input.float(1.15, "Fallback Stop ATR", minval=0.1, step=0.05, group=groupRisk)
maxStopAtr = input.float(1.80, "Max Stop ATR", minval=0.2, step=0.1, group=groupRisk)
spreadPrice = input.float(0.30, "Spread Price Units", minval=0.0, step=0.01, group=groupRisk)
slippagePrice = input.float(0.05, "Slippage Price Units", minval=0.0, step=0.01, group=groupRisk)
rr1 = input.float(0.85, "TP1 Net R", minval=0.25, step=0.05, group=groupRisk)
rr2 = input.float(1.30, "TP2 Net R", minval=0.25, step=0.05, group=groupRisk)
rr3 = input.float(1.90, "TP3 Net R", minval=0.25, step=0.05, group=groupRisk)
activeTarget = input.string("TP1", "Score Accuracy Against", options=["TP1", "TP2", "TP3"], group=groupRisk)
trackBars = input.int(12, "Bars To Judge TP/SL", minval=1, maxval=100, group=groupRisk)
bothHitResult = input.string("Neutral", "TP And SL Same Candle", options=["Neutral", "Wrong"], group=groupRisk)
groupDisplay = "10. Display"
dashboardPosition = input.string("Top right", "Dashboard Position", options=["Top right", "Top left", "Bottom right", "Bottom left"], group=groupDisplay)
dashboardCompact = input.bool(true, "Compact Dashboard", group=groupDisplay)
dashboardTextSize = input.string("Normal", "Dashboard Text Size", options=["Small", "Normal", "Large"], group=groupDisplay)
accuracyPosition = input.string("Bottom right", "Accuracy Position", options=["Top right", "Top left", "Bottom right", "Bottom left"], group=groupDisplay)
showDashboard = input.bool(true, "Show Dashboard", group=groupDisplay)
showTradeLines = input.bool(true, "Show TP / SL Lines", group=groupDisplay)
showAccuracy = input.bool(true, "Show TP Accuracy Ticks", group=groupDisplay)
accuracyLogSize = input.int(12, "Accuracy Log Size", minval=3, maxval=20, group=groupDisplay)
showLabels = input.bool(true, "Show Signal Labels", group=groupDisplay)
groupColour = "11. Bottom Colour Strip / Visual Risk"
showBottomStrip = input.bool(true, "Show Bottom Colour Strip", group=groupColour)
bottomStripPosition = input.string("Bottom right", "Bottom Strip Position", options=["Bottom center", "Bottom left", "Bottom right"], group=groupColour)
bottomStripTextSize = input.string("Small", "Bottom Strip Text Size", options=["Small", "Normal", "Large"], group=groupColour)
bottomStripCompact = input.bool(true, "Compact Bottom Strip", group=groupColour)
hideHelpWhenBottomStrip = input.bool(true, "Hide Help When Bottom Strip Is On", group=groupColour)
hideAccuracyWhenBottomStrip = input.bool(true, "Hide Accuracy Table When Bottom Strip Is On", group=groupColour)
showCandleColour = input.bool(true, "Colour Candles By Bias", group=groupColour)
showBackgroundTint = input.bool(false, "Background Tint By Bias", group=groupColour)
strongBullColour = input.color(color.rgb(0, 220, 130), "Strong Bull", group=groupColour)
weakBullColour = input.color(color.rgb(95, 180, 95), "Weak Bull", group=groupColour)
neutralColour = input.color(color.rgb(80, 80, 90), "Neutral", group=groupColour)
weakBearColour = input.color(color.rgb(210, 115, 70), "Weak Bear", group=groupColour)
strongBearColour = input.color(color.rgb(230, 55, 75), "Strong Bear", group=groupColour)
warningColour = input.color(color.rgb(255, 185, 0), "Warning / Caution", group=groupColour)
showScoreDepth = input.bool(false, "Show Score Depth Panel", group=groupDisplay)
scoreDepthPosition = input.string("Bottom left", "Score Depth Position", options=["Top right", "Top left", "Bottom right", "Bottom left"], group=groupDisplay)
scoreDepthTextSize = input.string("Small", "Score Depth Text Size", options=["Small", "Normal", "Large"], group=groupDisplay)
showIdealOnScore = input.bool(true, "Show Ideal Score Guide", group=groupDisplay)
idealScoreAction = input.int(80, "Ideal Score", minval=1, maxval=100, group=groupDisplay)
idealEdgeAction = input.int(20, "Ideal Gap", minval=0, maxval=100, group=groupDisplay)
strongScoreAction = input.int(75, "Strong Score", minval=1, maxval=100, group=groupDisplay)
groupMtfZones = "12. MTF Action Zones"
showMtfZones = input.bool(true, "Show MTF Zones", group=groupMtfZones)
showMtfZoneLabels = input.bool(true, "Show MTF Zone Labels", group=groupMtfZones)
showMtfZoneTable = input.bool(false, "Show Nearest Zone Table", group=groupMtfZones)
useMtfZonesAsBlocker = input.bool(true, "Use MTF Zones As Trade Blocker", group=groupMtfZones)
mtfZoneBreakMode = input.string("Close", "Zone Break Mode", options=["Close", "Wick"], group=groupMtfZones)
mtfZoneValidBars = input.int(36, "Zone Valid For Chart Bars", minval=3, maxval=300, group=groupMtfZones)
mtfZoneDeleteWhen = input.string("Broken or expired", "Remove Zone When", options=["Touched", "Broken or expired", "Expired only"], group=groupMtfZones)
mtfZoneTextInside = input.bool(true, "Write Text Inside Zone", group=groupMtfZones)
mtfZoneTextPrice = input.bool(true, "Show Zone Prices In Text", group=groupMtfZones)
mtfZoneMaxTotal = input.int(40, "Max MTF Zones", minval=5, maxval=120, group=groupMtfZones)
mtfZonePivotLeft = input.int(3, "HTF Pivot Left", minval=1, maxval=10, group=groupMtfZones)
mtfZonePivotRight = input.int(3, "HTF Pivot Right", minval=1, maxval=10, group=groupMtfZones)
mtfZoneAtrPad = input.float(0.12, "Zone ATR Padding", minval=0.0, maxval=1.0, step=0.01, group=groupMtfZones)
mtfZoneMinAtrSize = input.float(0.10, "Minimum Zone Size ATR", minval=0.0, maxval=2.0, step=0.05, group=groupMtfZones)
mtfZoneNearAtr = input.float(0.35, "Too Close Distance ATR", minval=0.05, maxval=3.0, step=0.05, group=groupMtfZones)
mtfZoneTf1On = input.bool(true, "TF1", group=groupMtfZones, inline="z1")
mtfZoneTf1 = input.timeframe("5", "", group=groupMtfZones, inline="z1")
mtfZoneTf2On = input.bool(true, "TF2", group=groupMtfZones, inline="z2")
mtfZoneTf2 = input.timeframe("15", "", group=groupMtfZones, inline="z2")
mtfZoneTf3On = input.bool(true, "TF3", group=groupMtfZones, inline="z3")
mtfZoneTf3 = input.timeframe("60", "", group=groupMtfZones, inline="z3")
mtfZoneTf4On = input.bool(true, "TF4", group=groupMtfZones, inline="z4")
mtfZoneTf4 = input.timeframe("240", "", group=groupMtfZones, inline="z4")
mtfZoneTf5On = input.bool(true, "TF5", group=groupMtfZones, inline="z5")
mtfZoneTf5 = input.timeframe("D", "", group=groupMtfZones, inline="z5")
mtfZoneTablePosition = input.string("Top left", "Zone Table Position", options=["Top right", "Top left", "Bottom right", "Bottom left"], group=groupMtfZones)
mtfZoneTextSize = input.string("Small", "Zone Text Size", options=["Small", "Normal", "Large"], group=groupMtfZones)
f_pos(_p) =>
_p == "Top left" ? position.top_left : _p == "Bottom left" ? position.bottom_left : _p == "Bottom right" ? position.bottom_right : position.top_right
f_bottom_pos(_p) =>
_p == "Bottom left" ? position.bottom_left : _p == "Bottom right" ? position.bottom_right : position.bottom_center
f_panel_size(_s) =>
_s == "Large" ? size.large : _s == "Normal" ? size.normal : size.small
f_fmt(_v) =>
str.tostring(_v, format.mintick)
f_clamp(_v, _lo, _hi) =>
math.max(_lo, math.min(_hi, _v))
f_score(_condition, _points) =>
_condition ? _points : 0
f_mid(_a, _b) =>
(_a + _b) * 0.5
f_short(_s, _n) =>
str.length(_s) > _n ? str.substring(_s, 0, _n) + "..." : _s
f_pe(_plain, _classic) =>
labelStyle == "Plain + Terms" ? _plain + " (" + _classic + ")" : labelStyle == "Plain Only" ? _plain : _classic
f_bias_bg(_score, _isBull) =>
_score >= 80 ? (_isBull ? strongBullColour : strongBearColour) : _score >= 65 ? (_isBull ? weakBullColour : weakBearColour) : neutralColour
f_heat_bg(_v) =>
_v >= 80 ? color.new(color.lime, 5) : _v >= 65 ? color.new(color.lime, 35) : _v >= 50 ? color.new(warningColour, 30) : _v >= 35 ? color.new(color.orange, 35) : color.new(color.red, 25)
f_line_set(_ln, _on, _y, _col, _style, _width) =>
line out = _ln
if _on and not na(_y)
if na(out)
out := line.new(bar_index, _y, bar_index + 3, _y, xloc=xloc.bar_index, extend=extend.none, color=_col, style=_style, width=_width)
else
line.set_xy1(out, bar_index, _y)
line.set_xy2(out, bar_index + 3, _y)
line.set_color(out, _col)
line.set_style(out, _style)
line.set_width(out, _width)
else
if not na(out)
line.delete(out)
out := na
out
f_macro(_sym) =>
request.security(_sym, macroTf, [close, ta.ema(close, macroLen), ta.roc(close, 5)], barmerge.gaps_off, barmerge.lookahead_off)
f_find_bull_ob(_n) =>
float top = na
float bot = na
int born = na
for i = 1 to _n
if na(born) and close[i] < open[i]
top := open[i]
bot := low[i]
born := bar_index - i
[top, bot, born]
f_find_bear_ob(_n) =>
float top = na
float bot = na
int born = na
for i = 1 to _n
if na(born) and close[i] > open[i]
top := high[i]
bot := open[i]
born := bar_index - i
[top, bot, born]
var box[] mtfZoneBoxes = array.new_box()
var label[] mtfZoneLabels = array.new_label()
var float[] mtfZoneTops = array.new_float()
var float[] mtfZoneBots = array.new_float()
var int[] mtfZoneDirs = array.new_int()
var string[] mtfZoneNames = array.new_string()
var string[] mtfZoneKeys = array.new_string()
var int[] mtfZoneRightTimes = array.new_int()
f_mtf_zone_data(_left, _right, _atrLen, _pad) =>
_atr = ta.atr(_atrLen)
_ph = ta.pivothigh(high, _left, _right)
_pl = ta.pivotlow(low, _left, _right)
_sTop = not na(_ph) ? high[_right] + _atr[_right] * _pad : na
_sBot = not na(_ph) ? math.max(open[_right], close[_right]) : na
_sTime = not na(_ph) ? time[_right] : na
_dTop = not na(_pl) ? math.min(open[_right], close[_right]) : na
_dBot = not na(_pl) ? low[_right] - _atr[_right] * _pad : na
_dTime = not na(_pl) ? time[_right] : na
[_sTop, _sBot, _sTime, _dTop, _dBot, _dTime]
f_tf_label(_tf) =>
_tf == "1" ? "1m" : _tf == "3" ? "3m" : _tf == "5" ? "5m" : _tf == "15" ? "15m" : _tf == "30" ? "30m" : _tf == "45" ? "45m" : _tf == "60" ? "1H" : _tf == "120" ? "2H" : _tf == "180" ? "3H" : _tf == "240" ? "4H" : _tf == "D" ? "1D" : _tf == "W" ? "1W" : _tf
f_add_mtf_zone(_enabled, _name, _dir, _topRaw, _botRaw, _tm, _border, _fill, _chartAtr) =>
_top = math.max(_topRaw, _botRaw)
_bot = math.min(_topRaw, _botRaw)
_minSize = _chartAtr * mtfZoneMinAtrSize
_valid = showMtfZones and _enabled and not na(_top) and not na(_bot) and not na(_tm) and _top - _bot >= _minSize
if _valid
_key = _name + "|" + str.tostring(_dir) + "|" + str.tostring(_tm)
if not array.includes(mtfZoneKeys, _key)
_barMs = int(nz(time - time[1], 60000))
_right = time + _barMs * mtfZoneValidBars
_type = _dir == 1 ? f_pe("BUY ZONE", "DEMAND") : f_pe("SELL ZONE", "SUPPLY")
_priceTxt = mtfZoneTextPrice ? "\n" + f_fmt(_bot) + " - " + f_fmt(_top) : ""
_txt = _name + " " + _type + _priceTxt
_box = box.new(_tm, _top, _right, _bot, xloc=xloc.bar_time, border_color=_border, bgcolor=_fill, text=mtfZoneTextInside ? _txt : "", text_color=color.white, text_size=size.tiny, text_halign=text.align_center, text_valign=text.align_center)
label _lb = na
if showMtfZoneLabels and not mtfZoneTextInside
_lb := label.new(_right, f_mid(_top, _bot), _txt, xloc=xloc.bar_time, style=label.style_label_left, color=_border, textcolor=color.white, size=size.tiny)
array.unshift(mtfZoneBoxes, _box)
array.unshift(mtfZoneLabels, _lb)
array.unshift(mtfZoneTops, _top)
array.unshift(mtfZoneBots, _bot)
array.unshift(mtfZoneDirs, _dir)
array.unshift(mtfZoneNames, _txt)
array.unshift(mtfZoneKeys, _key)
array.unshift(mtfZoneRightTimes, _right)
while array.size(mtfZoneBoxes) > mtfZoneMaxTotal
_last = array.size(mtfZoneBoxes) - 1
box.delete(array.get(mtfZoneBoxes, _last))
_oldLb = array.get(mtfZoneLabels, _last)
if not na(_oldLb)
label.delete(_oldLb)
array.remove(mtfZoneBoxes, _last)
array.remove(mtfZoneLabels, _last)
array.remove(mtfZoneTops, _last)
array.remove(mtfZoneBots, _last)
array.remove(mtfZoneDirs, _last)
array.remove(mtfZoneNames, _last)
array.remove(mtfZoneKeys, _last)
array.remove(mtfZoneRightTimes, _last)
0
f_maintain_mtf_zones() =>
if array.size(mtfZoneBoxes) > 0
_count = array.size(mtfZoneBoxes)
for j = 0 to _count - 1
i = _count - 1 - j
_top = array.get(mtfZoneTops, i)
_bot = array.get(mtfZoneBots, i)
_dir = array.get(mtfZoneDirs, i)
_right = array.get(mtfZoneRightTimes, i)
_touched = high >= _bot and low <= _top
_broken = mtfZoneBreakMode == "Close" ? (_dir == 1 ? close < _bot : close > _top) : (_dir == 1 ? low < _bot : high > _top)
_expired = time > _right
_remove = mtfZoneDeleteWhen == "Touched" ? (_touched or _expired) : mtfZoneDeleteWhen == "Broken or expired" ? (_broken or _expired) : _expired
if _remove
box.delete(array.get(mtfZoneBoxes, i))
_lb = array.get(mtfZoneLabels, i)
if not na(_lb)
label.delete(_lb)
array.remove(mtfZoneBoxes, i)
array.remove(mtfZoneLabels, i)
array.remove(mtfZoneTops, i)
array.remove(mtfZoneBots, i)
array.remove(mtfZoneDirs, i)
array.remove(mtfZoneNames, i)
array.remove(mtfZoneKeys, i)
array.remove(mtfZoneRightTimes, i)
else
_b = array.get(mtfZoneBoxes, i)
_bg = _touched ? color.new(_dir == 1 ? color.lime : color.red, 82) : color.new(_dir == 1 ? color.lime : color.red, 90)
box.set_bgcolor(_b, _bg)
box.set_right(_b, _right)
_lb = array.get(mtfZoneLabels, i)
if not na(_lb)
label.set_x(_lb, _right)
label.set_y(_lb, f_mid(_top, _bot))
0
f_clear_mtf_zones() =>
if array.size(mtfZoneBoxes) > 0
_count = array.size(mtfZoneBoxes)
for j = 0 to _count - 1
i = _count - 1 - j
box.delete(array.get(mtfZoneBoxes, i))
_lb = array.get(mtfZoneLabels, i)
if not na(_lb)
label.delete(_lb)
array.remove(mtfZoneBoxes, i)
array.remove(mtfZoneLabels, i)
array.remove(mtfZoneTops, i)
array.remove(mtfZoneBots, i)
array.remove(mtfZoneDirs, i)
array.remove(mtfZoneNames, i)
array.remove(mtfZoneKeys, i)
array.remove(mtfZoneRightTimes, i)
0
atr = ta.atr(atrLen)
fee = spreadPrice + slippagePrice
canSignal = not confirmSignalsOnClose or barstate.isconfirmed
inAsia = not na(time(timeframe.period, asiaSession, sessionTz))
inLondon = not na(time(timeframe.period, londonSession, sessionTz))
inNY = not na(time(timeframe.period, nySession, sessionTz))
inKillzone = inLondon or inNY
sessionOk = not tradeOnlyKillzones or inKillzone
longAllowed = tradeSide != "Short only"
shortAllowed = tradeSide != "Long only"
ema1 = ta.ema(src, ema1Len)
ema2 = ta.ema(src, ema2Len)
ema3 = ta.ema(src, ema3Len)
ema4 = ta.ema(src, ema4Len)
ema5 = ta.ema(src, ema5Len)
ema6 = ta.ema(src, ema6Len)
ema7 = ta.ema(src, ema7Len)
ema8 = ta.ema(src, ema8Len)
vwap = timeframe.isintraday ? ta.vwap(hlc3) : na
ribbonBull = ema1 > ema2 and ema2 > ema3 and ema3 > ema4 and ema4 > ema5 and ema5 > ema6 and ema6 > ema7 and ema7 > ema8
ribbonBear = ema1 < ema2 and ema2 < ema3 and ema3 < ema4 and ema4 < ema5 and ema5 < ema6 and ema6 < ema7 and ema7 < ema8
ribbonWidth = math.abs(ema1 - ema8)
ribbonCompressed = ribbonWidth <= atr * ribbonTightAtr
vwapBull = not useVwap or not timeframe.isintraday or close >= vwap
vwapBear = not useVwap or not timeframe.isintraday or close <= vwap
plot(showRibbon ? ema1 : na, "EMA 5", color=color.new(color.lime, 0))
plot(showRibbon ? ema2 : na, "EMA 8", color=color.new(color.lime, 15))
plot(showRibbon ? ema3 : na, "EMA 13", color=color.new(color.lime, 30))
plot(showRibbon ? ema4 : na, "EMA 21", color=color.new(color.yellow, 0), linewidth=2)
plot(showRibbon ? ema5 : na, "EMA 34", color=color.new(color.orange, 15))
plot(showRibbon ? ema6 : na, "EMA 55", color=color.new(color.orange, 30))
plot(showRibbon ? ema7 : na, "EMA 89", color=color.new(color.red, 35))
plot(showRibbon ? ema8 : na, "EMA 144", color=color.new(color.red, 50), linewidth=2)
plot(showRibbon and useVwap and timeframe.isintraday ? vwap : na, "VWAP", color=color.new(color.purple, 0), linewidth=2)
[tf1C, tf1F, tf1S] = request.security(syminfo.tickerid, mtf1, [close, ta.ema(close, mtfFastLen), ta.ema(close, mtfSlowLen)], barmerge.gaps_off, barmerge.lookahead_off)
[tf2C, tf2F, tf2S] = request.security(syminfo.tickerid, mtf2, [close, ta.ema(close, mtfFastLen), ta.ema(close, mtfSlowLen)], barmerge.gaps_off, barmerge.lookahead_off)
[tf3C, tf3F, tf3S] = request.security(syminfo.tickerid, mtf3, [close, ta.ema(close, mtfFastLen), ta.ema(close, mtfSlowLen)], barmerge.gaps_off, barmerge.lookahead_off)
[tf4C, tf4F, tf4S] = request.security(syminfo.tickerid, mtf4, [close, ta.ema(close, mtfFastLen), ta.ema(close, mtfSlowLen)], barmerge.gaps_off, barmerge.lookahead_off)
mtfBullCount = (tf1F > tf1S ? 1 : 0) + (tf2F > tf2S ? 1 : 0) + (tf3F > tf3S ? 1 : 0) + (tf4F > tf4S ? 1 : 0)
mtfBearCount = (tf1F < tf1S ? 1 : 0) + (tf2F < tf2S ? 1 : 0) + (tf3F < tf3S ? 1 : 0) + (tf4F < tf4S ? 1 : 0)
[dxyC, dxyE, dxyR] = f_macro(dxySym)
[yldC, yldE, yldR] = f_macro(us10ySym)
[xagC, xagE, xagR] = f_macro(silverSym)
[oilC, oilE, oilR] = f_macro(oilSym)
dxyUp = dxyC > dxyE and dxyR > 0
dxyDown = dxyC < dxyE and dxyR < 0
yldUp = yldC > yldE and yldR > 0
yldDown = yldC < yldE and yldR < 0
xagUp = xagC > xagE and xagR > 0
xagDown = xagC < xagE and xagR < 0
oilUp = oilC > oilE and oilR > 0
oilDown = oilC < oilE and oilR < 0
macroBull = useMacro ? (dxyDown ? 8 : 0) + (yldDown ? 8 : 0) + (xagUp ? 6 : 0) + (oilUp ? 2 : 0) : 0
macroBear = useMacro ? (dxyUp ? 8 : 0) + (yldUp ? 8 : 0) + (xagDown ? 6 : 0) + (oilDown ? 2 : 0) : 0
macroText = not useMacro ? "Macro off" : macroBull > macroBear ? "Macro supports gold" : macroBear > macroBull ? "Macro pressures gold" : "Macro mixed"
ph = ta.pivothigh(high, pivotLeft, pivotRight)
pl = ta.pivotlow(low, pivotLeft, pivotRight)
iph = ta.pivothigh(high, internalLeft, internalRight)
ipl = ta.pivotlow(low, internalLeft, internalRight)
var float swingHigh = na
var float swingLow = na
var float prevSwingHigh = na
var float prevSwingLow = na
var int swingHighBar = na
var int swingLowBar = na
var int trendState = 0
if not na(ph)
prevSwingHigh := swingHigh
swingHigh := ph
swingHighBar := bar_index - pivotRight
if not na(pl)
prevSwingLow := swingLow
swingLow := pl
swingLowBar := bar_index - pivotRight
crossOverSwingHigh = ta.crossover(close, swingHigh)
crossUnderSwingLow = ta.crossunder(close, swingLow)
bosBull = not na(swingHigh) and crossOverSwingHigh
bosBear = not na(swingLow) and crossUnderSwingLow
chochBull = bosBull and trendState == -1
chochBear = bosBear and trendState == 1
if bosBull
trendState := 1
if bosBear
trendState := -1
if showStructure and bosBull
label.new(bar_index, high, chochBull ? "CHoCH ↑" : "BOS ↑", style=label.style_label_down, color=color.new(color.lime, 0), textcolor=color.black, size=size.tiny)
if showStructure and bosBear
label.new(bar_index, low, chochBear ? "CHoCH ↓" : "BOS ↓", style=label.style_label_up, color=color.new(color.red, 0), textcolor=color.white, size=size.tiny)
eqh = showEqualLevels and not na(swingHigh) and not na(prevSwingHigh) and math.abs(swingHigh - prevSwingHigh) <= atr * equalToleranceAtr
eql = showEqualLevels and not na(swingLow) and not na(prevSwingLow) and math.abs(swingLow - prevSwingLow) <= atr * equalToleranceAtr
var line eqhLine = na
var line eqlLine = na
if eqh
if not na(eqhLine)
line.delete(eqhLine)
eqhLine := line.new(swingHighBar, swingHigh, bar_index, swingHigh, xloc=xloc.bar_index, color=color.new(color.red, 0), style=line.style_dotted, width=2)
if eql
if not na(eqlLine)
line.delete(eqlLine)
eqlLine := line.new(swingLowBar, swingLow, bar_index, swingLow, xloc=xloc.bar_index, color=color.new(color.lime, 0), style=line.style_dotted, width=2)
bullSweep = not na(swingLow) and low < swingLow and (not sweepCloseBack or close > swingLow)
bearSweep = not na(swingHigh) and high > swingHigh and (not sweepCloseBack or close < swingHigh)
var float asiaHigh = na
var float asiaLow = na
var float prevAsiaHigh = na
var float prevAsiaLow = na
newAsia = inAsia and not inAsia[1]
endAsia = not inAsia and inAsia[1]
if newAsia
asiaHigh := high
asiaLow := low
else if inAsia
asiaHigh := math.max(nz(asiaHigh, high), high)
asiaLow := math.min(nz(asiaLow, low), low)
if endAsia
prevAsiaHigh := asiaHigh
prevAsiaLow := asiaLow
asiaHighSweep = not na(prevAsiaHigh) and high > prevAsiaHigh and close < prevAsiaHigh
asiaLowSweep = not na(prevAsiaLow) and low < prevAsiaLow and close > prevAsiaLow
sessionBg = showSessions and inAsia ? color.new(color.blue, 92) : showSessions and inLondon ? color.new(color.green, 92) : showSessions and inNY ? color.new(color.orange, 92) : na
bgcolor(sessionBg)
plot(showSessions ? prevAsiaHigh : na, "Previous Asia High", color=color.new(color.blue, 25), style=plot.style_linebr)
plot(showSessions ? prevAsiaLow : na, "Previous Asia Low", color=color.new(color.blue, 25), style=plot.style_linebr)
rangeReady = not na(swingHigh) and not na(swingLow)
rangeTop = rangeReady ? math.max(swingHigh, swingLow) : na
rangeBot = rangeReady ? math.min(swingHigh, swingLow) : na
eqRange = rangeReady ? f_mid(rangeTop, rangeBot) : na
premium = rangeReady and close > eqRange
discount = rangeReady and close < eqRange
var line eqRangeLine = na
eqRangeLine := f_line_set(eqRangeLine, showPremiumDiscount and rangeReady, eqRange, color.new(color.gray, 15), line.style_dashed, 1)
[tf1STop, tf1SBot, tf1STime, tf1DTop, tf1DBot, tf1DTime] = request.security(syminfo.tickerid, mtfZoneTf1, f_mtf_zone_data(mtfZonePivotLeft, mtfZonePivotRight, atrLen, mtfZoneAtrPad), barmerge.gaps_off, barmerge.lookahead_off)
[tf2STop, tf2SBot, tf2STime, tf2DTop, tf2DBot, tf2DTime] = request.security(syminfo.tickerid, mtfZoneTf2, f_mtf_zone_data(mtfZonePivotLeft, mtfZonePivotRight, atrLen, mtfZoneAtrPad), barmerge.gaps_off, barmerge.lookahead_off)
[tf3STop, tf3SBot, tf3STime, tf3DTop, tf3DBot, tf3DTime] = request.security(syminfo.tickerid, mtfZoneTf3, f_mtf_zone_data(mtfZonePivotLeft, mtfZonePivotRight, atrLen, mtfZoneAtrPad), barmerge.gaps_off, barmerge.lookahead_off)
[tf4STop, tf4SBot, tf4STime, tf4DTop, tf4DBot, tf4DTime] = request.security(syminfo.tickerid, mtfZoneTf4, f_mtf_zone_data(mtfZonePivotLeft, mtfZonePivotRight, atrLen, mtfZoneAtrPad), barmerge.gaps_off, barmerge.lookahead_off)
[tf5STop, tf5SBot, tf5STime, tf5DTop, tf5DBot, tf5DTime] = request.security(syminfo.tickerid, mtfZoneTf5, f_mtf_zone_data(mtfZonePivotLeft, mtfZonePivotRight, atrLen, mtfZoneAtrPad), barmerge.gaps_off, barmerge.lookahead_off)
if showMtfZones
f_add_mtf_zone(mtfZoneTf1On, f_tf_label(mtfZoneTf1), -1, tf1STop, tf1SBot, tf1STime, color.new(color.red, 10), color.new(color.red, 88), atr)
f_add_mtf_zone(mtfZoneTf1On, f_tf_label(mtfZoneTf1), 1, tf1DTop, tf1DBot, tf1DTime, color.new(color.lime, 10), color.new(color.lime, 88), atr)
f_add_mtf_zone(mtfZoneTf2On, f_tf_label(mtfZoneTf2), -1, tf2STop, tf2SBot, tf2STime, color.new(color.red, 5), color.new(color.red, 86), atr)
f_add_mtf_zone(mtfZoneTf2On, f_tf_label(mtfZoneTf2), 1, tf2DTop, tf2DBot, tf2DTime, color.new(color.lime, 5), color.new(color.lime, 86), atr)
f_add_mtf_zone(mtfZoneTf3On, f_tf_label(mtfZoneTf3), -1, tf3STop, tf3SBot, tf3STime, color.new(color.orange, 0), color.new(color.red, 84), atr)
f_add_mtf_zone(mtfZoneTf3On, f_tf_label(mtfZoneTf3), 1, tf3DTop, tf3DBot, tf3DTime, color.new(color.aqua, 0), color.new(color.lime, 84), atr)
f_add_mtf_zone(mtfZoneTf4On, f_tf_label(mtfZoneTf4), -1, tf4STop, tf4SBot, tf4STime, color.new(color.fuchsia, 0), color.new(color.red, 82), atr)
f_add_mtf_zone(mtfZoneTf4On, f_tf_label(mtfZoneTf4), 1, tf4DTop, tf4DBot, tf4DTime, color.new(color.teal, 0), color.new(color.lime, 82), atr)
f_add_mtf_zone(mtfZoneTf5On, f_tf_label(mtfZoneTf5), -1, tf5STop, tf5SBot, tf5STime, color.new(color.purple, 0), color.new(color.red, 80), atr)
f_add_mtf_zone(mtfZoneTf5On, f_tf_label(mtfZoneTf5), 1, tf5DTop, tf5DBot, tf5DTime, color.new(color.blue, 0), color.new(color.lime, 80), atr)
f_maintain_mtf_zones()
else
f_clear_mtf_zones()
nearestSupplyDist = 100000000.0
nearestDemandDist = 100000000.0
nearestSupplyName = f_pe("No sell zone above", "NONE")
nearestDemandName = f_pe("No buy zone below", "NONE")
float nearestSupplyZone = na
float nearestDemandZone = na
insideMtfZone = false
insideMtfZoneText = f_pe("Price not inside a zone", "NO ZONE")
insideMtfZoneDir = 0
if array.size(mtfZoneBoxes) > 0
for i = 0 to array.size(mtfZoneBoxes) - 1
_top = array.get(mtfZoneTops, i)
_bot = array.get(mtfZoneBots, i)
_dir = array.get(mtfZoneDirs, i)
_name = array.get(mtfZoneNames, i)
_inside = close <= _top and close >= _bot
if _inside
insideMtfZone := true
insideMtfZoneText := _name
insideMtfZoneDir := _dir
if _dir == -1 and _bot >= close
_d = _bot - close
if _d < nearestSupplyDist
nearestSupplyDist := _d
nearestSupplyName := _name
nearestSupplyZone := _bot
if _dir == 1 and _top <= close
_d = close - _top
if _d < nearestDemandDist
nearestDemandDist := _d
nearestDemandName := _name
nearestDemandZone := _top
nearSupplyAtr = nearestSupplyDist < 100000000.0 ? nearestSupplyDist / atr : na
nearDemandAtr = nearestDemandDist < 100000000.0 ? nearestDemandDist / atr : na
tooCloseSupply = not na(nearSupplyAtr) and nearSupplyAtr <= mtfZoneNearAtr
tooCloseDemand = not na(nearDemandAtr) and nearDemandAtr <= mtfZoneNearAtr
mtfZoneDangerShort = useMtfZonesAsBlocker and showMtfZones and (insideMtfZoneDir == 1 or tooCloseDemand)
mtfZoneDangerLong = useMtfZonesAsBlocker and showMtfZones and (insideMtfZoneDir == -1 or tooCloseSupply)
var table mtfZoneTable = table.new(f_pos(mtfZoneTablePosition), 3, 5, border_width=1, frame_color=color.new(color.white, 70), frame_width=1)
mtfZoneSize = f_panel_size(mtfZoneTextSize)
if showMtfZoneTable and barstate.islast
table.clear(mtfZoneTable, 0, 0, 2, 4)
table.cell(mtfZoneTable, 0, 0, f_pe("BIG CHART ZONES", "MTF ZONES"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 1, 0, f_pe("MEANING", "ZONE"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 2, 0, f_pe("ROOM", "DIST"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 0, 1, f_pe("Price now", "Inside"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 1, 1, insideMtfZoneText, text_color=insideMtfZone ? color.black : color.white, bgcolor=insideMtfZone ? color.new(warningColour, 10) : color.new(color.gray, 35), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 2, 1, insideMtfZone ? f_pe("Decide", "WAIT") : f_pe("Clear", "CLEAR"), text_color=insideMtfZone ? color.black : color.white, bgcolor=insideMtfZone ? color.new(warningColour, 10) : color.new(color.lime, 25), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 0, 2, f_pe("Sell zone above", "Supply ↑"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 1, 2, nearestSupplyName, text_color=color.white, bgcolor=tooCloseSupply ? color.new(color.red, 10) : color.new(color.gray, 35), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 2, 2, na(nearSupplyAtr) ? f_pe("None", "NONE") : str.tostring(nearSupplyAtr, "#.##") + " ATR", text_color=tooCloseSupply ? color.white : color.black, bgcolor=tooCloseSupply ? color.new(color.red, 10) : color.new(color.lime, 25), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 0, 3, f_pe("Buy zone below", "Demand ↓"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 1, 3, nearestDemandName, text_color=color.white, bgcolor=tooCloseDemand ? color.new(color.red, 10) : color.new(color.gray, 35), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 2, 3, na(nearDemandAtr) ? f_pe("None", "NONE") : str.tostring(nearDemandAtr, "#.##") + " ATR", text_color=tooCloseDemand ? color.white : color.black, bgcolor=tooCloseDemand ? color.new(color.red, 10) : color.new(color.lime, 25), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 0, 4, f_pe("Trade read", "Action"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 1, 4, mtfZoneDangerLong ? f_pe("Buy blocked", "LONG RISK") : mtfZoneDangerShort ? f_pe("Sell blocked", "SHORT RISK") : f_pe("Room OK", "ROOM OK"), text_color=mtfZoneDangerLong or mtfZoneDangerShort ? color.white : color.black, bgcolor=mtfZoneDangerLong or mtfZoneDangerShort ? color.new(color.red, 10) : color.new(color.lime, 20), text_size=mtfZoneSize)
table.cell(mtfZoneTable, 2, 4, str.tostring(array.size(mtfZoneBoxes)) + " zones", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=mtfZoneSize)
if not showMtfZoneTable and barstate.islast
table.clear(mtfZoneTable, 0, 0, 2, 4)
bullFvg = useFvg and low > high[2] and low - high[2] >= atr * fvgMinAtr
bearFvg = useFvg and high < low[2] and low[2] - high >= atr * fvgMinAtr
var box[] bullFvgs = array.new_box()
var box[] bearFvgs = array.new_box()
var float[] bullFvgTops = array.new_float()
var float[] bullFvgBots = array.new_float()
var float[] bearFvgTops = array.new_float()
var float[] bearFvgBots = array.new_float()
var int[] bullFvgBorn = array.new_int()
var int[] bearFvgBorn = array.new_int()
if bullFvg and showFvg
b = box.new(bar_index - 2, low, bar_index + fvgLifeBars, high[2], xloc=xloc.bar_index, border_color=color.new(color.lime, 40), bgcolor=color.new(color.lime, 88))
array.push(bullFvgs, b)
array.push(bullFvgTops, low)
array.push(bullFvgBots, high[2])
array.push(bullFvgBorn, bar_index)
if bearFvg and showFvg
b = box.new(bar_index - 2, low[2], bar_index + fvgLifeBars, high, xloc=xloc.bar_index, border_color=color.new(color.red, 40), bgcolor=color.new(color.red, 88))
array.push(bearFvgs, b)
array.push(bearFvgTops, low[2])
array.push(bearFvgBots, high)
array.push(bearFvgBorn, bar_index)
bullFvgNear = false
bearFvgNear = false
if array.size(bullFvgs) > 0
bullFvgCount = array.size(bullFvgs)
for j = 0 to bullFvgCount - 1
i = bullFvgCount - 1 - j
top = array.get(bullFvgTops, i)
bot = array.get(bullFvgBots, i)
born = array.get(bullFvgBorn, i)
mitigated = fvgMitigation == "Close" ? close <= bot : low <= bot
expired = bar_index - born > fvgLifeBars
near = low <= top and high >= bot
bullFvgNear := bullFvgNear or near
if mitigated or expired
box.delete(array.get(bullFvgs, i))
array.remove(bullFvgs, i)
array.remove(bullFvgTops, i)
array.remove(bullFvgBots, i)
array.remove(bullFvgBorn, i)
else
box.set_right(array.get(bullFvgs, i), bar_index + 3)
if array.size(bearFvgs) > 0
bearFvgCount = array.size(bearFvgs)
for j = 0 to bearFvgCount - 1
i = bearFvgCount - 1 - j
top = array.get(bearFvgTops, i)
bot = array.get(bearFvgBots, i)
born = array.get(bearFvgBorn, i)
mitigated = fvgMitigation == "Close" ? close >= top : high >= top
expired = bar_index - born > fvgLifeBars
near = high >= bot and low <= top
bearFvgNear := bearFvgNear or near
if mitigated or expired
box.delete(array.get(bearFvgs, i))
array.remove(bearFvgs, i)
array.remove(bearFvgTops, i)
array.remove(bearFvgBots, i)
array.remove(bearFvgBorn, i)
else
box.set_right(array.get(bearFvgs, i), bar_index + 3)
bullDisplacement = close > high[1] and close - open >= atr * displacementAtr
bearDisplacement = close < low[1] and open - close >= atr * displacementAtr
var float bullObTop = na
var float bullObBot = na
var int bullObBorn = na
var bool bullObActive = false
var float bearObTop = na
var float bearObBot = na
var int bearObBorn = na
var bool bearObActive = false
var box bullObBox = na
var box bearObBox = na
[foundBullTop, foundBullBot, foundBullBorn] = f_find_bull_ob(obLookback)
[foundBearTop, foundBearBot, foundBearBorn] = f_find_bear_ob(obLookback)
if useOb and (bullDisplacement or bosBull) and not na(foundBullBorn)
bullObTop := foundBullTop
bullObBot := foundBullBot
bullObBorn := foundBullBorn
bullObActive := true
if not na(bullObBox)
box.delete(bullObBox)
if showOb
bullObBox := box.new(bullObBorn, bullObTop, bar_index + obLifeBars, bullObBot, xloc=xloc.bar_index, border_color=color.new(color.lime, 0), bgcolor=color.new(color.lime, 88))
if useOb and (bearDisplacement or bosBear) and not na(foundBearBorn)
bearObTop := foundBearTop
bearObBot := foundBearBot
bearObBorn := foundBearBorn
bearObActive := true
if not na(bearObBox)
box.delete(bearObBox)
if showOb
bearObBox := box.new(bearObBorn, bearObTop, bar_index + obLifeBars, bearObBot, xloc=xloc.bar_index, border_color=color.new(color.red, 0), bgcolor=color.new(color.red, 88))
if bullObActive and (close < bullObBot or bar_index - bullObBorn > obLifeBars)
bullObActive := false
if not na(bullObBox)
box.delete(bullObBox)
bullObBox := na
if bearObActive and (close > bearObTop or bar_index - bearObBorn > obLifeBars)
bearObActive := false
if not na(bearObBox)
box.delete(bearObBox)
bearObBox := na
if bullObActive and not na(bullObBox)
box.set_right(bullObBox, bar_index + 3)
if bearObActive and not na(bearObBox)
box.set_right(bearObBox, bar_index + 3)
bullObTouch = bullObActive and high >= bullObBot - atr * obTouchAtr and low <= bullObTop + atr * obTouchAtr
bearObTouch = bearObActive and high >= bearObBot - atr * obTouchAtr and low <= bearObTop + atr * obTouchAtr
body = math.max(math.abs(close - open), syminfo.mintick)
candleRange = math.max(high - low, syminfo.mintick)
upperWick = high - math.max(open, close)
lowerWick = math.min(open, close) - low
bullPin = lowerWick > body * 1.25 and close > open and close > low + candleRange * 0.55
bearPin = upperWick > body * 1.25 and close < open and close < high - candleRange * 0.55
bullEngulf = close > open and close[1] < open[1] and close >= open[1] and open <= close[1]
bearEngulf = close < open and close[1] > open[1] and close <= open[1] and open >= close[1]
bullTrigger = bullPin or bullEngulf or bullSweep or asiaLowSweep or bosBull
bearTrigger = bearPin or bearEngulf or bearSweep or asiaHighSweep or bosBear
longLocation = discount or bullObTouch or bullFvgNear or bullSweep or asiaLowSweep
shortLocation = premium or bearObTouch or bearFvgNear or bearSweep or asiaHighSweep
longBlocked = premium and not bullSweep and not asiaLowSweep and not bullObTouch
shortBlocked = discount and not bearSweep and not asiaHighSweep and not bearObTouch
longStopBase = bullObTouch ? bullObBot : bullFvgNear ? low - atr * 0.25 : not na(swingLow) ? swingLow : close - atr * fallbackStopAtr
shortStopBase = bearObTouch ? bearObTop : bearFvgNear ? high + atr * 0.25 : not na(swingHigh) ? swingHigh : close + atr * fallbackStopAtr
longStop = math.min(longStopBase - atr * 0.10, close - syminfo.mintick)
shortStop = math.max(shortStopBase + atr * 0.10, close + syminfo.mintick)
longRisk = close - longStop
shortRisk = shortStop - close
longRiskOk = longRisk > fee * 1.5 and longRisk <= atr * maxStopAtr
shortRiskOk = shortRisk > fee * 1.5 and shortRisk <= atr * maxStopAtr
trendLongScore = f_score(ribbonBull, 18) + f_score(ema1 > ema4, 8) + f_score(vwapBull, 5) + f_score(ribbonCompressed and close > ema1, 5)
trendShortScore = f_score(ribbonBear, 18) + f_score(ema1 < ema4, 8) + f_score(vwapBear, 5) + f_score(ribbonCompressed and close < ema1, 5)
smcLongScore = f_score(chochBull, 14) + f_score(bosBull, 10) + f_score(bullSweep, 18) + f_score(asiaLowSweep, 14) + f_score(bullObTouch, 12) + f_score(bullFvgNear, 10) + f_score(discount, 8)
smcShortScore = f_score(chochBear, 14) + f_score(bosBear, 10) + f_score(bearSweep, 18) + f_score(asiaHighSweep, 14) + f_score(bearObTouch, 12) + f_score(bearFvgNear, 10) + f_score(premium, 8)
mtfLongScore = useMtf ? mtfBullCount * 5 : 0
mtfShortScore = useMtf ? mtfBearCount * 5 : 0
triggerLongScore = f_score(bullTrigger, 14) + f_score(bullPin, 4) + f_score(bullEngulf, 4)
triggerShortScore = f_score(bearTrigger, 14) + f_score(bearPin, 4) + f_score(bearEngulf, 4)
qualityLongScore = f_score(sessionOk, 5) + f_score(longRiskOk, 8) + f_score(not longBlocked, 8) + f_score(candleRange >= atr * 0.25, 3)
qualityShortScore = f_score(sessionOk, 5) + f_score(shortRiskOk, 8) + f_score(not shortBlocked, 8) + f_score(candleRange >= atr * 0.25, 3)
longScoreRaw = trendLongScore + smcLongScore + mtfLongScore + triggerLongScore + qualityLongScore + macroBull - macroBear * 0.45
shortScoreRaw = trendShortScore + smcShortScore + mtfShortScore + triggerShortScore + qualityShortScore + macroBear - macroBull * 0.45
longScore = math.round(f_clamp(longBlocked or mtfZoneDangerLong ? math.min(longScoreRaw, 55) : longScoreRaw, 0, 100))
shortScore = math.round(f_clamp(shortBlocked or mtfZoneDangerShort ? math.min(shortScoreRaw, 55) : shortScoreRaw, 0, 100))
edge = math.abs(longScore - shortScore)
bestLong = longScore >= shortScore
bestScore = bestLong ? longScore : shortScore
var int lastLongBar = na
var int lastShortBar = na
freshLong = na(lastLongBar) or bar_index - lastLongBar >= minBarsBetweenSignals
freshShort = na(lastShortBar) or bar_index - lastShortBar >= minBarsBetweenSignals
longSetup = longAllowed and sessionOk and longLocation and bullTrigger and longRiskOk and not longBlocked and not mtfZoneDangerLong and longScore >= minScoreAction and longScore - shortScore >= minEdgeAction and freshLong
shortSetup = shortAllowed and sessionOk and shortLocation and bearTrigger and shortRiskOk and not shortBlocked and not mtfZoneDangerShort and shortScore >= minScoreAction and shortScore - longScore >= minEdgeAction and freshShort
buySignal = canSignal and longSetup and not longSetup[1]
sellSignal = canSignal and shortSetup and not shortSetup[1]
if buySignal
lastLongBar := bar_index
if sellSignal
lastShortBar := bar_index
var int tradeDir = 0
var float tradeEntry = na
var float tradeStop = na
var int tradeBar = na
if buySignal
tradeDir := 1
tradeEntry := close
tradeStop := longStop
tradeBar := bar_index
if sellSignal
tradeDir := -1
tradeEntry := close
tradeStop := shortStop
tradeBar := bar_index
tradeRisk = tradeDir != 0 ? math.abs(tradeEntry - tradeStop) : na
tradeNetRisk = tradeDir != 0 ? tradeRisk + fee : na
tp1 = tradeDir == 1 ? tradeEntry + rr1 * tradeNetRisk + fee : tradeDir == -1 ? tradeEntry - rr1 * tradeNetRisk - fee : na
tp2 = tradeDir == 1 ? tradeEntry + rr2 * tradeNetRisk + fee : tradeDir == -1 ? tradeEntry - rr2 * tradeNetRisk - fee : na
tp3 = tradeDir == 1 ? tradeEntry + rr3 * tradeNetRisk + fee : tradeDir == -1 ? tradeEntry - rr3 * tradeNetRisk - fee : na
be = tradeDir == 1 ? tradeEntry + fee : tradeDir == -1 ? tradeEntry - fee : na
tradeStopHit = tradeDir == 1 and low <= tradeStop or tradeDir == -1 and high >= tradeStop
tradeTp3Hit = tradeDir == 1 and high >= tp3 or tradeDir == -1 and low <= tp3
tradeExpired = tradeDir != 0 and bar_index - tradeBar > trackBars * 3
if tradeDir != 0 and (tradeStopHit or tradeTp3Hit or tradeExpired)
tradeDir := 0
tradeEntry := na
tradeStop := na
tradeBar := na
var line entryLine = na
var line stopLine = na
var line beLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
lineActive = showTradeLines and tradeDir != 0
entryLine := f_line_set(entryLine, lineActive, tradeEntry, color.new(color.white, 0), line.style_solid, 2)
stopLine := f_line_set(stopLine, lineActive, tradeStop, color.new(color.red, 0), line.style_solid, 2)
beLine := f_line_set(beLine, lineActive, be, color.new(color.gray, 0), line.style_dotted, 1)
tp1Line := f_line_set(tp1Line, lineActive, tp1, color.new(color.lime, 0), line.style_solid, 1)
tp2Line := f_line_set(tp2Line, lineActive, tp2, color.new(color.lime, 15), line.style_solid, 1)
tp3Line := f_line_set(tp3Line, lineActive, tp3, color.new(color.lime, 30), line.style_solid, 1)
var int[] pendingDirs = array.new_int()
var float[] pendingEntries = array.new_float()
var float[] pendingStops = array.new_float()
var float[] pendingTargets = array.new_float()
var int[] pendingBars = array.new_int()
var string[] accMarks = array.new_string()
var string[] accCalls = array.new_string()
targetR = activeTarget == "TP3" ? rr3 : activeTarget == "TP2" ? rr2 : rr1
if buySignal or sellSignal
d = buySignal ? 1 : -1
e = close
s = buySignal ? longStop : shortStop
r = math.abs(e - s)
net = r + fee
t = d == 1 ? e + targetR * net + fee : e - targetR * net - fee
array.push(pendingDirs, d)
array.push(pendingEntries, e)
array.push(pendingStops, s)
array.push(pendingTargets, t)
array.push(pendingBars, bar_index)
evalReady = false
evalGood = false
evalBad = false
evalNeutral = false
evalDir = 0
if array.size(pendingDirs) > 0
pendingCount = array.size(pendingDirs)
for j = 0 to pendingCount - 1
i = pendingCount - 1 - j
d = array.get(pendingDirs, i)
s = array.get(pendingStops, i)
t = array.get(pendingTargets, i)
born = array.get(pendingBars, i)
hitTp = d == 1 ? high >= t : low <= t
hitSl = d == 1 ? low <= s : high >= s
both = hitTp and hitSl
expired = bar_index - born >= trackBars
done = hitTp or hitSl or expired
if done
good = hitTp and not hitSl
bad = hitSl and not hitTp or both and bothHitResult == "Wrong"
neutral = both and bothHitResult == "Neutral" or expired and not hitTp and not hitSl or not good and not bad
mark = good ? "✓" : bad ? "✕" : "–"
call = (d == 1 ? "B " : "S ") + activeTarget
array.unshift(accMarks, mark)
array.unshift(accCalls, call)
if array.size(accMarks) > accuracyLogSize
array.pop(accMarks)
array.pop(accCalls)
evalReady := true
evalGood := good
evalBad := bad
evalNeutral := neutral
evalDir := d
array.remove(pendingDirs, i)
array.remove(pendingEntries, i)
array.remove(pendingStops, i)
array.remove(pendingTargets, i)
array.remove(pendingBars, i)
wins = 0
losses = 0
neutrals = 0
if array.size(accMarks) > 0
for i = 0 to array.size(accMarks) - 1
m = array.get(accMarks, i)
wins += m == "✓" ? 1 : 0
losses += m == "✕" ? 1 : 0
neutrals += m == "–" ? 1 : 0
scored = wins + losses
hitRate = scored > 0 ? math.round(wins * 100 / scored) : na
actionTextRaw = buySignal ? f_pe("BUY now", "BUY scalp") : sellSignal ? f_pe("SELL now", "SELL scalp") : tradeDir == 1 ? f_pe("Hold buy", "Hold long") : tradeDir == -1 ? f_pe("Hold sell", "Hold short") : bestLong and longScore >= minScoreAction - 10 and not showActionOnly ? f_pe("Buy setup forming", "Buy area forming") : not bestLong and shortScore >= minScoreAction - 10 and not showActionOnly ? f_pe("Sell setup forming", "Sell area forming") : "WAIT"
reasonLong = (ribbonBull ? f_pe("fast averages point up; ", "Ribbon bull; ") : "") + (bullSweep ? f_pe("low swept then recovered; ", "sell-side sweep; ") : "") + (asiaLowSweep ? f_pe("Asia low swept then recovered; ", "Asia low sweep; ") : "") + (bullObTouch ? f_pe("price is in a buy zone; ", "bull OB; ") : "") + (bullFvgNear ? f_pe("price is near a buy gap; ", "bull FVG; ") : "") + (discount ? f_pe("price is in lower half; ", "discount; ") : "") + (mtfBullCount >= 3 ? f_pe("bigger charts mostly point up; ", "MTF bull; ") : "") + (macroBull > macroBear ? f_pe("outside markets help gold; ", "macro bull; ") : "")
reasonShort = (ribbonBear ? f_pe("fast averages point down; ", "Ribbon bear; ") : "") + (bearSweep ? f_pe("high swept then rejected; ", "buy-side sweep; ") : "") + (asiaHighSweep ? f_pe("Asia high swept then rejected; ", "Asia high sweep; ") : "") + (bearObTouch ? f_pe("price is in a sell zone; ", "bear OB; ") : "") + (bearFvgNear ? f_pe("price is near a sell gap; ", "bear FVG; ") : "") + (premium ? f_pe("price is in upper half; ", "premium; ") : "") + (mtfBearCount >= 3 ? f_pe("bigger charts mostly point down; ", "MTF bear; ") : "") + (macroBear > macroBull ? f_pe("outside markets pressure gold; ", "macro bear; ") : "")
reasonText = showConfluenceReasons ? (bestLong ? reasonLong : reasonShort) : "Reasons hidden"
reasonText := str.length(reasonText) > 0 ? reasonText : f_pe("No strong reason yet", "No strong confluence")
stateBg = actionTextRaw == "BUY scalp" or actionTextRaw == "Hold long" or actionTextRaw == "Buy area forming" ? color.new(color.lime, 15) : actionTextRaw == "SELL scalp" or actionTextRaw == "Hold short" or actionTextRaw == "Sell area forming" ? color.new(color.red, 15) : color.new(color.gray, 25)
stateFg = actionTextRaw == "BUY scalp" or actionTextRaw == "Hold long" or actionTextRaw == "Buy area forming" ? color.black : color.white
biasSideText = buySignal ? f_pe("BUY TRIGGERED", "BUY TRIGGERED") : sellSignal ? f_pe("SELL TRIGGERED", "SELL TRIGGERED") : bestLong ? f_pe("BUY SIDE STRONGER", "BULLISH BIAS") : f_pe("SELL SIDE STRONGER", "BEARISH BIAS")
biasBg = f_bias_bg(bestScore, bestLong)
biasFg = bestLong and bestScore >= 65 ? color.black : color.white
riskBad = not sessionOk or bestScore < minScoreAction or edge < minEdgeAction or tradeDir == 0 and ((bestLong and (not longRiskOk or mtfZoneDangerLong)) or (not bestLong and (not shortRiskOk or mtfZoneDangerShort)))
riskWarn = not riskBad and (ribbonCompressed or edge < minEdgeAction + 4 or macroBull == macroBear or mtfZoneDangerLong or mtfZoneDangerShort)
riskText = riskBad ? "NO TRADE" : riskWarn ? f_pe("WAIT", "CAUTION") : f_pe("CLEAR", "OK")
riskBg = riskBad ? color.new(color.red, 10) : riskWarn ? color.new(warningColour, 10) : color.new(color.lime, 15)
riskFg = riskWarn or not riskBad ? color.black : color.white
sessionText = inAsia ? f_pe("Asia range", "ASIA") : inLondon ? f_pe("London active", "LONDON KZ") : inNY ? f_pe("NY active", "NY KZ") : f_pe("Quiet hours", "OFF SESSION")
sessionBg2 = inLondon or inNY ? color.new(color.orange, 10) : inAsia ? color.new(color.blue, 20) : color.new(color.gray, 35)
structureText = chochBull ? f_pe("Trend flipped up", "CHoCH ↑") : chochBear ? f_pe("Trend flipped down", "CHoCH ↓") : bosBull ? f_pe("Break up", "BOS ↑") : bosBear ? f_pe("Break down", "BOS ↓") : bullSweep ? f_pe("Low swept", "SSL SWEEP") : bearSweep ? f_pe("High swept", "BSL SWEEP") : f_pe("No break yet", "NO BREAK")
structureBg = chochBull or bosBull or bullSweep ? color.new(color.lime, 15) : chochBear or bosBear or bearSweep ? color.new(color.red, 15) : color.new(color.gray, 35)
structureFg = chochBull or bosBull or bullSweep ? color.black : color.white
zoneText2 = premium ? f_pe("Upper half - sell area", "PREMIUM") : discount ? f_pe("Lower half - buy area", "DISCOUNT") : f_pe("Middle - no edge", "EQUILIBRIUM")
zoneBg2 = premium ? color.new(color.red, 25) : discount ? color.new(color.lime, 25) : color.new(color.gray, 35)
zoneFg2 = discount ? color.black : color.white
liquidityText = asiaHighSweep ? f_pe("Asia high rejected", "ASIA HIGH SWEPT") : asiaLowSweep ? f_pe("Asia low recovered", "ASIA LOW SWEPT") : bearSweep ? f_pe("High swept/rejected", "BUY-SIDE SWEPT") : bullSweep ? f_pe("Low swept/recovered", "SELL-SIDE SWEPT") : f_pe("No sweep", "NO SWEEP")
liquidityBg = asiaLowSweep or bullSweep ? color.new(color.lime, 15) : asiaHighSweep or bearSweep ? color.new(color.red, 15) : color.new(color.gray, 35)
liquidityFg = asiaLowSweep or bullSweep ? color.black : color.white
zoneConfluenceText = bullObTouch ? f_pe("Buy block", "BULL OB") : bearObTouch ? f_pe("Sell block", "BEAR OB") : bullFvgNear ? f_pe("Buy gap", "BULL FVG") : bearFvgNear ? f_pe("Sell gap", "BEAR FVG") : f_pe("No block/gap", "NO OB/FVG")
zoneConfluenceBg = bullObTouch or bullFvgNear ? color.new(color.lime, 20) : bearObTouch or bearFvgNear ? color.new(color.red, 20) : color.new(color.gray, 35)
zoneConfluenceFg = bullObTouch or bullFvgNear ? color.black : color.white
macroBg2 = macroBull > macroBear ? color.new(color.lime, 20) : macroBear > macroBull ? color.new(color.red, 20) : color.new(color.gray, 35)
macroFg2 = macroBull > macroBear ? color.black : color.white
tpStatusText = tradeDir == 0 ? "NO LIVE TP" : tradeDir == 1 ? "LONG TP1 " + f_fmt(tp1) : "SHORT TP1 " + f_fmt(tp1)
tpStatusBg = tradeDir == 1 ? color.new(color.lime, 20) : tradeDir == -1 ? color.new(color.red, 20) : color.new(color.gray, 35)
tpStatusFg = tradeDir == 1 ? color.black : color.white
accStripText = scored > 0 ? activeTarget + " " + str.tostring(hitRate) + "% ✓" + str.tostring(wins) + " ✕" + str.tostring(losses) + " -" + str.tostring(neutrals) : "NO TP STATS"
accStripBg = scored == 0 ? color.new(color.gray, 35) : hitRate >= 65 ? color.new(color.lime, 15) : hitRate >= 50 ? color.new(warningColour, 15) : color.new(color.red, 15)
accStripFg = scored > 0 and hitRate >= 50 ? color.black : color.white
macroLongNet = macroBull - macroBear * 0.45
macroShortNet = macroBear - macroBull * 0.45
scoreDepthBias = bestLong ? f_pe("Buy score leads", "BUY LEADS") : f_pe("Sell score leads", "SELL LEADS")
scoreDepthBiasBg = bestLong ? color.new(color.lime, 15) : color.new(color.red, 15)
scoreDepthBiasFg = bestLong ? color.black : color.white
longBlockText = longBlocked ? f_pe("Bad buy location", "BLOCKED") : mtfZoneDangerLong ? f_pe("Sell zone too close", "MTF ZONE") : f_pe("Clear", "CLEAR")
shortBlockText = shortBlocked ? f_pe("Bad sell location", "BLOCKED") : mtfZoneDangerShort ? f_pe("Buy zone too close", "MTF ZONE") : f_pe("Clear", "CLEAR")
longRiskText = longRiskOk ? f_pe("Stop size OK", "RISK OK") : f_pe("Stop size bad", "RISK BAD")
shortRiskText = shortRiskOk ? f_pe("Stop size OK", "RISK OK") : f_pe("Stop size bad", "RISK BAD")
scoreDecisionText = buySignal ? f_pe("BUY now", "BUY FIRED") : sellSignal ? f_pe("SELL now", "SELL FIRED") : riskBad ? "NO TRADE" : riskWarn ? f_pe("Wait for close/confirm", "WAIT CONFIRM") : bestLong ? f_pe("Buy setup forming", "BUY FORMING") : f_pe("Sell setup forming", "SELL FORMING")
scoreDecisionBg = buySignal or sellSignal ? color.new(color.lime, 10) : riskBad ? color.new(color.red, 5) : riskWarn ? color.new(warningColour, 5) : color.new(color.gray, 25)
scoreDecisionFg = riskBad ? color.white : color.black
scoreQualityText = bestScore >= idealScoreAction and edge >= idealEdgeAction ? "IDEAL" : bestScore >= strongScoreAction and edge >= minEdgeAction ? "STRONG" : bestScore >= minScoreAction and edge >= minEdgeAction ? "TRADEABLE" : "WEAK"
scoreQualityBg = scoreQualityText == "IDEAL" ? color.new(color.lime, 5) : scoreQualityText == "STRONG" ? color.new(color.lime, 25) : scoreQualityText == "TRADEABLE" ? color.new(warningColour, 15) : color.new(color.red, 15)
scoreQualityFg = scoreQualityText == "WEAK" ? color.white : color.black
scoreGuideText = showIdealOnScore ? " | " + scoreQualityText + " | Ideal " + str.tostring(idealScoreAction) + "+ / Gap " + str.tostring(idealEdgeAction) + "+" : ""
scoreLineText = f_pe("Buy " + str.tostring(longScore) + " / Sell " + str.tostring(shortScore) + " | Gap " + str.tostring(edge) + scoreGuideText, "B " + str.tostring(longScore) + " / S " + str.tostring(shortScore) + " | E " + str.tostring(edge) + scoreGuideText)
scoreBottomText = scoreQualityText + " " + str.tostring(bestScore) + " / " + f_pe("Gap ", "E ") + str.tostring(edge)
scoreBottomGuideText = f_pe("Good " + str.tostring(minScoreAction) + "+ | Ideal " + str.tostring(idealScoreAction) + "+", "Min " + str.tostring(minScoreAction) + "+ | Ideal " + str.tostring(idealScoreAction) + "+")
mtfReadText = f_pe("Bigger charts: " + str.tostring(mtfBullCount) + " up / " + str.tostring(mtfBearCount) + " down", "B" + str.tostring(mtfBullCount) + "/S" + str.tostring(mtfBearCount))
trendReadText = ribbonBull ? f_pe("Short EMAs above long EMAs", "Ribbon bull") : ribbonBear ? f_pe("Short EMAs below long EMAs", "Ribbon bear") : f_pe("Trend mixed", "Mixed ribbon")
triggerReadText = bullTrigger ? f_pe("Buy trigger appeared", "Bull trigger") : bearTrigger ? f_pe("Sell trigger appeared", "Bear trigger") : f_pe("No trigger candle", "No trigger")
macroReadText = macroBull > macroBear ? f_pe("Outside markets help gold", "Gold +") : macroBear > macroBull ? f_pe("Outside markets pressure gold", "Gold -") : f_pe("Outside markets mixed", "Mixed")
var table scoreDepth = table.new(f_pos(scoreDepthPosition), 4, 11, border_width=1, frame_color=color.new(color.white, 70), frame_width=1)
scoreDepthSize = f_panel_size(scoreDepthTextSize)
if showScoreDepth and barstate.islast
table.clear(scoreDepth, 0, 0, 3, 10)
table.cell(scoreDepth, 0, 0, f_pe("WHY THIS SCORE", "SCORE DEPTH"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 0, "BUY", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 0, "SELL", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 0, "READ", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 1, "Final", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 1, str.tostring(longScore), text_color=longScore >= 65 ? color.black : color.white, bgcolor=f_heat_bg(longScore), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 1, str.tostring(shortScore), text_color=shortScore >= 65 ? color.black : color.white, bgcolor=f_heat_bg(shortScore), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 1, f_pe("Gap " + str.tostring(edge), "E " + str.tostring(edge)), text_color=edge >= minEdgeAction ? color.black : color.white, bgcolor=f_heat_bg(edge * 7), text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 2, f_pe("Trend", "Trend"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 2, str.tostring(trendLongScore), text_color=trendLongScore >= trendShortScore ? color.black : color.white, bgcolor=f_heat_bg(trendLongScore * 3), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 2, str.tostring(trendShortScore), text_color=trendShortScore >= trendLongScore ? color.black : color.white, bgcolor=f_heat_bg(trendShortScore * 3), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 2, trendReadText, text_color=color.white, bgcolor=color.new(color.gray, 35), text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 3, f_pe("Price action", "SMC"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 3, str.tostring(smcLongScore), text_color=smcLongScore >= smcShortScore ? color.black : color.white, bgcolor=f_heat_bg(smcLongScore), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 3, str.tostring(smcShortScore), text_color=smcShortScore >= smcLongScore ? color.black : color.white, bgcolor=f_heat_bg(smcShortScore), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 3, structureText + " / " + liquidityText, text_color=color.white, bgcolor=structureBg, text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 4, f_pe("Range area", "Zone"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 4, discount ? "+8" : "0", text_color=discount ? color.black : color.white, bgcolor=discount ? color.new(color.lime, 20) : color.new(color.gray, 35), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 4, premium ? "+8" : "0", text_color=color.white, bgcolor=premium ? color.new(color.red, 20) : color.new(color.gray, 35), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 4, zoneText2 + " / " + zoneConfluenceText, text_color=zoneFg2, bgcolor=zoneBg2, text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 5, f_pe("Bigger charts", "MTF"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 5, str.tostring(mtfLongScore), text_color=mtfLongScore >= mtfShortScore ? color.black : color.white, bgcolor=f_heat_bg(mtfLongScore * 4), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 5, str.tostring(mtfShortScore), text_color=mtfShortScore >= mtfLongScore ? color.black : color.white, bgcolor=f_heat_bg(mtfShortScore * 4), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 5, mtfReadText, text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 6, "Trigger", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 6, str.tostring(triggerLongScore), text_color=triggerLongScore >= triggerShortScore ? color.black : color.white, bgcolor=f_heat_bg(triggerLongScore * 4), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 6, str.tostring(triggerShortScore), text_color=triggerShortScore >= triggerLongScore ? color.black : color.white, bgcolor=f_heat_bg(triggerShortScore * 4), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 6, triggerReadText, text_color=color.white, bgcolor=bullTrigger ? color.new(color.lime, 20) : bearTrigger ? color.new(color.red, 20) : color.new(color.gray, 35), text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 7, f_pe("Trade filter", "Quality"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 7, str.tostring(qualityLongScore), text_color=qualityLongScore >= qualityShortScore ? color.black : color.white, bgcolor=f_heat_bg(qualityLongScore * 4), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 7, str.tostring(qualityShortScore), text_color=qualityShortScore >= qualityLongScore ? color.black : color.white, bgcolor=f_heat_bg(qualityShortScore * 4), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 7, sessionText + " / " + riskText, text_color=riskFg, bgcolor=riskBg, text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 8, f_pe("Outside markets", "Macro"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 8, str.tostring(math.round(macroLongNet)), text_color=macroLongNet > macroShortNet ? color.black : color.white, bgcolor=f_heat_bg(math.round(math.max(macroLongNet, 0) * 4)), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 8, str.tostring(math.round(macroShortNet)), text_color=macroShortNet > macroLongNet ? color.black : color.white, bgcolor=f_heat_bg(math.round(math.max(macroShortNet, 0) * 4)), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 8, macroReadText, text_color=macroFg2, bgcolor=macroBg2, text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 9, f_pe("Why blocked", "Block/Risk"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 9, longBlockText + " / " + longRiskText, text_color=not longBlocked and not mtfZoneDangerLong and longRiskOk ? color.black : color.white, bgcolor=not longBlocked and not mtfZoneDangerLong and longRiskOk ? color.new(color.lime, 20) : color.new(color.red, 15), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 9, shortBlockText + " / " + shortRiskText, text_color=not shortBlocked and not mtfZoneDangerShort and shortRiskOk ? color.black : color.white, bgcolor=not shortBlocked and not mtfZoneDangerShort and shortRiskOk ? color.new(color.lime, 20) : color.new(color.red, 15), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 9, scoreDepthBias, text_color=scoreDepthBiasFg, bgcolor=scoreDepthBiasBg, text_size=scoreDepthSize)
table.cell(scoreDepth, 0, 10, f_pe("What to do", "Decision"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 1, 10, "Min " + str.tostring(minScoreAction) + " / Ideal " + str.tostring(idealScoreAction), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 2, 10, f_pe("Gap min " + str.tostring(minEdgeAction) + " / ideal " + str.tostring(idealEdgeAction), "Edge " + str.tostring(minEdgeAction) + " / ideal " + str.tostring(idealEdgeAction)), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=scoreDepthSize)
table.cell(scoreDepth, 3, 10, scoreDecisionText, text_color=scoreDecisionFg, bgcolor=scoreDecisionBg, text_size=scoreDepthSize)
if not showScoreDepth and barstate.islast
table.clear(scoreDepth, 0, 0, 3, 10)
barBiasColour = not showCandleColour ? na : buySignal ? color.new(strongBullColour, 0) : sellSignal ? color.new(strongBearColour, 0) : bestLong and bestScore >= 65 ? color.new(weakBullColour, 0) : not bestLong and bestScore >= 65 ? color.new(weakBearColour, 0) : na
barcolor(barBiasColour)
bgBiasColour = not showBackgroundTint ? na : bestLong and bestScore >= minScoreAction ? color.new(strongBullColour, 92) : not bestLong and bestScore >= minScoreAction ? color.new(strongBearColour, 92) : na
bgcolor(bgBiasColour)
plotshape(showLabels and buySignal, title="BUY", style=shape.labelup, location=location.belowbar, color=color.new(color.lime, 0), text="BUY", textcolor=color.black, size=size.small)
plotshape(showLabels and sellSignal, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), text="SELL", textcolor=color.white, size=size.small)
plotshape(showLabels and bullSweep, title="Sell-side Sweep", style=shape.triangleup, location=location.belowbar, color=color.new(color.aqua, 0), text="SSL", textcolor=color.black, size=size.tiny)
plotshape(showLabels and bearSweep, title="Buy-side Sweep", style=shape.triangledown, location=location.abovebar, color=color.new(color.orange, 0), text="BSL", textcolor=color.white, size=size.tiny)
plotshape(showAccuracy and evalReady and evalGood, title="TP Hit", style=shape.circle, location=location.belowbar, color=color.new(color.lime, 0), text="✓", textcolor=color.black, size=size.tiny)
plotshape(showAccuracy and evalReady and evalBad, title="TP Failed", style=shape.circle, location=location.abovebar, color=color.new(color.red, 0), text="✕", textcolor=color.white, size=size.tiny)
plotshape(showAccuracy and evalReady and evalNeutral, title="TP Neutral", style=shape.circle, location=location.belowbar, color=color.new(color.gray, 0), text="–", textcolor=color.white, size=size.tiny)
var table dash = table.new(f_pos(dashboardPosition), 2, 6, border_width=1, frame_color=color.new(color.white, 75), frame_width=1)
dashSize = f_panel_size(dashboardTextSize)
if showDashboard and barstate.islast
table.clear(dash, 0, 0, 1, 5)
table.cell(dash, 0, 0, "Action", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=dashSize)
table.cell(dash, 1, 0, actionTextRaw, text_color=stateFg, bgcolor=stateBg, text_size=dashSize)
table.cell(dash, 0, 1, "Score", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=dashSize)
table.cell(dash, 1, 1, f_short(scoreLineText, dashboardCompact ? 72 : 120), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=dashSize)
table.cell(dash, 0, 2, "Reason", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=dashSize)
table.cell(dash, 1, 2, f_short(reasonText, dashboardCompact ? 46 : 90), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=dashSize)
table.cell(dash, 0, 3, f_pe("Where price is", "Zone"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=dashSize)
table.cell(dash, 1, 3, zoneText2 + " | " + zoneConfluenceText, text_color=zoneFg2, bgcolor=zoneBg2, text_size=dashSize)
table.cell(dash, 0, 4, f_pe("Outside markets", "Macro"), text_color=color.white, bgcolor=color.new(color.black, 0), text_size=dashSize)
table.cell(dash, 1, 4, macroReadText, text_color=macroFg2, bgcolor=macroBg2, text_size=dashSize)
table.cell(dash, 0, 5, "TP / Acc", text_color=color.white, bgcolor=color.new(color.black, 0), text_size=dashSize)
table.cell(dash, 1, 5, tradeDir == 0 ? accStripText : tpStatusText, text_color=tradeDir == 0 ? accStripFg : tpStatusFg, bgcolor=tradeDir == 0 ? accStripBg : tpStatusBg, text_size=dashSize)
var table help = table.new(position.top_left, 1, 1, border_width=1, frame_color=color.new(color.white, 85), frame_width=1)
if barstate.islast
table.clear(help, 0, 0, 0, 0)
showHelpNow = showHelpPanel and helpMode != "Off" and not (hideHelpWhenBottomStrip and showBottomStrip)
if showHelpNow
compactText = labelStyle == "Pro Terms" ? "BUY/SELL = actionable. Forming = wait. TP ticks score BUY/SELL only." : "Buy/Sell now = actionable. Upper half (PREMIUM) favors sells; lower half (DISCOUNT) favors buys. Bigger charts (MTF) = trend agreement."
fullText = labelStyle == "Pro Terms" ? "AurumEdge Mega Help\nBUY/SELL = actionable.\nForming = wait for trigger.\nScore = trend + SMC + OB/FVG + MTF + macro.\nTP ticks score real BUY/SELL calls only." : "AurumEdge Mega Help\nBuy/Sell now = actionable.\nSetup forming = wait for close/trigger.\nPremium = upper half of the current swing range; buys are riskier and sells make more sense.\nDiscount = lower half of the current swing range; sells are riskier and buys make more sense.\nMTF = multi-timeframe / bigger charts; how many higher charts agree with buy or sell.\nDemand = buy zone / support area.\nSupply = sell zone / resistance area.\nFVG = price gap / imbalance area that price may revisit.\nOB = order block / previous strong candle zone.\nBOS = break of structure / price broke a key high or low.\nCHoCH = change of character / possible trend flip.\nLiquidity sweep = price poked through a high or low then came back.\nGap or Edge = distance between Buy score and Sell score, not win probability.\nScore guide: Tradeable = minimum accepted, Strong = better, Ideal = best-quality setup only."
table.cell(help, 0, 0, helpMode == "Full" ? fullText : compactText, text_color=color.white, bgcolor=color.new(color.black, 15), text_size=size.small)
var table acc = table.new(f_pos(accuracyPosition), 8, 2, border_width=1, frame_color=color.new(color.white, 85), frame_width=1)
if showAccuracy and barstate.islast
table.clear(acc, 0, 0, 7, 1)
showAccNow = not (hideAccuracyWhenBottomStrip and showBottomStrip)
if showAccNow
maxAccCells = math.min(8, accuracyLogSize)
for i = 0 to 7
if i < maxAccCells
has = i < array.size(accMarks)
mark = has ? array.get(accMarks, i) : ""
call = has ? array.get(accCalls, i) : ""
bg = mark == "✓" ? color.new(color.lime, 20) : mark == "✕" ? color.new(color.red, 20) : mark == "–" ? color.new(color.gray, 25) : color.new(color.black, 0)
fg = mark == "✓" ? color.black : color.white
table.cell(acc, i, 0, mark, text_color=fg, bgcolor=bg, text_size=size.small)
table.cell(acc, i, 1, call, text_color=color.white, bgcolor=color.new(color.black, 0), text_size=size.small)
var table bottomStrip = table.new(f_bottom_pos(bottomStripPosition), 6, 2, border_width=1, frame_color=color.new(color.white, 75), frame_width=1)
bottomSize = f_panel_size(bottomStripTextSize)
if showBottomStrip and barstate.islast
table.clear(bottomStrip, 0, 0, 5, 1)
ruleText = buySignal ? f_pe("BUY now", "BUY FIRED") : sellSignal ? f_pe("SELL now", "SELL FIRED") : riskBad ? "NO TRADE" : riskWarn ? f_pe("Wait", "WAIT") : f_pe("Setup OK", "SETUP OK")
ruleBg = riskBad ? color.new(color.red, 5) : riskWarn ? color.new(warningColour, 5) : color.new(color.lime, 10)
ruleFg = riskBad ? color.white : color.black
compactScoreText = "B" + str.tostring(longScore) + " / S" + str.tostring(shortScore)
compactMtfText = f_pe("Big TF " + str.tostring(mtfBullCount) + " up/" + str.tostring(mtfBearCount) + " down", "MTF B" + str.tostring(mtfBullCount) + "/S" + str.tostring(mtfBearCount))
compactLiveText = barstate.isconfirmed ? f_pe("Closed", "CLOSED") : f_pe("Live", "LIVE")
table.cell(bottomStrip, 0, 0, ruleText, text_color=ruleFg, bgcolor=ruleBg, text_size=bottomSize)
table.cell(bottomStrip, 1, 0, biasSideText, text_color=biasFg, bgcolor=biasBg, text_size=bottomSize)
table.cell(bottomStrip, 2, 0, compactScoreText, text_color=color.white, bgcolor=color.new(color.black, 0), text_size=bottomSize)
table.cell(bottomStrip, 3, 0, scoreBottomText, text_color=scoreQualityFg, bgcolor=scoreQualityBg, text_size=bottomSize)
table.cell(bottomStrip, 4, 0, riskText, text_color=riskFg, bgcolor=riskBg, text_size=bottomSize)
table.cell(bottomStrip, 5, 0, tradeDir == 0 ? "NO TP" : tpStatusText, text_color=tpStatusFg, bgcolor=tpStatusBg, text_size=bottomSize)
table.cell(bottomStrip, 0, 1, sessionText, text_color=color.white, bgcolor=sessionBg2, text_size=bottomSize)
table.cell(bottomStrip, 1, 1, structureText, text_color=structureFg, bgcolor=structureBg, text_size=bottomSize)
table.cell(bottomStrip, 2, 1, zoneText2, text_color=zoneFg2, bgcolor=zoneBg2, text_size=bottomSize)
table.cell(bottomStrip, 3, 1, scoreBottomGuideText, text_color=color.white, bgcolor=color.new(color.black, 0), text_size=bottomSize)
table.cell(bottomStrip, 4, 1, compactMtfText, text_color=color.white, bgcolor=color.new(color.black, 0), text_size=bottomSize)
table.cell(bottomStrip, 5, 1, compactLiveText, text_color=color.white, bgcolor=barstate.isconfirmed ? color.new(color.gray, 30) : color.new(warningColour, 20), text_size=bottomSize)
if not showBottomStrip and barstate.islast
table.clear(bottomStrip, 0, 0, 5, 1)
alertcondition(buySignal, "AurumEdge Mega BUY", "AurumEdge Mega XAUUSD BUY scalp")
alertcondition(sellSignal, "AurumEdge Mega SELL", "AurumEdge Mega XAUUSD SELL scalp")
alertcondition(bullSweep, "AurumEdge Mega Sell-side Liquidity Sweep", "XAUUSD sell-side liquidity sweep detected")
alertcondition(bearSweep, "AurumEdge Mega Buy-side Liquidity Sweep", "XAUUSD buy-side liquidity sweep detected")
alertcondition(chochBull, "AurumEdge Mega Bullish CHoCH", "Bullish CHoCH detected")
alertcondition(chochBear, "AurumEdge Mega Bearish CHoCH", "Bearish CHoCH detected")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment