ajiim

🎁

Oct 7th, 2026
1,526
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.92 KB | None | 0 0
  1. //@version=6
  2. indicator("Stoic Edge Compass", shorttitle = "Stoic Edge Compass", overlay = true, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500, max_bars_back = 5000)
  3.  
  4. const string G_STR = "Market Structure"
  5. const string G_RNG = "Range Filter"
  6. const string G_TRD = "Trend Ribbon & 200 EMA"
  7. const string G_DOT = "Context Dots & Momentum Candles"
  8. const string G_LVL = "Structure Levels"
  9. const string G_SBS = "SBS Triangles"
  10. const string G_SR = "Dynamic Support/Resistance"
  11. const string G_PNL = "Status Panel"
  12. const string G_MTF = "Multi-Timeframe Alignment"
  13. const string G_CAP = "Chart Captions"
  14. const string G_COL = "Colors"
  15.  
  16. i_primaryLen = input.int(2, "Primary Swing Length", minval = 1, maxval = 50, group = G_STR, tooltip = "Causal swing length defining the PRIMARY (outer) structure on the selected chart.")
  17. i_localLen = input.int(1, "Local Swing Length", minval = 1, maxval = 20, group = G_STR, tooltip = "Causal swing length defining the LOCAL (nearest internal) structure.")
  18. i_acceptBars = input.int(1, "Accepted Break Closes", minval = 1, maxval = 10, group = G_STR, tooltip = "Consecutive closes beyond Structure Fail required before the PRIMARY hypothesis is rejected.")
  19. i_pbDepth = input.float(0.618, "Orderly Pullback Max Depth", minval = 0.1, maxval = 1.0, step = 0.01, group = G_STR, tooltip = "Maximum retracement of the active leg that still qualifies as an orderly PULLBACK.")
  20. i_turnBreaks = input.int(2, "Turn Watch Counter Breaks", minval = 1, maxval = 5, group = G_STR, tooltip = "Consecutive LOCAL breaks against PRIMARY treated as failure evidence (TURN WATCH).")
  21. i_useStd = input.bool(true, "Use Standard OHLC on Heikin Ashi Charts", group = G_STR)
  22.  
  23. i_rngLen = input.int(30, "Range Lookback", minval = 10, maxval = 200, group = G_RNG)
  24. i_rngFlips = input.int(4, "Local Flips to Establish Range", minval = 2, maxval = 20, group = G_RNG)
  25. i_rngWidth = input.float(3.5, "Max Range Width (ATR)", minval = 0.5, maxval = 20.0, step = 0.1, group = G_RNG)
  26. i_rngExit = input.int(2, "Closes Outside to Exit Range", minval = 1, maxval = 10, group = G_RNG)
  27.  
  28. i_showRibbon = input.bool(true, "Show Trend Ribbon", group = G_TRD)
  29. i_ribFastLen = input.int(8, "Ribbon Fast", minval = 1, inline = "rib", group = G_TRD)
  30. i_ribSlowLen = input.int(21, "Slow", minval = 2, inline = "rib", group = G_TRD)
  31. i_showEma = input.bool(true, "Show 200 EMA", group = G_TRD)
  32. i_emaLen = input.int(200, "EMA Length", minval = 1, group = G_TRD)
  33. i_emaWidth = input.int(3, "EMA Width", minval = 1, maxval = 4, group = G_TRD)
  34.  
  35. i_showDots = input.bool(true, "Show Context Dots", group = G_DOT)
  36. i_momCandles = input.bool(true, "Momentum Candles", group = G_DOT)
  37. i_exhRsiLen = input.int(14, "Exhaustion RSI Length", minval = 2, group = G_DOT)
  38. i_exhOB = input.float(75.0, "Exhaustion RSI Upper", minval = 50, maxval = 100, group = G_DOT)
  39. i_exhOS = input.float(25.0, "Exhaustion RSI Lower", minval = 0, maxval = 50, group = G_DOT)
  40. i_exhStretch = input.float(2.0, "Exhaustion Stretch (ATR from Ribbon)", minval = 0.1, step = 0.1, group = G_DOT)
  41.  
  42. i_showTrail = input.bool(false, "Show Structure Fail (Grey Trailing Line)", group = G_LVL)
  43. i_showNext = input.bool(false, "Show Next Test (Dashed Orange Line)", group = G_LVL)
  44. i_showLvlLbl = input.bool(true, "Show Level Labels", group = G_LVL)
  45.  
  46. i_showSbs = input.bool(true, "Show SBS Triangles", group = G_SBS)
  47. i_sbsLen = input.int(5, "Liquidity Swing Length", minval = 1, maxval = 30, group = G_SBS)
  48. i_sbsMax = input.int(10, "Max Remembered Levels", minval = 1, maxval = 50, group = G_SBS)
  49. i_sbsAge = input.int(300, "Max Level Age (Bars)", minval = 10, maxval = 5000, group = G_SBS)
  50. i_sbsWick = input.float(0.3, "Min Rejection Wick (% of Range)", minval = 0.0, maxval = 1.0, step = 0.05, group = G_SBS)
  51.  
  52. i_showSr = input.bool(true, "Show Dynamic Support/Resistance", group = G_SR)
  53. i_srLen = input.int(15, "Pivot Strength", minval = 2, maxval = 100, group = G_SR)
  54. i_srMax = input.int(3, "Max Zones", minval = 1, maxval = 20, group = G_SR)
  55. i_srHeight = input.float(0.25, "Zone Height (ATR)", minval = 0.05, step = 0.05, group = G_SR)
  56. i_srMerge = input.float(0.5, "Merge Distance (ATR)", minval = 0.05, step = 0.05, group = G_SR)
  57.  
  58. i_showPanel = input.bool(true, "Show Status Panel", group = G_PNL)
  59. i_panelPos = input.string("Top Right", "Position", options = ["Top Right", "Top Left", "Top Center", "Middle Right", "Bottom Right", "Bottom Left"], group = G_PNL)
  60. i_panelSize = input.string("Small", "Text Size", options = ["Tiny", "Small", "Normal"], group = G_PNL)
  61.  
  62. i_showMtf = input.bool(false, "Show Multi-Timeframe Table", group = G_MTF)
  63. i_mtfPos = input.string("Bottom Right", "Position", options = ["Top Right", "Top Left", "Top Center", "Middle Right", "Bottom Right", "Bottom Left"], group = G_MTF)
  64. i_tf1 = input.timeframe("5", "Timeframe 1", group = G_MTF)
  65. i_tf2 = input.timeframe("15", "Timeframe 2", group = G_MTF)
  66. i_tf3 = input.timeframe("60", "Timeframe 3", group = G_MTF)
  67. i_tf4 = input.timeframe("240", "Timeframe 4", group = G_MTF)
  68.  
  69. i_showCaps = input.bool(false, "Show Chart Captions (Follow the Trend / Stay Out of the Chop)", group = G_CAP)
  70.  
  71. i_colBull = input.color(#12B76A, "Bullish", inline = "c1", group = G_COL)
  72. i_colBear = input.color(#E5404F, "Bearish", inline = "c1", group = G_COL)
  73. i_colWait = input.color(#F7A531, "Wait / Caution", inline = "c2", group = G_COL)
  74. i_colNeutral = input.color(#9598A1, "Neutral", inline = "c2", group = G_COL)
  75. i_colSr = input.color(#E2703A, "Support/Resistance", inline = "c3", group = G_COL)
  76. i_colNext = input.color(#F7931A, "Next Test", inline = "c3", group = G_COL)
  77. i_colTrail = input.color(#8C8C8C, "Structure Fail", inline = "c4", group = G_COL)
  78. i_colPanelBg = input.color(#131722, "Panel Background", inline = "c4", group = G_COL)
  79.  
  80. const int PH_ALIGNED = 1
  81. const int PH_PULLBACK = 2
  82. const int PH_ROTATION = 3
  83. const int PH_TURN = 4
  84. const int PH_BUILDING = 5
  85.  
  86. type Zone
  87. box bx
  88. float mid
  89. int touches
  90.  
  91. f_pos(string p) =>
  92. switch p
  93. "Top Left" => position.top_left
  94. "Top Center" => position.top_center
  95. "Middle Right" => position.middle_right
  96. "Bottom Right" => position.bottom_right
  97. "Bottom Left" => position.bottom_left
  98. => position.top_right
  99.  
  100. f_size(string s) =>
  101. switch s
  102. "Tiny" => size.tiny
  103. "Normal" => size.normal
  104. => size.small
  105.  
  106. f_biasTxt(int b) =>
  107. b == 1 ? "BULLISH" : b == -1 ? "BEARISH" : "NEUTRAL"
  108.  
  109. f_biasCol(int b, color bu, color be, color ne) =>
  110. b == 1 ? bu : b == -1 ? be : ne
  111.  
  112. f_phaseTxt(int p) =>
  113. switch p
  114. PH_ALIGNED => "ALIGNED"
  115. PH_PULLBACK => "PULLBACK"
  116. PH_ROTATION => "ROTATION"
  117. PH_TURN => "TURN WATCH"
  118. => "BUILDING"
  119.  
  120. f_structBias(int len) =>
  121. var int b = 0
  122. var float sh = na
  123. var float sl = na
  124. float phv = ta.pivothigh(high, len, len)
  125. float plv = ta.pivotlow(low, len, len)
  126. if not na(phv)
  127. sh := phv
  128. if not na(plv)
  129. sl := plv
  130. if not na(sh) and close > sh
  131. b := 1
  132. sh := na
  133. else if not na(sl) and close < sl
  134. b := -1
  135. sl := na
  136. b
  137.  
  138. f_mtf(int len, int emaLen) =>
  139. int b = f_structBias(len)
  140. float e = ta.ema(close, emaLen)
  141. int et = close > e ? 1 : -1
  142. [b[1], et[1]]
  143.  
  144. f_addZone(array<Zone> zs, float level, int leftBar, float atrv, float mergeAtr, float heightAtr, int maxZones, color col) =>
  145. bool merged = false
  146. float half = heightAtr * atrv * 0.5
  147. if zs.size() > 0
  148. for z in zs
  149. if not merged and math.abs(level - z.mid) <= mergeAtr * atrv
  150. z.mid := (z.mid * z.touches + level) / (z.touches + 1)
  151. z.touches := z.touches + 1
  152. z.bx.set_top(z.mid + half)
  153. z.bx.set_bottom(z.mid - half)
  154. merged := true
  155. break
  156. if not merged
  157. box bxNew = box.new(leftBar, level + half, bar_index, level - half, border_color = color.new(col, 20), border_width = 1, bgcolor = color.new(col, 88), extend = extend.both)
  158. zs.push(Zone.new(bxNew, level, 1))
  159. if zs.size() > maxZones
  160. Zone old = zs.shift()
  161. old.bx.delete()
  162. merged
  163.  
  164. string stdTicker = ticker.standard(syminfo.tickerid)
  165. bool useStdData = i_useStd and chart.is_heikinashi
  166. [stdO, stdH, stdL, stdC] = if useStdData
  167. request.security(stdTicker, timeframe.period, [open, high, low, close], lookahead = barmerge.lookahead_off)
  168. else
  169. [float(na), float(na), float(na), float(na)]
  170. float o = useStdData ? nz(stdO, open) : open
  171. float h = useStdData ? nz(stdH, high) : high
  172. float l = useStdData ? nz(stdL, low) : low
  173. float c = useStdData ? nz(stdC, close) : close
  174.  
  175. float trueRng = math.max(h - l, math.abs(h - nz(c[1], c)), math.abs(l - nz(c[1], c)))
  176. float atr = nz(ta.rma(trueRng, 14), h - l)
  177.  
  178. float ribFast = ta.ema(c, i_ribFastLen)
  179. float ribSlow = ta.ema(c, i_ribSlowLen)
  180. float ema200 = ta.ema(c, i_emaLen)
  181. float rsi = ta.rsi(c, i_exhRsiLen)
  182. bool conf = barstate.isconfirmed
  183.  
  184. float lPH = ta.pivothigh(h, i_localLen, i_localLen)
  185. float lPL = ta.pivotlow(l, i_localLen, i_localLen)
  186.  
  187. var int lBias = 0
  188. var float lHigh = na
  189. var float lLow = na
  190. bool localBullBreak = false
  191. bool localBearBreak = false
  192.  
  193. if not na(lPH)
  194. lHigh := lPH
  195. if not na(lPL)
  196. lLow := lPL
  197. if not na(lHigh) and c > lHigh
  198. localBullBreak := true
  199. lBias := 1
  200. lHigh := na
  201. else if not na(lLow) and c < lLow
  202. localBearBreak := true
  203. lBias := -1
  204. lLow := na
  205.  
  206. int prevLBias = nz(lBias[1])
  207. bool localFlip = lBias != prevLBias and prevLBias != 0
  208.  
  209. float pPH = ta.pivothigh(h, i_primaryLen, i_primaryLen)
  210. float pPL = ta.pivotlow(l, i_primaryLen, i_primaryLen)
  211. float lowAfterPivot = ta.lowest(l, i_primaryLen)
  212. float highAfterPivot = ta.highest(h, i_primaryLen)
  213.  
  214. var int pBias = 0
  215. var bool pEstablished = false
  216. var float swingHigh = na
  217. var float swingLow = na
  218. var float lowSinceSwingHigh = na
  219. var float highSinceSwingLow = na
  220. var float failLevel = na
  221. var float legHigh = na
  222. var float legLow = na
  223. var int breakCount = 0
  224. var bool monitoring = false
  225.  
  226. bool primaryBullBos = false
  227. bool primaryBearBos = false
  228. bool primaryFlipBull = false
  229. bool primaryFlipBear = false
  230. bool monitorStart = false
  231.  
  232. lowSinceSwingHigh := na(lowSinceSwingHigh) ? l : math.min(lowSinceSwingHigh, l)
  233. highSinceSwingLow := na(highSinceSwingLow) ? h : math.max(highSinceSwingLow, h)
  234. legHigh := na(legHigh) ? h : math.max(legHigh, h)
  235. legLow := na(legLow) ? l : math.min(legLow, l)
  236.  
  237. if not na(pPH)
  238. swingHigh := pPH
  239. lowSinceSwingHigh := lowAfterPivot
  240. if not na(pPL)
  241. swingLow := pPL
  242. highSinceSwingLow := highAfterPivot
  243.  
  244. if pBias == 0
  245. if not na(swingHigh) and c > swingHigh
  246. pBias := 1
  247. pEstablished := false
  248. failLevel := nz(swingLow, legLow)
  249. legHigh := h
  250. swingHigh := na
  251. primaryFlipBull := true
  252. else if not na(swingLow) and c < swingLow
  253. pBias := -1
  254. pEstablished := false
  255. failLevel := nz(swingHigh, legHigh)
  256. legLow := l
  257. swingLow := na
  258. primaryFlipBear := true
  259. else if pBias == 1
  260. if not na(swingHigh) and c > swingHigh
  261. primaryBullBos := true
  262. failLevel := lowSinceSwingHigh
  263. swingHigh := na
  264. breakCount := 0
  265. monitoring := false
  266. pEstablished := true
  267. if not na(failLevel) and c < failLevel
  268. if not monitoring
  269. monitorStart := true
  270. monitoring := true
  271. breakCount += 1
  272. if breakCount >= i_acceptBars
  273. pBias := -1
  274. pEstablished := false
  275. failLevel := legHigh
  276. legLow := l
  277. breakCount := 0
  278. monitoring := false
  279. primaryFlipBear := true
  280. swingLow := not na(swingLow) and swingLow < c ? swingLow : na
  281. else if monitoring
  282. monitoring := false
  283. breakCount := 0
  284. else
  285. if not na(swingLow) and c < swingLow
  286. primaryBearBos := true
  287. failLevel := highSinceSwingLow
  288. swingLow := na
  289. breakCount := 0
  290. monitoring := false
  291. pEstablished := true
  292. if not na(failLevel) and c > failLevel
  293. if not monitoring
  294. monitorStart := true
  295. monitoring := true
  296. breakCount += 1
  297. if breakCount >= i_acceptBars
  298. pBias := 1
  299. pEstablished := false
  300. failLevel := legLow
  301. legHigh := h
  302. breakCount := 0
  303. monitoring := false
  304. primaryFlipBull := true
  305. swingHigh := not na(swingHigh) and swingHigh > c ? swingHigh : na
  306. else if monitoring
  307. monitoring := false
  308. breakCount := 0
  309.  
  310. float nextTest = pBias == 1 ? swingHigh : pBias == -1 ? swingLow : na
  311.  
  312. var int counterBreaks = 0
  313. if primaryFlipBull or primaryFlipBear
  314. counterBreaks := 0
  315. if pBias == 1
  316. if localBearBreak
  317. counterBreaks += 1
  318. else if localBullBreak
  319. counterBreaks := 0
  320. else if pBias == -1
  321. if localBullBreak
  322. counterBreaks += 1
  323. else if localBearBreak
  324. counterBreaks := 0
  325.  
  326. float flipCount = math.sum(localFlip ? 1.0 : 0.0, i_rngLen)
  327. float rngHi = ta.highest(h, i_rngLen)
  328. float rngLo = ta.lowest(l, i_rngLen)
  329. bool compressed = rngHi - rngLo <= i_rngWidth * atr
  330. bool rangeCond = bar_index >= i_rngLen and (nz(flipCount) >= i_rngFlips or compressed)
  331.  
  332. var bool inRange = false
  333. var float rangeTop = na
  334. var float rangeBot = na
  335. var int outsideCount = 0
  336. var int rangeExitBar = -100000
  337. bool rangeEstablished = false
  338.  
  339. if not inRange
  340. if rangeCond and bar_index - rangeExitBar >= math.round(i_rngLen / 2)
  341. inRange := true
  342. rangeTop := rngHi
  343. rangeBot := rngLo
  344. outsideCount := 0
  345. rangeEstablished := true
  346. else
  347. if c > rangeTop or c < rangeBot
  348. outsideCount += 1
  349. if outsideCount >= i_rngExit
  350. inRange := false
  351. outsideCount := 0
  352. rangeExitBar := bar_index
  353. else
  354. outsideCount := 0
  355.  
  356. float legRange = pBias == 1 ? legHigh - failLevel : pBias == -1 ? failLevel - legLow : na
  357. float retrace = 0.0
  358. if not na(legRange) and legRange > 0
  359. retrace := pBias == 1 ? (legHigh - c) / legRange : (c - legLow) / legRange
  360.  
  361. int phaseId = PH_BUILDING
  362. if pBias == 0 or not pEstablished
  363. phaseId := PH_BUILDING
  364. else if monitoring or counterBreaks >= i_turnBreaks
  365. phaseId := PH_TURN
  366. else if inRange
  367. phaseId := PH_ROTATION
  368. else if lBias == pBias
  369. phaseId := PH_ALIGNED
  370. else if retrace <= i_pbDepth
  371. phaseId := PH_PULLBACK
  372. else
  373. phaseId := PH_ROTATION
  374.  
  375. int focus = pEstablished and pBias != 0 and not inRange and (phaseId == PH_ALIGNED or phaseId == PH_PULLBACK) ? pBias : 0
  376. int prevFocus = nz(focus[1])
  377.  
  378. bool exhUp = nz(rsi) > i_exhOB and c - ribSlow > i_exhStretch * atr
  379. bool exhDn = nz(rsi, 50) < i_exhOS and ribSlow - c > i_exhStretch * atr
  380. bool exhaustion = exhUp or exhDn
  381. bool exhaustionStart = exhaustion and not exhaustion[1]
  382.  
  383. bool focusBuyStart = focus == 1 and prevFocus != 1
  384. bool focusSellStart = focus == -1 and prevFocus != -1
  385. bool focusToWait = focus == 0 and prevFocus != 0
  386.  
  387. bool greenEvent = focus == 1 and (focusBuyStart or primaryBullBos or (localBullBreak and prevLBias != 1))
  388. bool redEvent = focus == -1 and (focusSellStart or primaryBearBos or (localBearBreak and prevLBias != -1))
  389. bool yellowEvent = (focusToWait or rangeEstablished or exhaustionStart or monitorStart) and not greenEvent and not redEvent
  390.  
  391. bool greenDot = greenEvent and conf
  392. bool redDot = redEvent and conf
  393. bool yellowDot = yellowEvent and conf
  394.  
  395. float greenY = math.min(l, ribSlow)
  396. float redY = math.max(h, ribSlow)
  397. float yellowY = exhUp ? h + atr * 0.3 : exhDn ? l - atr * 0.3 : c >= ribSlow ? h + atr * 0.3 : l - atr * 0.3
  398.  
  399. color candleCol = na
  400. if i_momCandles
  401. if exhaustion
  402. candleCol := i_colWait
  403. else if focus == 1 and c > o
  404. candleCol := i_colBull
  405. else if focus == -1 and c < o
  406. candleCol := i_colBear
  407. else
  408. candleCol := i_colNeutral
  409.  
  410. color ribCol = focus == 1 ? color.new(i_colBull, 70) : focus == -1 ? color.new(i_colBear, 70) : inRange ? color.new(i_colNeutral, 80) : lBias == 1 ? color.new(i_colBull, 85) : lBias == -1 ? color.new(i_colBear, 85) : color.new(i_colNeutral, 85)
  411.  
  412. float sPH = ta.pivothigh(h, i_sbsLen, i_sbsLen)
  413. float sPL = ta.pivotlow(l, i_sbsLen, i_sbsLen)
  414.  
  415. var array<float> liqHighs = array.new<float>()
  416. var array<int> liqHighBars = array.new<int>()
  417. var array<float> liqLows = array.new<float>()
  418. var array<int> liqLowBars = array.new<int>()
  419.  
  420. if not na(sPH)
  421. liqHighs.push(sPH)
  422. liqHighBars.push(bar_index - i_sbsLen)
  423. if liqHighs.size() > i_sbsMax
  424. liqHighs.shift()
  425. liqHighBars.shift()
  426. if not na(sPL)
  427. liqLows.push(sPL)
  428. liqLowBars.push(bar_index - i_sbsLen)
  429. if liqLows.size() > i_sbsMax
  430. liqLows.shift()
  431. liqLowBars.shift()
  432.  
  433. float barRng = h - l
  434. bool bullWick = barRng > 0 and math.min(o, c) - l >= i_sbsWick * barRng
  435. bool bearWick = barRng > 0 and h - math.max(o, c) >= i_sbsWick * barRng
  436. bool sbsBull = false
  437. bool sbsBear = false
  438.  
  439. if liqLows.size() > 0
  440. for i = liqLows.size() - 1 to 0
  441. float lvl = liqLows.get(i)
  442. int age = bar_index - liqLowBars.get(i)
  443. bool swept = age > i_sbsLen and l < lvl and c > lvl and c > o and bullWick
  444. bool invalid = c < lvl
  445. if swept
  446. sbsBull := true
  447. if swept or invalid or age > i_sbsAge
  448. liqLows.remove(i)
  449. liqLowBars.remove(i)
  450.  
  451. if liqHighs.size() > 0
  452. for i = liqHighs.size() - 1 to 0
  453. float lvl = liqHighs.get(i)
  454. int age = bar_index - liqHighBars.get(i)
  455. bool swept = age > i_sbsLen and h > lvl and c < lvl and c < o and bearWick
  456. bool invalid = c > lvl
  457. if swept
  458. sbsBear := true
  459. if swept or invalid or age > i_sbsAge
  460. liqHighs.remove(i)
  461. liqHighBars.remove(i)
  462.  
  463. bool sbsBullSig = sbsBull and conf
  464. bool sbsBearSig = sbsBear and conf
  465.  
  466. float srPH = ta.pivothigh(h, i_srLen, i_srLen)
  467. float srPL = ta.pivotlow(l, i_srLen, i_srLen)
  468. var array<Zone> zones = array.new<Zone>()
  469.  
  470. if i_showSr
  471. if not na(srPH)
  472. f_addZone(zones, srPH, bar_index - i_srLen, atr, i_srMerge, i_srHeight, i_srMax, i_colSr)
  473. if not na(srPL)
  474. f_addZone(zones, srPL, bar_index - i_srLen, atr, i_srMerge, i_srHeight, i_srMax, i_colSr)
  475.  
  476. pRibFast = plot(i_showRibbon ? ribFast : na, "Ribbon Fast", color.new(color.black, 100), editable = false, display = display.pane)
  477. pRibSlow = plot(i_showRibbon ? ribSlow : na, "Ribbon Slow", color.new(color.black, 100), editable = false, display = display.pane)
  478. fill(pRibFast, pRibSlow, color = i_showRibbon ? ribCol : na, title = "Trend Ribbon", editable = false)
  479.  
  480. plot(i_showEma ? ema200 : na, "200 EMA", c > ema200 ? i_colBull : i_colBear, linewidth = i_emaWidth)
  481.  
  482. float trailVal = failLevel == failLevel[1] ? failLevel : na
  483. plot(i_showTrail ? trailVal : na, "Structure Fail", i_colTrail, 1, plot.style_linebr, editable = false)
  484.  
  485. var line ntLine = na
  486. if i_showNext
  487. if na(nextTest)
  488. ntLine := na
  489. else if na(nextTest[1]) or nextTest != nextTest[1] or na(ntLine)
  490. ntLine := line.new(bar_index, nextTest, bar_index + 1, nextTest, color = i_colNext, style = line.style_dashed, width = 1)
  491. else
  492. ntLine.set_x2(bar_index)
  493.  
  494. var label failLbl = na
  495. var label nextLbl = na
  496. if barstate.islast
  497. label.delete(failLbl)
  498. label.delete(nextLbl)
  499. if i_showLvlLbl and i_showTrail and not na(failLevel)
  500. failLbl := label.new(bar_index + 2, failLevel, "Structure Fail", style = label.style_label_left, color = color.new(color.white, 100), textcolor = i_colTrail, size = size.small)
  501. if i_showLvlLbl and i_showNext and not na(nextTest)
  502. nextLbl := label.new(bar_index + 2, nextTest, "Next Test", style = label.style_label_left, color = color.new(color.white, 100), textcolor = i_colNext, size = size.small)
  503.  
  504. plot(i_showDots and greenDot ? greenY : na, "Bullish Dot", i_colBull, 5, plot.style_circles, editable = false)
  505. plot(i_showDots and redDot ? redY : na, "Bearish Dot", i_colBear, 5, plot.style_circles, editable = false)
  506. plot(i_showDots and yellowDot ? yellowY : na, "Wait Dot", i_colWait, 5, plot.style_circles, editable = false)
  507.  
  508. plotshape(i_showSbs and sbsBullSig, "SBS Bullish", shape.triangleup, location.belowbar, i_colBull, size = size.tiny, editable = false)
  509. plotshape(i_showSbs and sbsBearSig, "SBS Bearish", shape.triangledown, location.abovebar, i_colBear, size = size.tiny, editable = false)
  510.  
  511. barcolor(i_momCandles ? candleCol : na, title = "Momentum Candles", editable = false)
  512.  
  513. if i_showCaps and conf
  514. if rangeEstablished
  515. label.new(bar_index, h + atr * 1.2, "Stay Out of the Chop", style = label.style_none, textcolor = i_colNeutral, size = size.normal)
  516. if focusBuyStart
  517. label.new(bar_index, l - atr * 1.2, "Follow the Trend", style = label.style_none, textcolor = i_colBull, size = size.normal)
  518. if focusSellStart
  519. label.new(bar_index, h + atr * 1.2, "Follow the Trend", style = label.style_none, textcolor = i_colBear, size = size.normal)
  520.  
  521. var table panel = i_showPanel ? table.new(f_pos(i_panelPos), 2, 4, bgcolor = color.new(i_colPanelBg, 10), frame_color = color.new(i_colNeutral, 60), frame_width = 1, border_color = color.new(i_colNeutral, 80), border_width = 1) : na
  522.  
  523. if i_showPanel and barstate.islast
  524. string szP = f_size(i_panelSize)
  525. string focusTx = focus == 1 ? "LOOK FOR BUYS" : focus == -1 ? "LOOK FOR SELLS" : "WAIT"
  526. color focusCl = focus == 1 ? i_colBull : focus == -1 ? i_colBear : i_colWait
  527. string primTx = pBias == 0 ? "BUILDING" : f_biasTxt(pBias) + (pEstablished ? "" : " (PROVISIONAL)")
  528. color primCl = pBias == 0 or not pEstablished ? i_colNeutral : f_biasCol(pBias, i_colBull, i_colBear, i_colNeutral)
  529. color dirCl = pBias == 1 ? i_colBull : i_colBear
  530. color phaseCl = phaseId == PH_ALIGNED ? dirCl : phaseId == PH_PULLBACK ? color.new(dirCl, 30) : phaseId == PH_TURN ? i_colWait : i_colNeutral
  531. panel.cell(0, 0, "FOCUS", text_color = color.white, text_size = szP, text_halign = text.align_left)
  532. panel.cell(1, 0, focusTx, text_color = color.white, bgcolor = focusCl, text_size = szP)
  533. panel.cell(0, 1, "PRIMARY", text_color = color.white, text_size = szP, text_halign = text.align_left)
  534. panel.cell(1, 1, primTx, text_color = primCl, text_size = szP)
  535. panel.cell(0, 2, "LOCAL", text_color = color.white, text_size = szP, text_halign = text.align_left)
  536. panel.cell(1, 2, f_biasTxt(lBias), text_color = f_biasCol(lBias, i_colBull, i_colBear, i_colNeutral), text_size = szP)
  537. panel.cell(0, 3, "PHASE", text_color = color.white, text_size = szP, text_halign = text.align_left)
  538. panel.cell(1, 3, f_phaseTxt(phaseId), text_color = phaseCl, text_size = szP)
  539.  
  540. [mb1, me1] = if i_showMtf
  541. request.security(stdTicker, i_tf1, f_mtf(i_primaryLen, i_emaLen), lookahead = barmerge.lookahead_on)
  542. else
  543. [int(na), int(na)]
  544. [mb2, me2] = if i_showMtf
  545. request.security(stdTicker, i_tf2, f_mtf(i_primaryLen, i_emaLen), lookahead = barmerge.lookahead_on)
  546. else
  547. [int(na), int(na)]
  548. [mb3, me3] = if i_showMtf
  549. request.security(stdTicker, i_tf3, f_mtf(i_primaryLen, i_emaLen), lookahead = barmerge.lookahead_on)
  550. else
  551. [int(na), int(na)]
  552. [mb4, me4] = if i_showMtf
  553. request.security(stdTicker, i_tf4, f_mtf(i_primaryLen, i_emaLen), lookahead = barmerge.lookahead_on)
  554. else
  555. [int(na), int(na)]
  556.  
  557. var table mtf = i_showMtf ? table.new(f_pos(i_mtfPos), 4, 7, bgcolor = color.new(i_colPanelBg, 10), frame_color = color.new(i_colNeutral, 60), frame_width = 1, border_color = color.new(i_colNeutral, 80), border_width = 1) : na
  558.  
  559. if i_showMtf and barstate.islast
  560. string szM = f_size(i_panelSize)
  561. array<string> tfs = array.from("Chart", i_tf1, i_tf2, i_tf3, i_tf4)
  562. array<int> bs = array.from(pBias, nz(mb1), nz(mb2), nz(mb3), nz(mb4))
  563. array<int> es = array.from(c > ema200 ? 1 : -1, nz(me1), nz(me2), nz(me3), nz(me4))
  564. mtf.cell(0, 0, "TF", text_color = color.white, text_size = szM)
  565. mtf.cell(1, 0, "STRUCTURE", text_color = color.white, text_size = szM)
  566. mtf.cell(2, 0, "200 EMA", text_color = color.white, text_size = szM)
  567. mtf.cell(3, 0, "ALIGN", text_color = color.white, text_size = szM)
  568. int bullCount = 0
  569. int bearCount = 0
  570. for i = 0 to 4
  571. int bv = bs.get(i)
  572. int ev = es.get(i)
  573. bullCount += bv == 1 ? 1 : 0
  574. bearCount += bv == -1 ? 1 : 0
  575. bool aligned = bv != 0 and bv == ev
  576. mtf.cell(0, i + 1, tfs.get(i), text_color = color.white, text_size = szM)
  577. mtf.cell(1, i + 1, f_biasTxt(bv), text_color = f_biasCol(bv, i_colBull, i_colBear, i_colNeutral), text_size = szM)
  578. mtf.cell(2, i + 1, ev == 1 ? "ABOVE" : ev == -1 ? "BELOW" : "-", text_color = f_biasCol(ev, i_colBull, i_colBear, i_colNeutral), text_size = szM)
  579. mtf.cell(3, i + 1, aligned ? "ALIGNED" : "MIXED", text_color = aligned ? f_biasCol(bv, i_colBull, i_colBear, i_colNeutral) : i_colWait, text_size = szM)
  580. string sumTx = bullCount >= 4 ? "BULLISH ALIGNMENT" : bearCount >= 4 ? "BEARISH ALIGNMENT" : "NO ALIGNMENT"
  581. color sumCl = bullCount >= 4 ? i_colBull : bearCount >= 4 ? i_colBear : i_colWait
  582. mtf.cell(0, 6, sumTx, text_color = color.white, bgcolor = sumCl, text_size = szM)
  583. mtf.merge_cells(0, 6, 3, 6)
  584.  
  585. alertcondition(greenDot, "Stoic Edge Compass - Green", "Stoic Edge Compass: Green dot - FOCUS LOOK FOR BUYS on {{ticker}} {{interval}}")
  586. alertcondition(redDot, "Stoic Edge Compass - Red", "Stoic Edge Compass: Red dot - FOCUS LOOK FOR SELLS on {{ticker}} {{interval}}")
  587. alertcondition(exhaustionStart and conf, "Stoic Edge Compass - Exhaustion Yellow", "Stoic Edge Compass: Yellow exhaustion warning on {{ticker}} {{interval}}")
  588. alertcondition(rangeEstablished and conf, "Stoic Edge Compass - Range Established", "Stoic Edge Compass: Range established - WAIT on {{ticker}} {{interval}}")
  589. alertcondition(yellowDot, "Stoic Edge Compass - Wait", "Stoic Edge Compass: Yellow Wait dot on {{ticker}} {{interval}}")
  590. alertcondition(focus != prevFocus and conf, "Stoic Edge Compass - Focus Change", "Stoic Edge Compass: FOCUS changed on {{ticker}} {{interval}}")
  591. alertcondition(sbsBullSig, "Stoic Edge Compass - SBS Bullish", "Stoic Edge Compass: Bullish SBS liquidity sweep on {{ticker}} {{interval}}")
  592. alertcondition(sbsBearSig, "Stoic Edge Compass - SBS Bearish", "Stoic Edge Compass: Bearish SBS liquidity sweep on {{ticker}} {{interval}}")
Advertisement
Comments
Add Comment
Please, Sign In to add comment