ajiim

🎁

Oct 14th, 2026
760
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.63 KB | None | 1 0
  1. //@version=6
  2. indicator("AlexTradesNQ Model", shorttitle = "AlexTradesNQ Model", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 500, max_bars_back = 500, dynamic_requests = true)
  3.  
  4. const string G_LVL = "Liquidity Levels (EQH / EQL)"
  5. const string G_FVG = "Fair Value Gaps"
  6. const string G_FIB = "Leg & Fibonacci"
  7. const string G_SIG = "Entry Signals"
  8. const string G_ALT = "Alerts"
  9.  
  10. const string TT_LVTF = "Level timeframe slot: on/off toggle, timeframe and color. Disabled slots are not calculated. Timeframes below the chart timeframe are skipped."
  11. const string TT_RET = "How deep a candle must retrace toward a tracked swing for the test to count, as a percentage of the move away from the swing."
  12. const string TT_MAXLV = "Maximum number of levels kept above and below price. The oldest levels beyond the cap are removed."
  13. const string TT_RMBRK = "When enabled, a level is deleted the moment a chart candle closes through it. When disabled, the level stays on the chart dimmed and frozen at the break point."
  14. const string TT_EXT = "How many bars all drawings extend past the latest candle (levels, FVG boxes, fibonacci lines and open trade lines)."
  15. const string TT_FVTF = "FVG timeframe slot: on/off toggle, timeframe, bullish color and bearish color. These are also the leg retrace targets of the entry model. Timeframes below the chart timeframe are skipped."
  16. const string TT_PLOT = "Master toggle for drawing the boxes. Signal logic keeps running with plotting off."
  17. const string TT_MERGE = "Combines overlapping same-direction gaps into one labeled box. Display only."
  18. const string TT_RMMIT = "Removes a box once price closes through the far side of the gap; when disabled the box is dimmed and frozen instead."
  19. const string TT_NEAR = "How many unmitigated gaps stay visible, ranked by distance from the current price. Hidden gaps remain fully tracked."
  20. const string TT_SHFIB = "Toggles the fibonacci drawings. The leg logic keeps running with drawing off."
  21. const string TT_LEGLN = "Pivot length that defines a leg on the chart timeframe. Larger values produce fewer, larger legs and confirm swings later."
  22. const string TT_FILL = "Optional fill between the 0.5 and 1 lines."
  23. const string TT_AGE = "Maximum age of a gap on the scan timeframes (5m-1m) before it can no longer become an IFVG."
  24. const string TT_TOUT = "A setup that has not produced an entry within this many chart bars is abandoned."
  25.  
  26. bool lvOn1 = input.bool(true, "", inline = "lv1", group = G_LVL)
  27. string lvTf1 = input.timeframe("15", "", inline = "lv1", group = G_LVL)
  28. color lvCol1 = input.color(#B2B5BE, "", inline = "lv1", group = G_LVL, tooltip = TT_LVTF)
  29. bool lvOn2 = input.bool(true, "", inline = "lv2", group = G_LVL)
  30. string lvTf2 = input.timeframe("30", "", inline = "lv2", group = G_LVL)
  31. color lvCol2 = input.color(#42A5F5, "", inline = "lv2", group = G_LVL, tooltip = TT_LVTF)
  32. bool lvOn3 = input.bool(true, "", inline = "lv3", group = G_LVL)
  33. string lvTf3 = input.timeframe("60", "", inline = "lv3", group = G_LVL)
  34. color lvCol3 = input.color(#FFA726, "", inline = "lv3", group = G_LVL, tooltip = TT_LVTF)
  35. bool lvOn4 = input.bool(true, "", inline = "lv4", group = G_LVL)
  36. string lvTf4 = input.timeframe("240", "", inline = "lv4", group = G_LVL)
  37. color lvCol4 = input.color(#AB47BC, "", inline = "lv4", group = G_LVL, tooltip = TT_LVTF)
  38. bool lvOn5 = input.bool(true, "", inline = "lv5", group = G_LVL)
  39. string lvTf5 = input.timeframe("D", "", inline = "lv5", group = G_LVL)
  40. color lvCol5 = input.color(#FFEB3B, "", inline = "lv5", group = G_LVL, tooltip = TT_LVTF)
  41. int lvMinRet = input.int(90, "Min Retracement %", minval = 50, maxval = 99, group = G_LVL, tooltip = TT_RET)
  42. int lvMax = input.int(8, "Max Levels Per Side", minval = 1, maxval = 25, group = G_LVL, tooltip = TT_MAXLV)
  43. bool lvRemoveBrk = input.bool(true, "Remove Broken Levels", group = G_LVL, tooltip = TT_RMBRK)
  44. string lvStyleIn = input.string("Solid", "Line Style / Width", options = ["Solid", "Dashed", "Dotted"], inline = "lvst", group = G_LVL)
  45. int lvWidth = input.int(1, "", minval = 1, maxval = 4, inline = "lvst", group = G_LVL)
  46. string lvSizeIn = input.string("Small", "Label Size", options = ["Tiny", "Small", "Normal"], group = G_LVL)
  47. int extBars = input.int(12, "Extend Right (Bars)", minval = 0, maxval = 500, group = G_LVL, tooltip = TT_EXT)
  48.  
  49. bool fvOn1 = input.bool(true, "", inline = "fv1", group = G_FVG)
  50. string fvTf1 = input.timeframe("5", "", inline = "fv1", group = G_FVG)
  51. color fvBull1 = input.color(color.new(#9598A1, 85), "", inline = "fv1", group = G_FVG)
  52. color fvBear1 = input.color(color.new(#9598A1, 85), "", inline = "fv1", group = G_FVG, tooltip = TT_FVTF)
  53. bool fvOn2 = input.bool(true, "", inline = "fv2", group = G_FVG)
  54. string fvTf2 = input.timeframe("15", "", inline = "fv2", group = G_FVG)
  55. color fvBull2 = input.color(color.new(#9598A1, 85), "", inline = "fv2", group = G_FVG)
  56. color fvBear2 = input.color(color.new(#9598A1, 85), "", inline = "fv2", group = G_FVG, tooltip = TT_FVTF)
  57. bool fvOn3 = input.bool(true, "", inline = "fv3", group = G_FVG)
  58. string fvTf3 = input.timeframe("30", "", inline = "fv3", group = G_FVG)
  59. color fvBull3 = input.color(color.new(#9598A1, 85), "", inline = "fv3", group = G_FVG)
  60. color fvBear3 = input.color(color.new(#9598A1, 85), "", inline = "fv3", group = G_FVG, tooltip = TT_FVTF)
  61. bool fvOn4 = input.bool(true, "", inline = "fv4", group = G_FVG)
  62. string fvTf4 = input.timeframe("60", "", inline = "fv4", group = G_FVG)
  63. color fvBull4 = input.color(color.new(#9598A1, 85), "", inline = "fv4", group = G_FVG)
  64. color fvBear4 = input.color(color.new(#9598A1, 85), "", inline = "fv4", group = G_FVG, tooltip = TT_FVTF)
  65. bool fvgPlot = input.bool(true, "Plot FVGs", group = G_FVG, tooltip = TT_PLOT)
  66. bool fvgLabelOn = input.bool(true, "Label / Color", inline = "fvl", group = G_FVG)
  67. color fvgLabelCol = input.color(color.new(#787B86, 20), "", inline = "fvl", group = G_FVG)
  68. bool fvgMerge = input.bool(true, "Merge Overlapping FVGs", group = G_FVG, tooltip = TT_MERGE)
  69. bool fvgRemoveMit = input.bool(true, "Remove Mitigated", group = G_FVG, tooltip = TT_RMMIT)
  70. int fvgNearest = input.int(2, "Show Nearest FVGs", minval = 1, maxval = 25, group = G_FVG, tooltip = TT_NEAR)
  71.  
  72. bool showFib = input.bool(true, "Show Fibonacci", group = G_FIB, tooltip = TT_SHFIB)
  73. int legLen = input.int(10, "Leg Swing Length", minval = 2, maxval = 100, group = G_FIB, tooltip = TT_LEGLN)
  74. color fibLongCol = input.color(#26A69A, "0.5 Long / Short Colors", inline = "f05", group = G_FIB)
  75. color fibShortCol = input.color(#F23645, "", inline = "f05", group = G_FIB)
  76. color fib01Col = input.color(#D1D4DC, "0 / 1 Lines Color", group = G_FIB)
  77. bool fibFillOn = input.bool(false, "Retrace Zone Fill", inline = "ffill", group = G_FIB)
  78. color fibFillCol = input.color(color.new(#26A69A, 90), "", inline = "ffill", group = G_FIB, tooltip = TT_FILL)
  79.  
  80. int ifvgAge = input.int(60, "IFVG Max Gap Age (Minutes)", minval = 5, maxval = 1440, group = G_SIG, tooltip = TT_AGE)
  81. int setupTimeout = input.int(500, "Setup Timeout (Bars)", minval = 20, maxval = 5000, group = G_SIG, tooltip = TT_TOUT)
  82. color sigLongCol = input.color(#26A69A, "Long / Short Colors", inline = "sgc", group = G_SIG)
  83. color sigShortCol = input.color(#F23645, "", inline = "sgc", group = G_SIG)
  84. color entryCol = input.color(#2962FF, "Entry / TP / SL Colors", inline = "trc", group = G_SIG)
  85. color tpCol = input.color(#26A69A, "", inline = "trc", group = G_SIG)
  86. color slCol = input.color(#F23645, "", inline = "trc", group = G_SIG)
  87. string sigSizeIn = input.string("Small", "Label Size", options = ["Tiny", "Small", "Normal"], group = G_SIG)
  88.  
  89. bool altLong = input.bool(true, "Long Signal", group = G_ALT)
  90. bool altShort = input.bool(true, "Short Signal", group = G_ALT)
  91. bool altTP = input.bool(true, "TP Hit", group = G_ALT)
  92. bool altSL = input.bool(true, "SL Hit", group = G_ALT)
  93. bool altLvl = input.bool(false, "Liquidity Level Break", group = G_ALT)
  94.  
  95. const int FVG_MAX = 25
  96. const int LEG_TARGET_MAX = 12
  97. const int MAX_TRADES = 30
  98. const int V_MAX_BARS = 8
  99. const int V_MAX_COUNTER = 3
  100. const int CASCADE_WAIT_MS = 300000
  101. const int STREAM_MAX = 40
  102. const int SCAN_GAP_MAX = 30
  103.  
  104. color TRANSPARENT = color.new(#000000, 100)
  105. int chartSec = timeframe.in_seconds(timeframe.period)
  106. int barMs = chartSec * 1000
  107. int extMs = extBars * barMs
  108. string lvLineStyle = lvStyleIn == "Dashed" ? line.style_dashed : lvStyleIn == "Dotted" ? line.style_dotted : line.style_solid
  109. string lvSize = lvSizeIn == "Tiny" ? size.tiny : lvSizeIn == "Normal" ? size.normal : size.small
  110. string sigSize = sigSizeIn == "Tiny" ? size.tiny : sigSizeIn == "Normal" ? size.normal : size.small
  111.  
  112. var array<int> SWING_LENS = array.from(5, 10, 15)
  113.  
  114. type ScanGap
  115. float top
  116. float bottom
  117. bool isBull
  118. int formTime
  119.  
  120. type Stream
  121. array<float> o
  122. array<float> h
  123. array<float> l
  124. array<float> c
  125. array<int> t
  126. array<ScanGap> gaps
  127.  
  128. type SwingTrack
  129. float price = na
  130. int swTime = na
  131. float deepest = na
  132. bool pending = false
  133.  
  134. type Level
  135. float price
  136. bool isHigh
  137. int mask
  138. int touches
  139. int startTime
  140. int lastTouch
  141. bool broken = false
  142. int breakTime = na
  143. line ln
  144. label lb
  145.  
  146. type FVG
  147. float top
  148. float bottom
  149. bool isBull
  150. int slot
  151. int startTime
  152. int closeTime
  153. bool mitigated = false
  154. int mitTime = na
  155.  
  156. type Target
  157. FVG gap
  158. bool tapped = false
  159.  
  160. type Leg
  161. int dir
  162. array<Target> targets
  163. bool active = false
  164. float origin = na
  165. int originBar = na
  166. int originTime = na
  167. float ext = na
  168. int extBar = na
  169. int startBar = na
  170. bool tap05 = false
  171. bool armed = false
  172. float turn = na
  173. int turnBar = na
  174. int counter = 0
  175. int tapMask = 0
  176. int candIdx = -1
  177. int candStart = na
  178. line l1
  179. line l0
  180. line l05
  181. line diag
  182. label b1
  183. label b0
  184. label b05
  185. linefill lf
  186.  
  187. type Trade
  188. int dir
  189. float entry
  190. float sl
  191. float tp
  192. int entryBar
  193. int entryTime
  194. string legTfs
  195. string ifvgTf
  196. int result = 0
  197. label sig
  198. line le
  199. line lsl
  200. line ltp
  201. label bE
  202. label bSL
  203. label bTP
  204. line f1
  205. line f0
  206. line f05
  207. line fdiag
  208. label fb1
  209. label fb0
  210. label fb05
  211. linefill flf
  212.  
  213. f_tfName(string tf) =>
  214. int sec = timeframe.in_seconds(tf)
  215. string nm = ""
  216. if sec < 60
  217. nm := str.tostring(sec) + "s"
  218. else if sec < 3600
  219. nm := str.tostring(math.round(sec / 60.0)) + "m"
  220. else if sec < 86400
  221. nm := str.tostring(math.round(sec / 3600.0)) + "H"
  222. else if sec == 86400
  223. nm := "D"
  224. else if sec < 604800
  225. nm := str.tostring(math.round(sec / 86400.0)) + "D"
  226. else if sec == 604800
  227. nm := "W"
  228. else if sec < 2419200
  229. nm := str.tostring(math.round(sec / 604800.0)) + "W"
  230. else
  231. nm := "M"
  232. nm
  233.  
  234. f_px(float p) =>
  235. str.tostring(p, format.mintick)
  236.  
  237. f_bit(int i) =>
  238. int(math.pow(2, i))
  239.  
  240. f_has(int mask, int i) =>
  241. math.floor(mask / f_bit(i)) % 2 == 1
  242.  
  243. f_set(int mask, int i) =>
  244. f_has(mask, i) ? mask : mask + f_bit(i)
  245.  
  246. f_maskText(int mask, array<string> names, array<int> secs) =>
  247. array<int> idx = array.new<int>()
  248. array<int> sv = array.new<int>()
  249. for i = 0 to names.size() - 1
  250. if f_has(mask, i)
  251. idx.push(i)
  252. sv.push(secs.get(i))
  253. string txt = ""
  254. if idx.size() > 0
  255. array<int> ordIdx = sv.sort_indices(order.ascending)
  256. for k = 0 to ordIdx.size() - 1
  257. txt := txt + (k == 0 ? "" : " + ") + names.get(idx.get(ordIdx.get(k)))
  258. txt
  259.  
  260. f_maskTop(int mask, array<int> secs) =>
  261. int best = -1
  262. int bestSec = -1
  263. for i = 0 to secs.size() - 1
  264. if f_has(mask, i) and secs.get(i) > bestSec
  265. best := i
  266. bestSec := secs.get(i)
  267. math.max(best, 0)
  268.  
  269. f_dim(color c) =>
  270. color.new(c, math.min(100.0, color.t(c) + (100.0 - color.t(c)) * 0.6))
  271.  
  272. f_newStream() =>
  273. Stream.new(array.new<float>(), array.new<float>(), array.new<float>(), array.new<float>(), array.new<int>(), array.new<ScanGap>())
  274.  
  275. f_streamPush(Stream s, float pO, float pH, float pL, float pC, int pT) =>
  276. s.o.push(pO)
  277. s.h.push(pH)
  278. s.l.push(pL)
  279. s.c.push(pC)
  280. s.t.push(pT)
  281. if s.o.size() > STREAM_MAX
  282. s.o.shift()
  283. s.h.shift()
  284. s.l.shift()
  285. s.c.shift()
  286. s.t.shift()
  287. true
  288.  
  289. f_htf(string tf) =>
  290. [rO, rH, rL, rC, rT] = request.security(syminfo.tickerid, tf, [open[1], high[1], low[1], close[1], time[1]], lookahead = barmerge.lookahead_on)
  291. int tfSec = timeframe.in_seconds(tf)
  292. bool same = tfSec == chartSec
  293. bool fresh = not na(rT) and (na(rT[1]) or rT != rT[1])
  294. bool isNew = same ? barstate.isconfirmed : fresh
  295. [same ? open : rO, same ? high : rH, same ? low : rL, same ? close : rC, same ? time : rT, same ? time_close : rT + tfSec * 1000, isNew]
  296.  
  297. array<string> lvlNames = array.from(f_tfName(lvTf1), f_tfName(lvTf2), f_tfName(lvTf3), f_tfName(lvTf4), f_tfName(lvTf5))
  298. array<int> lvlSecs = array.from(timeframe.in_seconds(lvTf1), timeframe.in_seconds(lvTf2), timeframe.in_seconds(lvTf3), timeframe.in_seconds(lvTf4), timeframe.in_seconds(lvTf5))
  299. array<color> lvlCols = array.from(lvCol1, lvCol2, lvCol3, lvCol4, lvCol5)
  300. array<bool> lvlOn = array.from(lvOn1 and lvlSecs.get(0) >= chartSec, lvOn2 and lvlSecs.get(1) >= chartSec, lvOn3 and lvlSecs.get(2) >= chartSec, lvOn4 and lvlSecs.get(3) >= chartSec, lvOn5 and lvlSecs.get(4) >= chartSec)
  301.  
  302. array<string> fvgNames = array.from(f_tfName(fvTf1), f_tfName(fvTf2), f_tfName(fvTf3), f_tfName(fvTf4))
  303. array<int> fvgSecs = array.from(timeframe.in_seconds(fvTf1), timeframe.in_seconds(fvTf2), timeframe.in_seconds(fvTf3), timeframe.in_seconds(fvTf4))
  304. array<color> fvgBullCols = array.from(fvBull1, fvBull2, fvBull3, fvBull4)
  305. array<color> fvgBearCols = array.from(fvBear1, fvBear2, fvBear3, fvBear4)
  306. array<bool> fvgOn = array.from(fvOn1 and fvgSecs.get(0) >= chartSec, fvOn2 and fvgSecs.get(1) >= chartSec, fvOn3 and fvgSecs.get(2) >= chartSec, fvOn4 and fvgSecs.get(3) >= chartSec)
  307.  
  308. array<string> scanNames = array.from("5m", "4m", "3m", "2m", "1m")
  309. array<int> scanSec = array.from(300, 240, 180, 120, 60)
  310. array<bool> scanOn = array.from(300 >= chartSec, 240 >= chartSec, 180 >= chartSec, 120 >= chartSec, 60 >= chartSec)
  311.  
  312. array<bool> ifvgL = array.new<bool>(5, false)
  313. array<bool> ifvgS = array.new<bool>(5, false)
  314. array<bool> pushL = array.new<bool>(5, false)
  315. array<bool> pushS = array.new<bool>(5, false)
  316. array<string> alertQ = array.new<string>()
  317.  
  318. var array<Stream> lvStreams = array.new<Stream>()
  319. var array<Stream> fvStreams = array.new<Stream>()
  320. var array<Stream> scanStreams = array.new<Stream>()
  321. var array<SwingTrack> swHigh = array.new<SwingTrack>()
  322. var array<SwingTrack> swLow = array.new<SwingTrack>()
  323. var array<Level> eqhLevels = array.new<Level>()
  324. var array<Level> eqlLevels = array.new<Level>()
  325. var array<FVG> fvgAll = array.new<FVG>()
  326. var array<box> fvgBoxes = array.new<box>()
  327. var array<Trade> trades = array.new<Trade>()
  328. var Leg longLeg = Leg.new(dir = 1, targets = array.new<Target>())
  329. var Leg shortLeg = Leg.new(dir = -1, targets = array.new<Target>())
  330.  
  331. if barstate.isfirst
  332. for i = 0 to 4
  333. lvStreams.push(f_newStream())
  334. scanStreams.push(f_newStream())
  335. for i = 0 to 3
  336. fvStreams.push(f_newStream())
  337. for i = 0 to 14
  338. swHigh.push(SwingTrack.new())
  339. swLow.push(SwingTrack.new())
  340.  
  341. f_levelText(Level lv) =>
  342. f_maskText(lv.mask, lvlNames, lvlSecs) + (lv.isHigh ? " EQH" : " EQL")
  343.  
  344. f_levelDraw(Level lv) =>
  345. color baseCol = lvlCols.get(f_maskTop(lv.mask, lvlSecs))
  346. color drawCol = lv.broken ? f_dim(baseCol) : baseCol
  347. int rightX = lv.broken ? lv.breakTime : time + extMs
  348. string txt = f_levelText(lv)
  349. string tip = "Touches: " + str.tostring(lv.touches)
  350. if na(lv.ln)
  351. lv.ln := line.new(lv.startTime, lv.price, rightX, lv.price, xloc = xloc.bar_time, color = drawCol, style = lvLineStyle, width = lvWidth)
  352. lv.lb := label.new(rightX, lv.price, txt, xloc = xloc.bar_time, color = TRANSPARENT, style = label.style_label_left, textcolor = drawCol, size = lvSize, tooltip = tip)
  353. else
  354. line.set_x1(lv.ln, lv.startTime)
  355. line.set_x2(lv.ln, rightX)
  356. line.set_color(lv.ln, drawCol)
  357. label.set_x(lv.lb, rightX)
  358. label.set_text(lv.lb, txt)
  359. label.set_textcolor(lv.lb, drawCol)
  360. label.set_tooltip(lv.lb, tip)
  361. true
  362.  
  363. f_levelRemove(Level lv) =>
  364. line.delete(lv.ln)
  365. label.delete(lv.lb)
  366. true
  367.  
  368. f_levelCreate(bool isHigh, float price, int slot, int swTime) =>
  369. array<Level> side = isHigh ? eqhLevels : eqlLevels
  370. Level found = na
  371. if side.size() > 0
  372. for lvItem in side
  373. if not lvItem.broken and lvItem.price == price
  374. found := lvItem
  375. break
  376. if na(found)
  377. Level nl = Level.new(price, isHigh, f_bit(slot), 1, swTime, time)
  378. side.push(nl)
  379. f_levelDraw(nl)
  380. if side.size() > lvMax
  381. f_levelRemove(side.shift())
  382. else
  383. if found.lastTouch != time
  384. found.touches := found.touches + 1
  385. found.lastTouch := time
  386. found.mask := f_set(found.mask, slot)
  387. found.startTime := math.min(found.startTime, swTime)
  388. f_levelDraw(found)
  389. true
  390.  
  391. f_testSwing(SwingTrack sw, bool isHigh, int slot, float pO, float pH, float pL, float pC) =>
  392. if not na(sw.price)
  393. bool broke = isHigh ? pH > sw.price : pL < sw.price
  394. if broke
  395. sw.price := na
  396. sw.pending := false
  397. else
  398. bool confirmCandle = isHigh ? pC < pO : pC > pO
  399. bool oppCandle = isHigh ? pC > pO : pC < pO
  400. bool created = false
  401. if sw.pending
  402. sw.pending := false
  403. if confirmCandle
  404. f_levelCreate(isHigh, sw.price, slot, sw.swTime)
  405. created := true
  406. if not created
  407. float move = isHigh ? sw.price - sw.deepest : sw.deepest - sw.price
  408. float thr = isHigh ? sw.deepest + move * lvMinRet / 100.0 : sw.deepest - move * lvMinRet / 100.0
  409. bool tested = move > 0 and (isHigh ? pH >= thr : pL <= thr)
  410. if tested
  411. if confirmCandle
  412. f_levelCreate(isHigh, sw.price, slot, sw.swTime)
  413. created := true
  414. else if oppCandle
  415. sw.pending := true
  416. if created
  417. sw.deepest := isHigh ? pL : pH
  418. else
  419. sw.deepest := isHigh ? math.min(sw.deepest, pL) : math.max(sw.deepest, pH)
  420. true
  421.  
  422. f_swingProcess(int slot, Stream s) =>
  423. int sz = s.h.size()
  424. float cO = s.o.get(sz - 1)
  425. float cH = s.h.get(sz - 1)
  426. float cL = s.l.get(sz - 1)
  427. float cC = s.c.get(sz - 1)
  428. for k = 0 to 2
  429. int n = SWING_LENS.get(k)
  430. SwingTrack trH = swHigh.get(slot * 3 + k)
  431. SwingTrack trL = swLow.get(slot * 3 + k)
  432. f_testSwing(trH, true, slot, cO, cH, cL, cC)
  433. f_testSwing(trL, false, slot, cO, cH, cL, cC)
  434. if sz >= 2 * n + 1
  435. int p = sz - 1 - n
  436. float pivH = s.h.get(p)
  437. float pivL = s.l.get(p)
  438. bool isPH = true
  439. bool isPL = true
  440. for i = sz - 1 - 2 * n to sz - 1
  441. if i != p
  442. float hi = s.h.get(i)
  443. float lo = s.l.get(i)
  444. if i < p ? hi >= pivH : hi > pivH
  445. isPH := false
  446. if i < p ? lo <= pivL : lo < pivL
  447. isPL := false
  448. if isPH or isPL
  449. float minAfter = s.l.get(p + 1)
  450. float maxAfter = s.h.get(p + 1)
  451. for j = p + 1 to sz - 1
  452. minAfter := math.min(minAfter, s.l.get(j))
  453. maxAfter := math.max(maxAfter, s.h.get(j))
  454. if isPH
  455. trH.price := pivH
  456. trH.swTime := s.t.get(p)
  457. trH.deepest := minAfter
  458. trH.pending := false
  459. if isPL
  460. trL.price := pivL
  461. trL.swTime := s.t.get(p)
  462. trL.deepest := maxAfter
  463. trL.pending := false
  464. true
  465.  
  466. f_levelSlot(int slot, bool enabled, bool isNew, float pO, float pH, float pL, float pC, int pT) =>
  467. if enabled and isNew and not na(pC)
  468. Stream s = lvStreams.get(slot)
  469. f_streamPush(s, pO, pH, pL, pC, pT)
  470. f_swingProcess(slot, s)
  471. true
  472.  
  473. f_levelsBreakCheck(array<Level> side) =>
  474. if side.size() > 0
  475. for i = side.size() - 1 to 0
  476. Level lv = side.get(i)
  477. if not lv.broken and (lv.isHigh ? close > lv.price : close < lv.price)
  478. if altLvl
  479. alertQ.push("AlexTradesNQ Model | Liquidity Level Break: " + f_levelText(lv) + " @ " + f_px(lv.price))
  480. if lvRemoveBrk
  481. f_levelRemove(lv)
  482. side.remove(i)
  483. else
  484. lv.broken := true
  485. lv.breakTime := time
  486. f_levelDraw(lv)
  487. true
  488.  
  489. f_levelsExtend(array<Level> side) =>
  490. if side.size() > 0
  491. for lvExt in side
  492. if not lvExt.broken and not na(lvExt.ln)
  493. line.set_x2(lvExt.ln, time + extMs)
  494. label.set_x(lvExt.lb, time + extMs)
  495. true
  496.  
  497. f_legAddTarget(Leg lg, FVG g) =>
  498. if lg.active and g.isBull == (lg.dir == 1) and not g.mitigated and g.closeTime > lg.originTime
  499. lg.targets.push(Target.new(g))
  500. if lg.targets.size() > LEG_TARGET_MAX
  501. lg.targets.shift()
  502. true
  503.  
  504. f_fvgSlot(int slot, bool enabled, bool isNew, float pO, float pH, float pL, float pC, int pT, int pCT) =>
  505. if enabled and isNew and not na(pC)
  506. Stream s = fvStreams.get(slot)
  507. f_streamPush(s, pO, pH, pL, pC, pT)
  508. int n = s.h.size()
  509. if n >= 3
  510. float h1 = s.h.get(n - 3)
  511. float l1 = s.l.get(n - 3)
  512. float h3 = s.h.get(n - 1)
  513. float l3 = s.l.get(n - 1)
  514. int t1 = s.t.get(n - 3)
  515. FVG g = na
  516. if l3 > h1
  517. g := FVG.new(l3, h1, true, slot, t1, pCT)
  518. else if h3 < l1
  519. g := FVG.new(l1, h3, false, slot, t1, pCT)
  520. if not na(g)
  521. fvgAll.push(g)
  522. if fvgAll.size() > FVG_MAX
  523. fvgAll.shift()
  524. f_legAddTarget(longLeg, g)
  525. f_legAddTarget(shortLeg, g)
  526. true
  527.  
  528. f_fvgMitigation() =>
  529. if fvgAll.size() > 0
  530. for i = fvgAll.size() - 1 to 0
  531. FVG g = fvgAll.get(i)
  532. if not g.mitigated and ((g.isBull and close < g.bottom) or (not g.isBull and close > g.top))
  533. g.mitigated := true
  534. g.mitTime := time
  535. if g.mitigated and fvgRemoveMit
  536. fvgAll.remove(i)
  537. true
  538.  
  539. f_scanSlot(int k, bool isNew, float pO, float pH, float pL, float pC, int pT) =>
  540. int ageMs = ifvgAge * 60000
  541. Stream s = scanStreams.get(k)
  542. if scanOn.get(k) and isNew and not na(pC)
  543. f_streamPush(s, pO, pH, pL, pC, pT)
  544. if s.gaps.size() > 0
  545. for i = s.gaps.size() - 1 to 0
  546. ScanGap sg = s.gaps.get(i)
  547. if pT - sg.formTime > ageMs
  548. s.gaps.remove(i)
  549. else if not sg.isBull and pC > sg.top
  550. ifvgL.set(k, true)
  551. s.gaps.remove(i)
  552. else if sg.isBull and pC < sg.bottom
  553. ifvgS.set(k, true)
  554. s.gaps.remove(i)
  555. int n = s.h.size()
  556. if n >= 3
  557. float h1 = s.h.get(n - 3)
  558. float l1 = s.l.get(n - 3)
  559. float h3 = s.h.get(n - 1)
  560. float l3 = s.l.get(n - 1)
  561. if l3 > h1
  562. s.gaps.push(ScanGap.new(l3, h1, true, pT))
  563. else if h3 < l1
  564. s.gaps.push(ScanGap.new(l1, h3, false, pT))
  565. if s.gaps.size() > SCAN_GAP_MAX
  566. s.gaps.shift()
  567. if scanOn.get(k) and scanSec.get(k) > chartSec and s.gaps.size() > 0
  568. bool pl = false
  569. bool ps = false
  570. for pg in s.gaps
  571. if time - pg.formTime <= ageMs
  572. if not pg.isBull and close > pg.top
  573. pl := true
  574. if pg.isBull and close < pg.bottom
  575. ps := true
  576. pushL.set(k, pl)
  577. pushS.set(k, ps)
  578. true
  579.  
  580. f_legResetProgress(Leg lg) =>
  581. lg.tap05 := false
  582. lg.armed := false
  583. lg.turn := na
  584. lg.turnBar := na
  585. lg.counter := 0
  586. lg.tapMask := 0
  587. if lg.targets.size() > 0
  588. for tgR in lg.targets
  589. tgR.tapped := false
  590. true
  591.  
  592. f_legKill(Leg lg) =>
  593. line.delete(lg.l1)
  594. line.delete(lg.l0)
  595. line.delete(lg.l05)
  596. line.delete(lg.diag)
  597. label.delete(lg.b1)
  598. label.delete(lg.b0)
  599. label.delete(lg.b05)
  600. linefill.delete(lg.lf)
  601. lg.l1 := na
  602. lg.l0 := na
  603. lg.l05 := na
  604. lg.diag := na
  605. lg.b1 := na
  606. lg.b0 := na
  607. lg.b05 := na
  608. lg.lf := na
  609. f_legResetProgress(lg)
  610. lg.targets.clear()
  611. lg.active := false
  612. lg.candIdx := -1
  613. lg.candStart := na
  614. true
  615.  
  616. f_legStart(Leg lg, float oPx, int oBar, int oTime, float ePx, int eBar) =>
  617. f_legKill(lg)
  618. lg.active := true
  619. lg.origin := oPx
  620. lg.originBar := oBar
  621. lg.originTime := oTime
  622. lg.ext := ePx
  623. lg.extBar := eBar
  624. lg.startBar := bar_index
  625. if fvgAll.size() > 0
  626. for fg in fvgAll
  627. f_legAddTarget(lg, fg)
  628. true
  629.  
  630. f_fibDraw(Leg lg, int x2) =>
  631. if lg.active
  632. bool isL = lg.dir == 1
  633. float p1 = lg.origin
  634. float p0 = lg.ext
  635. float p5 = (p1 + p0) / 2.0
  636. color c5 = isL ? fibLongCol : fibShortCol
  637. if na(lg.l1)
  638. lg.l1 := line.new(lg.originBar, p1, x2, p1, color = fib01Col, width = 1)
  639. lg.l0 := line.new(lg.extBar, p0, x2, p0, color = fib01Col, width = 1)
  640. lg.l05 := line.new(lg.originBar, p5, x2, p5, color = c5, width = 1)
  641. lg.diag := line.new(lg.originBar, p1, lg.extBar, p0, color = color.new(c5, 40), style = line.style_dotted, width = 1)
  642. lg.b1 := label.new(x2, p1, "", color = TRANSPARENT, style = label.style_label_left, textcolor = fib01Col, size = size.tiny)
  643. lg.b0 := label.new(x2, p0, "", color = TRANSPARENT, style = label.style_label_left, textcolor = fib01Col, size = size.tiny)
  644. lg.b05 := label.new(x2, p5, "", color = c5, style = label.style_label_left, textcolor = color.white, size = size.tiny)
  645. if fibFillOn
  646. lg.lf := linefill.new(lg.l05, lg.l1, fibFillCol)
  647. else
  648. line.set_xy1(lg.l1, lg.originBar, p1)
  649. line.set_xy2(lg.l1, x2, p1)
  650. line.set_xy1(lg.l0, lg.extBar, p0)
  651. line.set_xy2(lg.l0, x2, p0)
  652. line.set_xy1(lg.l05, lg.originBar, p5)
  653. line.set_xy2(lg.l05, x2, p5)
  654. line.set_xy1(lg.diag, lg.originBar, p1)
  655. line.set_xy2(lg.diag, lg.extBar, p0)
  656. label.set_xy(lg.b1, x2, p1)
  657. label.set_xy(lg.b0, x2, p0)
  658. label.set_xy(lg.b05, x2, p5)
  659. label.set_text(lg.b1, "1 (" + f_px(p1) + ")")
  660. label.set_text(lg.b0, "0 (" + f_px(p0) + ")")
  661. label.set_text(lg.b05, "0.5 (" + f_px(p5) + ")")
  662. true
  663.  
  664. f_legUpdate(Leg lg) =>
  665. if lg.active
  666. bool isL = lg.dir == 1
  667. bool hasCand = lg.candIdx >= 0
  668. bool extended = isL ? high > lg.ext : low < lg.ext
  669. if extended
  670. lg.ext := isL ? high : low
  671. lg.extBar := bar_index
  672. if not hasCand
  673. f_legResetProgress(lg)
  674. if lg.targets.size() > 0
  675. for i = lg.targets.size() - 1 to 0
  676. if lg.targets.get(i).gap.mitigated
  677. lg.targets.remove(i)
  678. if hasCand
  679. lg.turn := isL ? math.min(nz(lg.turn, low), low) : math.max(nz(lg.turn, high), high)
  680. else
  681. float fib05 = (lg.origin + lg.ext) / 2.0
  682. if not extended
  683. if isL ? low <= fib05 : high >= fib05
  684. lg.tap05 := true
  685. if lg.targets.size() > 0
  686. for tg in lg.targets
  687. if isL ? low <= tg.gap.top : high >= tg.gap.bottom
  688. tg.tapped := true
  689. int tapM = 0
  690. if lg.targets.size() > 0
  691. for tg2 in lg.targets
  692. if tg2.tapped
  693. tapM := f_set(tapM, tg2.gap.slot)
  694. lg.tapMask := tapM
  695. if lg.armed and tapM == 0
  696. lg.armed := false
  697. lg.turn := na
  698. lg.turnBar := na
  699. lg.counter := 0
  700. if not lg.armed
  701. if lg.tap05 and tapM > 0
  702. lg.armed := true
  703. lg.turn := isL ? low : high
  704. lg.turnBar := bar_index
  705. lg.counter := 0
  706. else
  707. bool newTurn = isL ? low < lg.turn : high > lg.turn
  708. if newTurn
  709. lg.turn := isL ? low : high
  710. lg.turnBar := bar_index
  711. lg.counter := 0
  712. else
  713. if isL ? close < open : close > open
  714. lg.counter := lg.counter + 1
  715. if bar_index - lg.turnBar > V_MAX_BARS or lg.counter > V_MAX_COUNTER
  716. f_legResetProgress(lg)
  717. true
  718.  
  719. f_legCandidate(Leg lg) =>
  720. bool release = false
  721. if lg.active
  722. bool isL = lg.dir == 1
  723. int best = -1
  724. for k = 0 to 4
  725. if best < 0 and scanOn.get(k) and (isL ? ifvgL.get(k) : ifvgS.get(k))
  726. best := k
  727. if best >= 0 and ((lg.candIdx < 0 and lg.armed) or (lg.candIdx >= 0 and best < lg.candIdx))
  728. lg.candIdx := best
  729. lg.candStart := time
  730. if lg.candIdx >= 0
  731. bool hold = false
  732. if lg.candIdx > 0
  733. for j = 0 to lg.candIdx - 1
  734. if scanOn.get(j) and scanSec.get(j) > chartSec and (isL ? pushL.get(j) : pushS.get(j))
  735. hold := true
  736. if hold and time - lg.candStart >= CASCADE_WAIT_MS
  737. hold := false
  738. release := not hold
  739. release
  740.  
  741. f_legEndCheck(Leg lg) =>
  742. if lg.active and lg.candIdx < 0
  743. bool through = lg.dir == 1 ? close < lg.origin : close > lg.origin
  744. if through or bar_index - lg.startBar > setupTimeout
  745. f_legKill(lg)
  746. true
  747.  
  748. f_tradeTip(Trade tr) =>
  749. string res = tr.result == 1 ? "TP Hit" : tr.result == -1 ? "SL Hit" : "Running"
  750. (tr.dir == 1 ? "Long" : "Short") + "\nLeg FVG: " + tr.legTfs + "\nIFVG: " + tr.ifvgTf + "\nTime: " + str.format_time(tr.entryTime, "yyyy-MM-dd HH:mm", syminfo.timezone) + "\nEntry: " + f_px(tr.entry) + "\nSL: " + f_px(tr.sl) + "\nTP: " + f_px(tr.tp) + "\nResult: " + res
  751.  
  752. f_tradeClear(Trade tr) =>
  753. line.delete(tr.le)
  754. line.delete(tr.lsl)
  755. line.delete(tr.ltp)
  756. label.delete(tr.bE)
  757. label.delete(tr.bSL)
  758. label.delete(tr.bTP)
  759. line.delete(tr.f1)
  760. line.delete(tr.f0)
  761. line.delete(tr.f05)
  762. line.delete(tr.fdiag)
  763. label.delete(tr.fb1)
  764. label.delete(tr.fb0)
  765. label.delete(tr.fb05)
  766. linefill.delete(tr.flf)
  767. true
  768.  
  769. f_openTrade(Leg lg) =>
  770. bool isL = lg.dir == 1
  771. float entryPx = close
  772. float slPx = isL ? math.min(nz(lg.turn, low), low) : math.max(nz(lg.turn, high), high)
  773. float risk = math.abs(entryPx - slPx)
  774. if risk <= 0
  775. risk := syminfo.mintick
  776. slPx := isL ? entryPx - risk : entryPx + risk
  777. float tpPx = isL ? entryPx + risk : entryPx - risk
  778. string legTxt = lg.tapMask > 0 ? f_maskText(lg.tapMask, fvgNames, fvgSecs) : "-"
  779. string ifvgTxt = scanNames.get(lg.candIdx)
  780. Trade tr = Trade.new(dir = lg.dir, entry = entryPx, sl = slPx, tp = tpPx, entryBar = bar_index, entryTime = time, legTfs = legTxt, ifvgTf = ifvgTxt)
  781. color sigCol = isL ? sigLongCol : sigShortCol
  782. int x2 = bar_index + extBars
  783. tr.sig := label.new(bar_index, isL ? low : high, isL ? "L" : "S", yloc = isL ? yloc.belowbar : yloc.abovebar, color = sigCol, style = isL ? label.style_label_up : label.style_label_down, textcolor = color.white, size = sigSize, tooltip = f_tradeTip(tr))
  784. tr.le := line.new(bar_index, entryPx, x2, entryPx, color = entryCol, width = 1)
  785. tr.lsl := line.new(bar_index, slPx, x2, slPx, color = slCol, width = 1)
  786. tr.ltp := line.new(bar_index, tpPx, x2, tpPx, color = tpCol, width = 1)
  787. tr.bE := label.new(x2, entryPx, "Entry: " + f_px(entryPx), color = TRANSPARENT, style = label.style_label_left, textcolor = entryCol, size = sigSize)
  788. tr.bSL := label.new(x2, slPx, "SL: " + f_px(slPx), color = TRANSPARENT, style = label.style_label_left, textcolor = slCol, size = sigSize)
  789. tr.bTP := label.new(x2, tpPx, "TP: " + f_px(tpPx), color = TRANSPARENT, style = label.style_label_left, textcolor = tpCol, size = sigSize)
  790. if showFib
  791. f_fibDraw(lg, bar_index)
  792. tr.f1 := lg.l1
  793. tr.f0 := lg.l0
  794. tr.f05 := lg.l05
  795. tr.fdiag := lg.diag
  796. tr.fb1 := lg.b1
  797. tr.fb0 := lg.b0
  798. tr.fb05 := lg.b05
  799. tr.flf := lg.lf
  800. lg.l1 := na
  801. lg.l0 := na
  802. lg.l05 := na
  803. lg.diag := na
  804. lg.b1 := na
  805. lg.b0 := na
  806. lg.b05 := na
  807. lg.lf := na
  808. trades.push(tr)
  809. if trades.size() > MAX_TRADES
  810. f_tradeClear(trades.shift())
  811. if isL and altLong
  812. alertQ.push("AlexTradesNQ Model | Long Signal | Entry: " + f_px(entryPx) + " | SL: " + f_px(slPx) + " | TP: " + f_px(tpPx))
  813. if not isL and altShort
  814. alertQ.push("AlexTradesNQ Model | Short Signal | Entry: " + f_px(entryPx) + " | SL: " + f_px(slPx) + " | TP: " + f_px(tpPx))
  815. f_legKill(lg)
  816. true
  817.  
  818. f_legStep(Leg lg) =>
  819. f_legUpdate(lg)
  820. if f_legCandidate(lg)
  821. f_openTrade(lg)
  822. f_legEndCheck(lg)
  823. true
  824.  
  825. f_tradesUpdate() =>
  826. if trades.size() > 0
  827. for tr in trades
  828. if tr.result == 0 and bar_index > tr.entryBar
  829. bool isL = tr.dir == 1
  830. bool hitSL = isL ? low <= tr.sl : high >= tr.sl
  831. bool hitTP = isL ? high >= tr.tp : low <= tr.tp
  832. if hitSL or hitTP
  833. tr.result := hitSL ? -1 : 1
  834. f_tradeClear(tr)
  835. label.set_tooltip(tr.sig, f_tradeTip(tr))
  836. string side = isL ? "Long" : "Short"
  837. if hitSL and altSL
  838. alertQ.push("AlexTradesNQ Model | SL Hit (" + side + ") @ " + f_px(tr.sl))
  839. if not hitSL and altTP
  840. alertQ.push("AlexTradesNQ Model | TP Hit (" + side + ") @ " + f_px(tr.tp))
  841. true
  842.  
  843. f_tradesExtend() =>
  844. if trades.size() > 0
  845. int x2 = bar_index + extBars
  846. for trx in trades
  847. if trx.result == 0
  848. line.set_x2(trx.le, x2)
  849. line.set_x2(trx.lsl, x2)
  850. line.set_x2(trx.ltp, x2)
  851. label.set_x(trx.bE, x2)
  852. label.set_x(trx.bSL, x2)
  853. label.set_x(trx.bTP, x2)
  854. true
  855.  
  856. f_fvgRender() =>
  857. if fvgBoxes.size() > 0
  858. for bx in fvgBoxes
  859. box.delete(bx)
  860. fvgBoxes.clear()
  861. if fvgPlot and fvgAll.size() > 0
  862. int rightX = time + extMs
  863. if not fvgRemoveMit
  864. for mg in fvgAll
  865. if mg.mitigated
  866. color mc = f_dim(mg.isBull ? fvgBullCols.get(mg.slot) : fvgBearCols.get(mg.slot))
  867. string mtxt = fvgLabelOn ? fvgNames.get(mg.slot) + " FVG" : ""
  868. fvgBoxes.push(box.new(mg.startTime, mg.top, mg.mitTime, mg.bottom, border_color = TRANSPARENT, border_width = 1, xloc = xloc.bar_time, bgcolor = mc, text = mtxt, text_size = size.tiny, text_color = f_dim(fvgLabelCol), text_halign = text.align_right, text_valign = text.align_bottom))
  869. array<float> gTop = array.new<float>()
  870. array<float> gBot = array.new<float>()
  871. array<int> gStart = array.new<int>()
  872. array<int> gMask = array.new<int>()
  873. array<bool> gBull = array.new<bool>()
  874. for d = 0 to 1
  875. bool wantBull = d == 0
  876. array<float> bots = array.new<float>()
  877. array<int> ids = array.new<int>()
  878. for i = 0 to fvgAll.size() - 1
  879. FVG cg = fvgAll.get(i)
  880. if not cg.mitigated and cg.isBull == wantBull
  881. bots.push(cg.bottom)
  882. ids.push(i)
  883. if ids.size() > 0
  884. array<int> ordB = bots.sort_indices(order.ascending)
  885. float cTop = na
  886. float cBot = na
  887. int cStart = na
  888. int cMask = 0
  889. for k = 0 to ordB.size() - 1
  890. FVG sg = fvgAll.get(ids.get(ordB.get(k)))
  891. if na(cTop) or not fvgMerge or sg.bottom > cTop
  892. if not na(cTop)
  893. gTop.push(cTop)
  894. gBot.push(cBot)
  895. gStart.push(cStart)
  896. gMask.push(cMask)
  897. gBull.push(wantBull)
  898. cTop := sg.top
  899. cBot := sg.bottom
  900. cStart := sg.startTime
  901. cMask := f_bit(sg.slot)
  902. else
  903. cTop := math.max(cTop, sg.top)
  904. cStart := math.min(cStart, sg.startTime)
  905. cMask := f_set(cMask, sg.slot)
  906. gTop.push(cTop)
  907. gBot.push(cBot)
  908. gStart.push(cStart)
  909. gMask.push(cMask)
  910. gBull.push(wantBull)
  911. if gTop.size() > 0
  912. array<float> dist = array.new<float>()
  913. for i = 0 to gTop.size() - 1
  914. float zt = gTop.get(i)
  915. float zb = gBot.get(i)
  916. dist.push(close > zt ? close - zt : close < zb ? zb - close : 0.0)
  917. array<int> rank = dist.sort_indices(order.ascending)
  918. int shown = math.min(fvgNearest, rank.size())
  919. for k = 0 to shown - 1
  920. int gi = rank.get(k)
  921. int topS = f_maskTop(gMask.get(gi), fvgSecs)
  922. color zc = gBull.get(gi) ? fvgBullCols.get(topS) : fvgBearCols.get(topS)
  923. string ztxt = fvgLabelOn ? f_maskText(gMask.get(gi), fvgNames, fvgSecs) + " FVG" : ""
  924. fvgBoxes.push(box.new(gStart.get(gi), gTop.get(gi), rightX, gBot.get(gi), border_color = TRANSPARENT, border_width = 1, xloc = xloc.bar_time, bgcolor = zc, text = ztxt, text_size = size.tiny, text_color = fvgLabelCol, text_halign = text.align_right, text_valign = text.align_bottom))
  925. true
  926.  
  927. [lo1, lh1, ll1, lc1, lt1, lct1, ln1] = f_htf(lvTf1)
  928. [lo2, lh2, ll2, lc2, lt2, lct2, ln2] = f_htf(lvTf2)
  929. [lo3, lh3, ll3, lc3, lt3, lct3, ln3] = f_htf(lvTf3)
  930. [lo4, lh4, ll4, lc4, lt4, lct4, ln4] = f_htf(lvTf4)
  931. [lo5, lh5, ll5, lc5, lt5, lct5, ln5] = f_htf(lvTf5)
  932.  
  933. [fo1, fh1, fl1, fc1, ft1, fct1, fn1] = f_htf(fvTf1)
  934. [fo2, fh2, fl2, fc2, ft2, fct2, fn2] = f_htf(fvTf2)
  935. [fo3, fh3, fl3, fc3, ft3, fct3, fn3] = f_htf(fvTf3)
  936. [fo4, fh4, fl4, fc4, ft4, fct4, fn4] = f_htf(fvTf4)
  937.  
  938. [so1, sh1, sl1, sc1, st1, sct1, sn1] = f_htf("5")
  939. [so2, sh2, sl2, sc2, st2, sct2, sn2] = f_htf("4")
  940. [so3, sh3, sl3, sc3, st3, sct3, sn3] = f_htf("3")
  941. [so4, sh4, sl4, sc4, st4, sct4, sn4] = f_htf("2")
  942. [so5, sh5, sl5, sc5, st5, sct5, sn5] = f_htf("1")
  943.  
  944. float legPH = ta.pivothigh(high, legLen, legLen)
  945. float legPL = ta.pivotlow(low, legLen, legLen)
  946. float hiAfter = ta.highest(high, legLen)
  947. int hiAfterOff = ta.highestbars(high, legLen)
  948. float loAfter = ta.lowest(low, legLen)
  949. int loAfterOff = ta.lowestbars(low, legLen)
  950. int legOriginTime = time[legLen]
  951.  
  952. f_levelSlot(0, lvlOn.get(0), ln1, lo1, lh1, ll1, lc1, lt1)
  953. f_levelSlot(1, lvlOn.get(1), ln2, lo2, lh2, ll2, lc2, lt2)
  954. f_levelSlot(2, lvlOn.get(2), ln3, lo3, lh3, ll3, lc3, lt3)
  955. f_levelSlot(3, lvlOn.get(3), ln4, lo4, lh4, ll4, lc4, lt4)
  956. f_levelSlot(4, lvlOn.get(4), ln5, lo5, lh5, ll5, lc5, lt5)
  957.  
  958. f_fvgSlot(0, fvgOn.get(0), fn1, fo1, fh1, fl1, fc1, ft1, fct1)
  959. f_fvgSlot(1, fvgOn.get(1), fn2, fo2, fh2, fl2, fc2, ft2, fct2)
  960. f_fvgSlot(2, fvgOn.get(2), fn3, fo3, fh3, fl3, fc3, ft3, fct3)
  961. f_fvgSlot(3, fvgOn.get(3), fn4, fo4, fh4, fl4, fc4, ft4, fct4)
  962. f_fvgMitigation()
  963.  
  964. f_levelsBreakCheck(eqhLevels)
  965. f_levelsBreakCheck(eqlLevels)
  966.  
  967. f_scanSlot(0, sn1, so1, sh1, sl1, sc1, st1)
  968. f_scanSlot(1, sn2, so2, sh2, sl2, sc2, st2)
  969. f_scanSlot(2, sn3, so3, sh3, sl3, sc3, st3)
  970. f_scanSlot(3, sn4, so4, sh4, sl4, sc4, st4)
  971. f_scanSlot(4, sn5, so5, sh5, sl5, sc5, st5)
  972.  
  973. if not na(legPH) and not shortLeg.armed and shortLeg.candIdx < 0
  974. f_legStart(shortLeg, legPH, bar_index - legLen, legOriginTime, loAfter, bar_index + loAfterOff)
  975. if not na(legPL) and not longLeg.armed and longLeg.candIdx < 0
  976. f_legStart(longLeg, legPL, bar_index - legLen, legOriginTime, hiAfter, bar_index + hiAfterOff)
  977.  
  978. f_tradesUpdate()
  979.  
  980. f_legStep(longLeg)
  981. f_legStep(shortLeg)
  982.  
  983. if barstate.islast
  984. f_fvgRender()
  985. f_levelsExtend(eqhLevels)
  986. f_levelsExtend(eqlLevels)
  987. if showFib
  988. f_fibDraw(longLeg, bar_index + extBars)
  989. f_fibDraw(shortLeg, bar_index + extBars)
  990. f_tradesExtend()
  991.  
  992. if alertQ.size() > 0
  993. for msg in alertQ
  994. alert(msg, alert.freq_once_per_bar_close)
Add Comment
Please, Sign In to add comment