ajiim

๐ŸŽ

Sep 17th, 2026
3,696
3
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 76.77 KB | None | 3 0
  1. //@version=6
  2. indicator("CISD Model+ | Triton Trades", shorttitle = "CISD Model+", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 500, max_bars_back = 5000)
  3.  
  4. const string G_GEN = "General Settings"
  5. const string G_LIQ = "Liquidity"
  6. const string G_SESS = "Session Liquidity"
  7. const string G_FVG = "Fair Value Gaps"
  8. const string G_CISD = "CISD Settings"
  9. const string G_HTFCISD = "Higher Timeframe CISDs"
  10. const string G_SMT = "SMT Settings"
  11. const string G_RISK = "Risk & Contract Sizing"
  12. const string G_ALERT = "Alert Settings"
  13. const string G_WM = "Watermark / Info Box"
  14. const string G_CHECK = "Strategy Checklist"
  15.  
  16. const string STY_SOLID = "Solid"
  17. const string STY_DASH = "Dashed"
  18. const string STY_DOT = "Dotted"
  19.  
  20. const string TIP_BIAS = "Neutral shows bullish and bearish setups. Bullish/Bearish filters the model to a single direction."
  21. const string TIP_HIDEINV = "Removes every CISD whose stop-loss level has been violated. Keeps the chart clean of false positives."
  22. const string TIP_SETUPS = "How many CISD lines are retained per direction."
  23. const string TIP_MINGRADE = "Minimum grade required before a CISD is rendered or fires an alert."
  24. const string TIP_CTFFVG = "Allows CISDs that deliver from a CURRENT timeframe fair value gap (instead of a liquidity sweep)."
  25. const string TIP_CTFSWEEP = "Uses current timeframe swing highs/lows as valid liquidity. Turn off to require HTF liquidity only."
  26. const string TIP_PROX = "Suppresses CISDs that form too close (in price) to an existing CISD of the same direction."
  27. const string TIP_MAXBARS = "Maximum number of bars allowed between the CISD sequence and the confirmation close."
  28. const string TIP_SWEEP = "Marks each swing high/low that gets taken and closed back through."
  29. const string TIP_PRESERVE = "Keeps a session level drawn after it has been swept (shown as a sweep)."
  30. const string TIP_HTFMODE = "Automatic aligns HTF FVGs to the chart timeframe. Manual lets you pick each timeframe."
  31. const string TIP_POTENTIAL = "Draws the CISD level BEFORE it is confirmed, so you can see where price must close."
  32. const string TIP_DISABLELBL = "Hides the label on current-timeframe CISDs (HTF CISD labels stay visible)."
  33. const string TIP_SMTCISD = "Validates a CISD that did NOT sweep liquidity when SMT exists with the correlated asset."
  34. const string TIP_SLPLACE = "Stop loss is placed at the wick or the body of the sequence extreme."
  35. const string TIP_SIZING = "Suggests a contract count from $ risk and stop distance on current-TF CISDs."
  36. const string TIP_HOVER = "Sizing information is only visible when you hover the CISD label."
  37. const string TIP_MANHTF = "Override the automatic higher timeframe selection for the multi-TF CISD engine."
  38. const string TIP_SENS = "Sensitive = every SMT. Normal = medium swings. Strict = major swings only."
  39. const string TIP_RT = "Plots SMT before the divergence candle closes and trails it in real time."
  40. const string TIP_ALERTS = "Master switch. Alerts still respect Bias, Min Grade and the session windows below."
  41.  
  42. const color C_LONG_DEF = #2962FF
  43. const color C_SHORT_DEF = #F23645
  44. const color C_BULL_FVG = #26A69A
  45. const color C_BEAR_FVG = #EF5350
  46.  
  47. string i_bias = input.string("Neutral", "Bias", options = ["Neutral", "Bullish", "Bearish"], group = G_GEN, tooltip = TIP_BIAS)
  48. bool i_hideInvalid = input.bool(true, "Hide Invalidated Setups", group = G_GEN, tooltip = TIP_HIDEINV)
  49. int i_setupsShown = input.int(5, "Number of Setups Displayed", minval = 1, maxval = 30, group = G_GEN, tooltip = TIP_SETUPS)
  50. string i_minGrade = input.string("C", "Min Grade to Display", options = ["C", "B-", "B+", "A", "A+"], group = G_GEN, tooltip = TIP_MINGRADE)
  51. bool i_ctfFvgDeliver = input.bool(true, "Current Timeframe FVG Delivery", group = G_GEN, tooltip = TIP_CTFFVG)
  52. bool i_ctfSweeps = input.bool(true, "Current Timeframe Liquidity Sweeps", group = G_GEN, tooltip = TIP_CTFSWEEP)
  53. bool i_ignoreProx = input.bool(true, "Ignore Close Proximity CISDs", group = G_GEN, tooltip = TIP_PROX)
  54. int i_maxConfirmBars = input.int(15, "Max Bars to Confirm CISD", minval = 1, maxval = 200, group = G_GEN)
  55. int i_pivotLen = 2
  56. float i_proxATR = 0.75
  57.  
  58. string i_liqMode = input.string("Manual", "Alignment Mode", options = ["Automatic", "Manual"], inline = "LQ0", group = G_LIQ)
  59. string i_liqTF = input.timeframe("60", "Timeframe", inline = "LQ0", group = G_LIQ)
  60.  
  61. bool i_showLiq = input.bool(false, "Show Liquidity:", inline = "LQ1", group = G_LIQ)
  62. color i_buysideCol = input.color(#26303E, "Buyside", inline = "LQ1", group = G_LIQ)
  63. color i_sellsideCol = input.color(#26303E, "Sellside", inline = "LQ1", group = G_LIQ)
  64. string i_liqStyle = input.string(STY_DOT, "Line Style", options = [STY_SOLID, STY_DASH, STY_DOT], inline = "LQ2", group = G_LIQ)
  65. string i_liqSize = input.string("Small", "Label Size", options = ["Tiny", "Small", "Normal", "Large"], inline = "LQ2", group = G_LIQ)
  66. int i_liqMax = input.int(2, "Max Liquidity Levels", minval = 1, maxval = 30, inline = "LQ2b", group = G_LIQ)
  67.  
  68. bool i_showSweeps = input.bool(false, "Show Liquidity Sweeps", inline = "LQ3", group = G_LIQ, tooltip = TIP_SWEEP)
  69. color i_sweepCol = input.color(color.new(#787B86, 35), "", inline = "LQ3", group = G_LIQ)
  70. string i_sweepText = input.string("$$$", "", inline = "LQ3", group = G_LIQ)
  71. string i_sweepStyle = input.string(STY_DOT, "Sweep Line Style", options = [STY_SOLID, STY_DASH, STY_DOT], inline = "LQ4", group = G_LIQ)
  72. string i_sweepSize = input.string("Tiny", "Label Size", options = ["Tiny", "Small", "Normal", "Large"], inline = "LQ4", group = G_LIQ)
  73. int i_sweepMax = input.int(2, "Max Sweeps Displayed", minval = 1, maxval = 50, inline = "LQ4b", group = G_LIQ)
  74.  
  75. bool i_showSession = input.bool(true, "Show Session Liquidity", inline = "SS0", group = G_SESS)
  76. bool i_preserveSweep = input.bool(true, "Preserve After Sweep", inline = "SS0", group = G_SESS, tooltip = TIP_PRESERVE)
  77. string i_sessStyle = input.string(STY_DOT, "Session Line Style", options = [STY_SOLID, STY_DASH, STY_DOT], inline = "SS1", group = G_SESS)
  78. string i_sessSize = input.string("Small", "Session Label Size", options = ["Tiny", "Small", "Normal", "Large"], inline = "SS1", group = G_SESS)
  79.  
  80. bool i_asiaOn = input.bool(true, "Asia", inline = "SS2", group = G_SESS)
  81. color i_asiaCol = input.color(#26303E, "", inline = "SS2", group = G_SESS)
  82. string i_asiaStart = input.session("2000-0000", "", inline = "SS2", group = G_SESS)
  83.  
  84. bool i_londonOn = input.bool(true, "London", inline = "SS3", group = G_SESS)
  85. color i_londonCol = input.color(#26303E, "", inline = "SS3", group = G_SESS)
  86. string i_londonStart = input.session("0200-0500", "", inline = "SS3", group = G_SESS)
  87.  
  88. bool i_pdhpdl = input.bool(true, "PDH/PDL PDH", inline = "SS5", group = G_SESS)
  89. color i_pdhCol = input.color(#26303E, "", inline = "SS5", group = G_SESS)
  90. color i_pdlCol = input.color(#26303E, "PDL", inline = "SS5", group = G_SESS)
  91.  
  92. bool i_pwhpwl = input.bool(true, "PWH/PWL PWH", inline = "SS6", group = G_SESS)
  93. color i_pwhCol = input.color(#26303E, "", inline = "SS6", group = G_SESS)
  94. color i_pwlCol = input.color(#26303E, "PWL", inline = "SS6", group = G_SESS)
  95.  
  96. int i_sessExtend = input.int(40, "Level Extension (bars)", minval = 5, maxval = 200, group = G_SESS)
  97.  
  98. bool i_showHtfFvg = input.bool(true, "Show HTF FVGs", inline = "FV0", group = G_FVG)
  99. bool i_fvgBorder = input.bool(false, "Show Border", inline = "FV0", group = G_FVG)
  100. int i_fvgPerSide = input.int(1, "Number of FVGs Displayed Per Side", minval = 1, maxval = 10, group = G_FVG)
  101. string i_htfMode = input.string("Automatic", "HTF Timeframe Mode", options = ["Automatic", "Manual"], group = G_FVG, tooltip = TIP_HTFMODE)
  102. int i_manualHTFs = input.int(3, "Manual HTFs", minval = 1, maxval = 3, group = G_FVG)
  103. string i_tf1 = input.timeframe("60", "TF 1", inline = "FV1", group = G_FVG)
  104. string i_tf2 = input.timeframe("240", "TF 2", inline = "FV1", group = G_FVG)
  105. string i_tf3 = input.timeframe("D", "TF 3", inline = "FV1", group = G_FVG)
  106. color i_fvgLblCol = input.color(#26303E, "Label Color", inline = "FV2", group = G_FVG)
  107. string i_fvgLblSize = input.string("Tiny", "Label Size", options = ["Tiny", "Small", "Normal", "Large"], inline = "FV2", group = G_FVG)
  108. color i_fvgBullCol = input.color(color.new(#9c9c9c, 88), "Bullish Color", inline = "FV3", group = G_FVG)
  109. color i_fvgBearCol = input.color(color.new(#9c9c9c, 88), "Bearish Color", inline = "FV3", group = G_FVG)
  110. bool i_fvgMitigate = true
  111.  
  112. bool i_showCISD = input.bool(true, "Show CISD", group = G_CISD)
  113. bool i_showPotential = input.bool(true, "Show Potential Current-TF CISDs", group = G_CISD, tooltip = TIP_POTENTIAL)
  114. bool i_disableCtfLbl = input.bool(false, "Disable Current TF Labels", group = G_CISD, tooltip = TIP_DISABLELBL)
  115. bool i_cisdFromSMT = input.bool(true, "Detect CISDs from SMTs", group = G_CISD, tooltip = TIP_SMTCISD)
  116. color i_longCol = input.color(C_LONG_DEF, "Long Color", inline = "CS1", group = G_CISD)
  117. color i_shortCol = input.color(C_SHORT_DEF, "Short Color", inline = "CS1", group = G_CISD)
  118. string i_cisdLblSize = input.string("Tiny", "Label Size", options = ["Tiny", "Small", "Normal", "Large"], inline = "CS1", group = G_CISD)
  119. int i_cisdWidth = input.int(1, "Line Width", minval = 1, maxval = 5, inline = "CS2", group = G_CISD)
  120. int i_cisdExtend = input.int(16, "CISD Line Extension (bars)", minval = 1, maxval = 200, inline = "CS2", group = G_CISD)
  121. int i_minSeqLen = 1
  122. int i_maxSeqLen = 12
  123.  
  124. bool i_showSL = input.bool(true, "Show Stop Loss", inline = "RK0", group = G_CISD)
  125. string i_slPlacement = input.string("Wick", "Placement", options = ["Wick", "Body"], inline = "RK0", group = G_CISD, tooltip = TIP_SLPLACE)
  126. color i_slCol = #26303E
  127. string i_slStyle = STY_DOT
  128. int i_slExtendBars = input.int(4, "Stop Loss Line Extension (bars)", minval = 1, maxval = 100, group = G_CISD)
  129. bool i_sizingOn = input.bool(true, "Contract Sizing Risk ($)", inline = "RK2", group = G_CISD, tooltip = TIP_SIZING)
  130. float i_riskUSD = input.float(2000, "", minval = 1, inline = "RK2", group = G_CISD)
  131. bool i_hoverOnly = input.bool(true, "Sizing on Hover Only", group = G_CISD, tooltip = TIP_HOVER)
  132. bool i_showTarget = true
  133. int i_tgtExtendBars = 15
  134. float i_minRR = 1.5
  135.  
  136. bool i_showHtfCISD = input.bool(false, "Show Higher Timeframe CISDs", group = G_HTFCISD)
  137. bool i_htfPotential = input.bool(false, "Show Potential CISDs", inline = "HC0", group = G_HTFCISD)
  138. string i_htfCisdStyle = input.string(STY_DOT, "", options = [STY_SOLID, STY_DASH, STY_DOT], inline = "HC0", group = G_HTFCISD)
  139. bool i_manualHtfCISD = input.bool(false, "Manual Higher Timeframe Selection", group = G_HTFCISD, tooltip = TIP_MANHTF)
  140. string i_htfCisd1 = input.timeframe("2", "Higher Timeframe 1", inline = "HC1", group = G_HTFCISD)
  141. string i_htfCisd2 = input.timeframe("3", "Higher Timeframe 2", inline = "HC1", group = G_HTFCISD)
  142. float i_mergeTolATR = 0.15
  143.  
  144. bool i_showSMT = input.bool(true, "Show SMT Divergences", group = G_SMT)
  145. bool i_autoPair = input.bool(true, "Automatic Correlated Asset", inline = "SM0", group = G_SMT)
  146. string i_manualPair = input.symbol("CME_MINI:ES1!", "", inline = "SM0", group = G_SMT)
  147. string i_smtSens = input.string("Normal", "Sensitivity", options = ["Sensitive", "Normal", "Strict"], group = G_SMT, tooltip = TIP_SENS)
  148. bool i_smtRealtime = input.bool(false, "Real-time SMTs", group = G_SMT, tooltip = TIP_RT)
  149. int i_smtMax = input.int(3, "Max SMTs Displayed", minval = 1, maxval = 20, group = G_SMT)
  150. color i_smtBullCol = input.color(C_LONG_DEF, "Bullish:", inline = "SM1", group = G_SMT)
  151. string i_smtBullWidth = input.string("Thin", "", options = ["Thin", "Medium", "Thick"], inline = "SM1", group = G_SMT)
  152. string i_smtBullStyle = input.string(STY_DOT, "", options = [STY_SOLID, STY_DASH, STY_DOT], inline = "SM1", group = G_SMT)
  153. color i_smtBearCol = input.color(C_SHORT_DEF, "Bearish:", inline = "SM2", group = G_SMT)
  154. string i_smtBearWidth = input.string("Thin", "", options = ["Thin", "Medium", "Thick"], inline = "SM2", group = G_SMT)
  155. string i_smtBearStyle = input.string(STY_DOT, "", options = [STY_SOLID, STY_DASH, STY_DOT], inline = "SM2", group = G_SMT)
  156. bool i_smtLabel = input.bool(true, "Label", inline = "SM3", group = G_SMT)
  157. color i_smtLblCol = input.color(#26303E, "", inline = "SM3", group = G_SMT)
  158. string i_smtLblSize = input.string("Tiny", "Size", options = ["Tiny", "Small", "Normal", "Large"], inline = "SM3", group = G_SMT)
  159. bool i_smtSymbol = input.bool(true, "Show symbol", inline = "SM3", group = G_SMT)
  160. int i_smtLookback = input.int(6, "SMT Lookback (bars)", minval = 1, maxval = 50, group = G_SMT)
  161.  
  162. bool i_alertsOn = input.bool(true, "Enable Alerts", group = G_ALERT, tooltip = TIP_ALERTS)
  163. bool i_alertS1 = input.bool(true, "Session 1", inline = "AL1", group = G_ALERT)
  164. string i_alertS1Win = input.session("0600-1600", "", inline = "AL1", group = G_ALERT)
  165. bool i_alertS2 = input.bool(false, "Session 2", inline = "AL2", group = G_ALERT)
  166. string i_alertS2Win = input.session("2000-0000", "", inline = "AL2", group = G_ALERT)
  167. bool i_alertS3 = input.bool(false, "Session 3", inline = "AL3", group = G_ALERT)
  168. string i_alertS3Win = input.session("0200-0500", "", inline = "AL3", group = G_ALERT)
  169. bool i_alertConfirmed = input.bool(true, "Confirmed CISD", inline = "AL4", group = G_ALERT)
  170. string i_msgConfirmed = input.string("CISD confirmed", "", inline = "AL4", group = G_ALERT)
  171. bool i_alertPotential = input.bool(false, "Potential CISD", inline = "AL5", group = G_ALERT)
  172. string i_msgPotential = input.string("Potential CISD", "", inline = "AL5", group = G_ALERT)
  173. bool i_alertHTF = input.bool(false, "HTF CISD", inline = "AL6", group = G_ALERT)
  174. string i_msgHTF = input.string("HTF CISD detected", "", inline = "AL6", group = G_ALERT)
  175. bool i_alertSweep = false
  176. string i_msgSweep = "Liquidity swept"
  177. bool i_alertSMT = false
  178. string i_msgSMT = "SMT divergence"
  179.  
  180. bool i_showInfoBox = input.bool(true, "Show Info Box", group = G_WM)
  181. color i_wmTextCol = input.color(color.new(#787B86, 35), "Text Color", group = G_WM)
  182. string i_wmSite = input.string("cisdmodel.com", "Site Text", group = G_WM)
  183. string i_wmLine1 = input.string("CISD Model+ | Triton Trades", "Line 1 Text", group = G_WM)
  184. bool i_wmShowDate = true
  185. string i_wmPos = "Bottom Center"
  186.  
  187. bool i_showChecklist = input.bool(true, "Show Strategy Checklist", inline = "CK0", group = G_CHECK)
  188. bool i_showGrade = input.bool(true, "Show Setup Grade", inline = "CK0", group = G_CHECK)
  189. string i_tblSize = input.string("Small", "Table Text Size", options = ["Tiny", "Small", "Normal", "Large"], inline = "CK1", group = G_CHECK)
  190. color i_cellCol = input.color(color.new(#b2b5be, 75), "Cell Normal", inline = "CK1", group = G_CHECK)
  191. color i_hdrBg = input.color(#434651, "Header Background", inline = "CK2", group = G_CHECK)
  192. color i_hdrTxt = input.color(#e0e3eb, "Header Text", inline = "CK2", group = G_CHECK)
  193. bool i_ckTintRows = false
  194. color i_ckPassCol = color.new(#089981, 78)
  195. color i_ckFailCol = color.new(#F23645, 82)
  196. string i_tblPos = input.string("Bottom Right", "Checklist Position", options = ["Top Left", "Top Right", "Middle Right", "Bottom Left", "Bottom Right"], group = G_CHECK)
  197. bool i_ckSweep = input.bool(true, "Liquidity Sweep", inline = "CK3", group = G_CHECK)
  198. bool i_ckPDA = input.bool(true, "HTF PDA Delivery", inline = "CK3", group = G_CHECK)
  199. bool i_ckVolume = input.bool(true, "Volume", inline = "CK4", group = G_CHECK)
  200. bool i_ckSession = input.bool(true, "Session Sweep", inline = "CK4", group = G_CHECK)
  201. bool i_ckTargets = input.bool(true, "Clear Targets", inline = "CK5", group = G_CHECK)
  202. bool i_ckSMT = input.bool(true, "SMT", inline = "CK5", group = G_CHECK)
  203. float i_volMult = 1.2
  204.  
  205. lineStyle(string s) =>
  206. switch s
  207. STY_SOLID => line.style_solid
  208. STY_DASH => line.style_dashed
  209. STY_DOT => line.style_dotted
  210. => line.style_solid
  211.  
  212. txtSize(string s) =>
  213. switch s
  214. "Tiny" => size.tiny
  215. "Small" => size.small
  216. "Normal" => size.normal
  217. "Large" => size.large
  218. "Huge" => size.huge
  219. => size.small
  220.  
  221. widthOf(string s) =>
  222. switch s
  223. "Thin" => 1
  224. "Medium" => 2
  225. "Thick" => 3
  226. => 1
  227.  
  228. tblPosOf(string s) =>
  229. switch s
  230. "Top Left" => position.top_left
  231. "Top Center" => position.top_center
  232. "Top Right" => position.top_right
  233. "Middle Center" => position.middle_center
  234. "Middle Right" => position.middle_right
  235. "Bottom Left" => position.bottom_left
  236. "Bottom Center" => position.bottom_center
  237. "Bottom Right" => position.bottom_right
  238. => position.bottom_right
  239.  
  240. gradeText(int g) =>
  241. switch g
  242. 7 => "A+"
  243. 6 => "A"
  244. 5 => "B+"
  245. 4 => "B-"
  246. 3 => "C"
  247. => "-"
  248.  
  249. gradeRank(string g) =>
  250. switch g
  251. "A+" => 7
  252. "A" => 6
  253. "B+" => 5
  254. "B-" => 4
  255. "C" => 3
  256. => 0
  257.  
  258. gradeColor(int g) =>
  259. switch g
  260. 7 => color.new(#00C853, 0)
  261. 6 => color.new(#64DD17, 0)
  262. 5 => color.new(#9ACD32, 0)
  263. 4 => color.new(#FFB300, 0)
  264. 3 => color.new(#FF7043, 0)
  265. => color.new(#787B86, 0)
  266.  
  267. tfLabel(string tf) =>
  268. string res = tf
  269. if str.contains(tf, "S")
  270. res := "S" + str.replace_all(tf, "S", "")
  271. else if tf == "D" or tf == "1D"
  272. res := "D1"
  273. else if tf == "W" or tf == "1W"
  274. res := "W1"
  275. else if tf == "M" or tf == "1M"
  276. res := "MN"
  277. else
  278. int mins = na(str.tonumber(tf)) ? na : int(str.tonumber(tf))
  279. if na(mins)
  280. res := tf
  281. else if mins >= 60 and mins % 60 == 0
  282. res := "H" + str.tostring(mins / 60)
  283. else
  284. res := "M" + str.tostring(mins)
  285. res
  286.  
  287. int TF_SEC = timeframe.in_seconds(timeframe.period)
  288.  
  289. autoFvgTF1() =>
  290. string r = "60"
  291. if TF_SEC <= 60
  292. r := "15"
  293. else if TF_SEC <= 300
  294. r := "60"
  295. else if TF_SEC <= 900
  296. r := "240"
  297. else if TF_SEC <= 3600
  298. r := "D"
  299. else
  300. r := "W"
  301. r
  302.  
  303. autoFvgTF2() =>
  304. string r = "240"
  305. if TF_SEC <= 60
  306. r := "60"
  307. else if TF_SEC <= 300
  308. r := "240"
  309. else if TF_SEC <= 900
  310. r := "D"
  311. else if TF_SEC <= 3600
  312. r := "W"
  313. else
  314. r := "M"
  315. r
  316.  
  317. autoFvgTF3() =>
  318. string r = "D"
  319. if TF_SEC <= 300
  320. r := "D"
  321. else if TF_SEC <= 3600
  322. r := "W"
  323. else
  324. r := "M"
  325. r
  326.  
  327. autoCisdTF1() =>
  328. string r = "5"
  329. if TF_SEC <= 60
  330. r := "2"
  331. else if TF_SEC <= 120
  332. r := "3"
  333. else if TF_SEC <= 180
  334. r := "5"
  335. else if TF_SEC <= 300
  336. r := "15"
  337. else if TF_SEC <= 900
  338. r := "60"
  339. else if TF_SEC <= 3600
  340. r := "240"
  341. else
  342. r := "D"
  343. r
  344.  
  345. autoCisdTF2() =>
  346. string r = "15"
  347. if TF_SEC <= 60
  348. r := "3"
  349. else if TF_SEC <= 120
  350. r := "5"
  351. else if TF_SEC <= 180
  352. r := "15"
  353. else if TF_SEC <= 300
  354. r := "30"
  355. else if TF_SEC <= 900
  356. r := "240"
  357. else if TF_SEC <= 3600
  358. r := "D"
  359. else
  360. r := "W"
  361. r
  362.  
  363. autoLiqTF() =>
  364. string r = "60"
  365. if TF_SEC <= 60
  366. r := "15"
  367. else if TF_SEC <= 300
  368. r := "60"
  369. else
  370. r := "240"
  371. r
  372.  
  373. string FVG_TF1 = i_htfMode == "Automatic" ? autoFvgTF1() : i_tf1
  374. string FVG_TF2 = i_htfMode == "Automatic" ? autoFvgTF2() : i_tf2
  375. string FVG_TF3 = i_htfMode == "Automatic" ? autoFvgTF3() : i_tf3
  376. string HC_TF1 = i_manualHtfCISD ? i_htfCisd1 : autoCisdTF1()
  377. string HC_TF2 = i_manualHtfCISD ? i_htfCisd2 : autoCisdTF2()
  378. string LIQ_TF = i_liqMode == "Automatic" ? autoLiqTF() : i_liqTF
  379.  
  380. resolvePair() =>
  381. string sym = i_manualPair
  382. if i_autoPair
  383. string root = syminfo.ticker
  384. string mapped = switch root
  385. "ES1!" => "NQ1!"
  386. "NQ1!" => "ES1!"
  387. "YM1!" => "ES1!"
  388. "RTY1!" => "ES1!"
  389. "GC1!" => "SI1!"
  390. "SI1!" => "GC1!"
  391. "CL1!" => "RB1!"
  392. "RB1!" => "CL1!"
  393. "6E1!" => "6B1!"
  394. "6B1!" => "6E1!"
  395. "6A1!" => "6N1!"
  396. "6N1!" => "6A1!"
  397. "BTC1!" => "ETH1!"
  398. "ETH1!" => "BTC1!"
  399. "BTCUSD" => "ETHUSD"
  400. "ETHUSD" => "BTCUSD"
  401. "BTCUSDT" => "ETHUSDT"
  402. "ETHUSDT" => "BTCUSDT"
  403. "USDJPY" => "DXY"
  404. "USDCHF" => "DXY"
  405. "USDCAD" => "DXY"
  406. "DXY" => "USDJPY"
  407. "EURUSD" => "GBPUSD"
  408. "GBPUSD" => "EURUSD"
  409. "AUDUSD" => "NZDUSD"
  410. "NZDUSD" => "AUDUSD"
  411. "AUDCAD" => "NZDCAD"
  412. "NZDCAD" => "AUDCAD"
  413. "EURCAD" => "GBPCAD"
  414. "GBPCAD" => "EURCAD"
  415. "EURAUD" => "GBPAUD"
  416. "GBPAUD" => "EURAUD"
  417. "EURNZD" => "GBPNZD"
  418. "GBPNZD" => "EURNZD"
  419. "EURJPY" => "GBPJPY"
  420. "GBPJPY" => "EURJPY"
  421. "AUDJPY" => "NZDJPY"
  422. "NZDJPY" => "AUDJPY"
  423. "XAUUSD" => "XAGUSD"
  424. "XAGUSD" => "XAUUSD"
  425. => ""
  426. if mapped != ""
  427. sym := syminfo.prefix + ":" + mapped
  428. else
  429. sym := i_manualPair
  430. sym
  431.  
  432. string SMT_SYMBOL = resolvePair()
  433. string SMT_SHORT = str.replace_all(str.substring(SMT_SYMBOL, na(str.pos(SMT_SYMBOL, ":")) ? 0 : str.pos(SMT_SYMBOL, ":") + 1), "1!", "")
  434.  
  435. type Liq
  436. float price
  437. int bar
  438. bool buyside
  439. bool swept
  440. line ln
  441. label lb
  442.  
  443. type Sweep
  444. float price
  445. int bar
  446. bool buyside
  447. line ln
  448. label lb
  449.  
  450. type Fvg
  451. float top
  452. float bot
  453. int bar
  454. bool bull
  455. bool mitigated
  456. string tf
  457. box bx
  458. label lb
  459.  
  460. type Cisd
  461. float level
  462. float extreme
  463. float bodyExtreme
  464. int startBar
  465. int endBar
  466. int slBar
  467. int confirmBar
  468. bool bull
  469. bool confirmed
  470. bool invalidated
  471. bool potential
  472. string tf
  473. int grade
  474. bool ckSweep
  475. bool ckPDA
  476. bool ckVol
  477. bool ckSession
  478. bool ckTargets
  479. bool ckSMT
  480. float target
  481. int contracts
  482. float slPrice
  483. line ln
  484. line slLn
  485. label lb
  486. label slLb
  487.  
  488. type Smt
  489. int bar1
  490. int bar2
  491. float p1
  492. float p2
  493. bool bull
  494. line ln
  495. label lb
  496.  
  497. type SessLvl
  498. string name
  499. float price
  500. int bar
  501. bool high
  502. bool swept
  503. line ln
  504. label lb
  505. int sweptTime
  506.  
  507. var array<Liq> liqBuy = array.new<Liq>()
  508. var array<Liq> liqSell = array.new<Liq>()
  509. var array<Sweep> sweeps = array.new<Sweep>()
  510. var array<Fvg> fvgs = array.new<Fvg>()
  511. var array<Cisd> cisdBull = array.new<Cisd>()
  512. var array<Cisd> cisdBear = array.new<Cisd>()
  513. var array<Cisd> cisdHtf = array.new<Cisd>()
  514. var array<Smt> smts = array.new<Smt>()
  515. var array<SessLvl> sessLvls = array.new<SessLvl>()
  516.  
  517. var float lastGradeBull = 0.0
  518. var float lastGradeBear = 0.0
  519. var int lastGradeVal = 0
  520. var bool lastGradeIsBull = true
  521.  
  522. var array<int> g_barTimes = array.new<int>()
  523. array.push(g_barTimes, int(time))
  524.  
  525. findBarIndexByTime(int t) =>
  526. int lo = 0
  527. int hi = array.size(g_barTimes) - 1
  528. int result = 0
  529. while lo <= hi
  530. int mid = math.floor((lo + hi) / 2.0)
  531. int midTime = array.get(g_barTimes, mid)
  532. if midTime <= t
  533. result := mid
  534. lo := mid + 1
  535. else
  536. hi := mid - 1
  537. result
  538.  
  539. float atr = ta.atr(14)
  540. float volSMA = ta.sma(volume, 20)
  541. bool volSpike = not na(volSMA) and volume > volSMA * i_volMult
  542.  
  543. bool biasAllowsLong = i_bias != "Bearish"
  544. bool biasAllowsShort = i_bias != "Bullish"
  545.  
  546. float ph = ta.pivothigh(high, i_pivotLen, i_pivotLen)
  547. float pl = ta.pivotlow(low, i_pivotLen, i_pivotLen)
  548.  
  549. int smtLen = switch i_smtSens
  550. "Sensitive" => 2
  551. "Normal" => 5
  552. "Strict" => 10
  553. => 5
  554.  
  555. float smtPh = ta.pivothigh(high, smtLen, smtLen)
  556. float smtPl = ta.pivotlow(low, smtLen, smtLen)
  557.  
  558. [cmpHigh, cmpLow, cmpClose, cmpOpen] = request.security(SMT_SYMBOL, timeframe.period, [high, low, close, open], barmerge.gaps_off, barmerge.lookahead_off)
  559.  
  560. float cmpPh = ta.pivothigh(cmpHigh, smtLen, smtLen)
  561. float cmpPl = ta.pivotlow(cmpLow, smtLen, smtLen)
  562.  
  563. pruneLiq(array<Liq> arr, int maxN) =>
  564. while array.size(arr) > maxN
  565. Liq old = array.shift(arr)
  566. if not na(old.ln)
  567. line.delete(old.ln)
  568. if not na(old.lb)
  569. label.delete(old.lb)
  570.  
  571. addLiq(bool buyside, float price, int bar) =>
  572. Liq l = Liq.new(price, bar, buyside, false, na, na)
  573. if i_showLiq
  574. l.ln := line.new(bar, price, bar_index, price, xloc = xloc.bar_index, color = buyside ? i_buysideCol : i_sellsideCol, style = lineStyle(i_liqStyle), width = 1)
  575. l.lb := label.new(bar_index, price, buyside ? "BSL" : "SSL", xloc = xloc.bar_index, style = buyside ? label.style_label_down : label.style_label_up, color = color.new(color.white, 100), textcolor = buyside ? i_buysideCol : i_sellsideCol, size = txtSize(i_liqSize))
  576. array.push(buyside ? liqBuy : liqSell, l)
  577. pruneLiq(buyside ? liqBuy : liqSell, i_liqMax)
  578.  
  579. if not na(ph)
  580. addLiq(true, ph, bar_index - i_pivotLen)
  581.  
  582. if not na(pl)
  583. addLiq(false, pl, bar_index - i_pivotLen)
  584.  
  585. extendLiqArray(array<Liq> arr) =>
  586. if array.size(arr) > 0
  587. for i = 0 to array.size(arr) - 1
  588. Liq l = array.get(arr, i)
  589. if not l.swept and not na(l.ln)
  590. line.set_x2(l.ln, bar_index + 3)
  591. if not na(l.lb)
  592. label.set_x(l.lb, bar_index + 3)
  593.  
  594. if i_showLiq and barstate.islast
  595. extendLiqArray(liqBuy)
  596. extendLiqArray(liqSell)
  597.  
  598. pruneSweeps() =>
  599. while array.size(sweeps) > i_sweepMax
  600. Sweep s = array.shift(sweeps)
  601. if not na(s.ln)
  602. line.delete(s.ln)
  603. if not na(s.lb)
  604. label.delete(s.lb)
  605.  
  606. var bool sweptBuyNow = false
  607. var bool sweptSellNow = false
  608. var int lastSweepBuyBar = -10000
  609. var int lastSweepSellBar = -10000
  610. var float lastSweepBuyPx = na
  611. var float lastSweepSellPx = na
  612.  
  613. sweptBuyNow := false
  614. sweptSellNow := false
  615.  
  616. if array.size(liqBuy) > 0
  617. for i = array.size(liqBuy) - 1 to 0
  618. Liq l = array.get(liqBuy, i)
  619. if not l.swept and high > l.price and close < l.price
  620. l.swept := true
  621. sweptBuyNow := true
  622. lastSweepBuyBar := bar_index
  623. lastSweepBuyPx := l.price
  624. if i_showSweeps
  625. Sweep s = Sweep.new(l.price, bar_index, true, na, na)
  626. s.ln := line.new(l.bar, l.price, bar_index, l.price, xloc = xloc.bar_index, color = i_sweepCol, style = lineStyle(i_sweepStyle), width = 1)
  627. s.lb := label.new(bar_index, l.price, i_sweepText, xloc = xloc.bar_index, style = label.style_label_down, color = color.new(color.white, 100), textcolor = i_sweepCol, size = txtSize(i_sweepSize))
  628. array.push(sweeps, s)
  629. pruneSweeps()
  630.  
  631. if array.size(liqSell) > 0
  632. for i = array.size(liqSell) - 1 to 0
  633. Liq l = array.get(liqSell, i)
  634. if not l.swept and low < l.price and close > l.price
  635. l.swept := true
  636. sweptSellNow := true
  637. lastSweepSellBar := bar_index
  638. lastSweepSellPx := l.price
  639. if i_showSweeps
  640. Sweep s = Sweep.new(l.price, bar_index, false, na, na)
  641. s.ln := line.new(l.bar, l.price, bar_index, l.price, xloc = xloc.bar_index, color = i_sweepCol, style = lineStyle(i_sweepStyle), width = 1)
  642. s.lb := label.new(bar_index, l.price, i_sweepText, xloc = xloc.bar_index, style = label.style_label_up, color = color.new(color.white, 100), textcolor = i_sweepCol, size = txtSize(i_sweepSize))
  643. array.push(sweeps, s)
  644. pruneSweeps()
  645.  
  646. [htfPh, htfPl] = request.security(syminfo.tickerid, LIQ_TF, [ta.pivothigh(high, 2, 2), ta.pivotlow(low, 2, 2)], barmerge.gaps_off, barmerge.lookahead_off)
  647.  
  648. var float htfBSL = na
  649. var float htfSSL = na
  650. var int htfSweepBuyBar = -10000
  651. var int htfSweepSellBar = -10000
  652.  
  653. if not na(htfPh) and htfPh != htfPh[1]
  654. htfBSL := htfPh
  655. if not na(htfPl) and htfPl != htfPl[1]
  656. htfSSL := htfPl
  657.  
  658. if not na(htfBSL) and high > htfBSL and close < htfBSL
  659. htfSweepBuyBar := bar_index
  660. if not na(htfSSL) and low < htfSSL and close > htfSSL
  661. htfSweepSellBar := bar_index
  662.  
  663. string TZ = "America/New_York"
  664.  
  665. bool inAsia = not na(time(timeframe.period, i_asiaStart, TZ))
  666. bool inLondon = not na(time(timeframe.period, i_londonStart, TZ))
  667.  
  668. var float asiaH = na
  669. var float asiaL = na
  670. var int asiaHb = na
  671. var int asiaLb = na
  672. var float lonH = na
  673. var float lonL = na
  674. var int lonHb = na
  675. var int lonLb = na
  676.  
  677. dateTag() =>
  678. str.tostring(month(time, TZ)) + "/" + str.tostring(dayofmonth(time, TZ))
  679.  
  680. pushSess(string nm, float px, int bar, bool isHigh, color col) =>
  681. if i_showSession and not na(px)
  682. SessLvl s = SessLvl.new(nm, px, bar, isHigh, false, na, na, na)
  683. s.ln := line.new(bar, px, bar_index + i_sessExtend, px, xloc = xloc.bar_index, color = col, style = lineStyle(i_sessStyle), width = 1)
  684. s.lb := label.new(bar_index + i_sessExtend - 4, px, nm, xloc = xloc.bar_index, style = isHigh ? label.style_label_down : label.style_label_up, color = color.new(color.white, 100), textcolor = col, size = txtSize(i_sessSize))
  685. array.push(sessLvls, s)
  686. while array.size(sessLvls) > 24
  687. SessLvl o = array.shift(sessLvls)
  688. if not na(o.ln)
  689. line.delete(o.ln)
  690. if not na(o.lb)
  691. label.delete(o.lb)
  692.  
  693. if i_asiaOn
  694. if inAsia and not inAsia[1]
  695. asiaH := high
  696. asiaL := low
  697. asiaHb := bar_index
  698. asiaLb := bar_index
  699. else if inAsia
  700. if high > nz(asiaH, high)
  701. asiaH := high
  702. asiaHb := bar_index
  703. if low < nz(asiaL, low)
  704. asiaL := low
  705. asiaLb := bar_index
  706. if not inAsia and inAsia[1]
  707. pushSess(dateTag() + " ASIA.H", asiaH, nz(asiaHb, bar_index), true, i_asiaCol)
  708. pushSess(dateTag() + " ASIA.L", asiaL, nz(asiaLb, bar_index), false, i_asiaCol)
  709.  
  710. if i_londonOn
  711. if inLondon and not inLondon[1]
  712. lonH := high
  713. lonL := low
  714. lonHb := bar_index
  715. lonLb := bar_index
  716. else if inLondon
  717. if high > nz(lonH, high)
  718. lonH := high
  719. lonHb := bar_index
  720. if low < nz(lonL, low)
  721. lonL := low
  722. lonLb := bar_index
  723. if not inLondon and inLondon[1]
  724. pushSess(dateTag() + " LON.H", lonH, nz(lonHb, bar_index), true, i_londonCol)
  725. pushSess(dateTag() + " LON.L", lonL, nz(lonLb, bar_index), false, i_londonCol)
  726.  
  727. var float curDayH = na
  728. var float curDayL = na
  729. var int curDayHb = na
  730. var int curDayLb = na
  731. var float pdh = na
  732. var float pdl = na
  733. var int pdhBar = na
  734. var int pdlBar = na
  735.  
  736. var float curWeekH = na
  737. var float curWeekL = na
  738. var int curWeekHb = na
  739. var int curWeekLb = na
  740. var float pwh = na
  741. var float pwl = na
  742. var int pwhBar = na
  743. var int pwlBar = na
  744.  
  745. var line pdhLn = na
  746. var line pdlLn = na
  747. var line pwhLn = na
  748. var line pwlLn = na
  749. var label pdhLb = na
  750. var label pdlLb = na
  751. var label pwhLb = na
  752. var label pwlLb = na
  753.  
  754. var bool pdhSwept = false
  755. var bool pdlSwept = false
  756. var bool pwhSwept = false
  757. var bool pwlSwept = false
  758.  
  759. bool newDay = ta.change(time("D")) != 0
  760. bool newWeek = ta.change(time("W")) != 0
  761.  
  762. if newDay
  763. pdh := curDayH
  764. pdl := curDayL
  765. pdhBar := curDayHb
  766. pdlBar := curDayLb
  767. pdhSwept := false
  768. pdlSwept := false
  769. curDayH := high
  770. curDayL := low
  771. curDayHb := time
  772. curDayLb := time
  773. else
  774. if na(curDayH) or high > curDayH
  775. curDayH := high
  776. curDayHb := time
  777. if na(curDayL) or low < curDayL
  778. curDayL := low
  779. curDayLb := time
  780.  
  781. if newWeek
  782. pwh := curWeekH
  783. pwl := curWeekL
  784. pwhBar := curWeekHb
  785. pwlBar := curWeekLb
  786. pwhSwept := false
  787. pwlSwept := false
  788. curWeekH := high
  789. curWeekL := low
  790. curWeekHb := time
  791. curWeekLb := time
  792. else
  793. if na(curWeekH) or high > curWeekH
  794. curWeekH := high
  795. curWeekHb := time
  796. if na(curWeekL) or low < curWeekL
  797. curWeekL := low
  798. curWeekLb := time
  799.  
  800. if i_pdhpdl and not na(pdh) and not pdhSwept and high > pdh
  801. pdhSwept := true
  802. if i_pdhpdl and not na(pdl) and not pdlSwept and low < pdl
  803. pdlSwept := true
  804. if i_pwhpwl and not na(pwh) and not pwhSwept and high > pwh
  805. pwhSwept := true
  806. if i_pwhpwl and not na(pwl) and not pwlSwept and low < pwl
  807. pwlSwept := true
  808.  
  809. drawKeyLevel(line ln, label lb, float px, int startT, bool swept, color col, string txt, bool isHigh) =>
  810. line outLn = ln
  811. label outLb = lb
  812. if not na(px) and not na(startT) and (not swept or i_preserveSweep)
  813. int x1 = startT
  814. int extTime = int(timeframe.in_seconds() * 1000 * i_sessExtend)
  815. int x2 = swept ? time : time + extTime
  816. if na(outLn)
  817. outLn := line.new(x1, px, x2, px, xloc = xloc.bar_time, color = col, style = lineStyle(swept ? STY_DOT : i_sessStyle))
  818. outLb := label.new(x2, px, txt, xloc = xloc.bar_time, style = isHigh ? label.style_label_down : label.style_label_up, color = color.new(color.white, 100), textcolor = col, size = txtSize(i_sessSize))
  819. else
  820. line.set_xy1(outLn, x1, px)
  821. line.set_xy2(outLn, x2, px)
  822. line.set_style(outLn, lineStyle(swept ? STY_DOT : i_sessStyle))
  823. label.set_xy(outLb, x2, px)
  824. else
  825. if not na(outLn)
  826. line.delete(outLn)
  827. outLn := na
  828. if not na(outLb)
  829. label.delete(outLb)
  830. outLb := na
  831. [outLn, outLb]
  832.  
  833. if barstate.islast
  834. if i_pdhpdl
  835. [t_pdhLn, t_pdhLb] = drawKeyLevel(pdhLn, pdhLb, pdh, pdhBar, pdhSwept, i_pdhCol, "PDH", true)
  836. pdhLn := t_pdhLn
  837. pdhLb := t_pdhLb
  838.  
  839. [t_pdlLn, t_pdlLb] = drawKeyLevel(pdlLn, pdlLb, pdl, pdlBar, pdlSwept, i_pdlCol, "PDL", false)
  840. pdlLn := t_pdlLn
  841. pdlLb := t_pdlLb
  842.  
  843. if i_pwhpwl
  844. [t_pwhLn, t_pwhLb] = drawKeyLevel(pwhLn, pwhLb, pwh, pwhBar, pwhSwept, i_pwhCol, "PWH", true)
  845. pwhLn := t_pwhLn
  846. pwhLb := t_pwhLb
  847.  
  848. [t_pwlLn, t_pwlLb] = drawKeyLevel(pwlLn, pwlLb, pwl, pwlBar, pwlSwept, i_pwlCol, "PWL", false)
  849. pwlLn := t_pwlLn
  850. pwlLb := t_pwlLb
  851.  
  852. var int lastSessSweepBar = -10000
  853. var bool lastSessSweepWasHigh = false
  854.  
  855. if array.size(sessLvls) > 0
  856. for i = array.size(sessLvls) - 1 to 0
  857. SessLvl s = array.get(sessLvls, i)
  858. if not s.swept
  859. bool hit = s.high ? high > s.price : low < s.price
  860. if hit
  861. s.swept := true
  862. s.sweptTime := time
  863. lastSessSweepBar := bar_index
  864. lastSessSweepWasHigh := s.high
  865. if not i_preserveSweep
  866. if not na(s.ln)
  867. line.delete(s.ln)
  868. s.ln := na
  869. if not na(s.lb)
  870. label.delete(s.lb)
  871. s.lb := na
  872. else
  873. if not na(s.ln)
  874. line.set_style(s.ln, line.style_dotted)
  875. line.set_x2(s.ln, bar_index)
  876. if not na(s.lb)
  877. label.set_x(s.lb, bar_index)
  878. else
  879. if not na(s.ln) and i_preserveSweep
  880. line.set_x2(s.ln, math.max(line.get_x2(s.ln), s.bar + 1))
  881.  
  882. if array.size(sessLvls) > 0
  883. for i = array.size(sessLvls) - 1 to 0
  884. SessLvl s = array.get(sessLvls, i)
  885. if s.swept and not na(s.sweptTime) and (time - s.sweptTime) > 86400000
  886. if not na(s.ln)
  887. line.delete(s.ln)
  888. if not na(s.lb)
  889. label.delete(s.lb)
  890. array.remove(sessLvls, i)
  891.  
  892. if barstate.islast and array.size(sessLvls) > 0
  893. for i = 0 to array.size(sessLvls) - 1
  894. SessLvl s = array.get(sessLvls, i)
  895. if not s.swept and not na(s.ln)
  896. line.set_x2(s.ln, bar_index + i_sessExtend)
  897. if not na(s.lb)
  898. label.set_x(s.lb, bar_index + i_sessExtend - 4)
  899.  
  900. nearestTargetAbove() =>
  901. float best = na
  902. if array.size(sessLvls) > 0
  903. for i = 0 to array.size(sessLvls) - 1
  904. SessLvl s = array.get(sessLvls, i)
  905. if not s.swept and s.price > close
  906. best := na(best) ? s.price : math.min(best, s.price)
  907. if i_pdhpdl and not pdhSwept and not na(pdh) and pdh > close
  908. best := na(best) ? pdh : math.min(best, pdh)
  909. if i_pwhpwl and not pwhSwept and not na(pwh) and pwh > close
  910. best := na(best) ? pwh : math.min(best, pwh)
  911. best
  912.  
  913. nearestTargetBelow() =>
  914. float best = na
  915. if array.size(sessLvls) > 0
  916. for i = 0 to array.size(sessLvls) - 1
  917. SessLvl s = array.get(sessLvls, i)
  918. if not s.swept and s.price < close
  919. best := na(best) ? s.price : math.max(best, s.price)
  920. if i_pdhpdl and not pdlSwept and not na(pdl) and pdl < close
  921. best := na(best) ? pdl : math.max(best, pdl)
  922. if i_pwhpwl and not pwlSwept and not na(pwl) and pwl < close
  923. best := na(best) ? pwl : math.max(best, pwl)
  924. best
  925.  
  926. bool ctfBullFvg = low > high[2] and close[1] > high[2]
  927. bool ctfBearFvg = high < low[2] and close[1] < low[2]
  928.  
  929. var float ctfBullFvgTop = na
  930. var float ctfBullFvgBot = na
  931. var int ctfBullFvgBar = na
  932. var float ctfBearFvgTop = na
  933. var float ctfBearFvgBot = na
  934. var int ctfBearFvgBar = na
  935.  
  936. if ctfBullFvg
  937. ctfBullFvgTop := low
  938. ctfBullFvgBot := high[2]
  939. ctfBullFvgBar := bar_index
  940. if ctfBearFvg
  941. ctfBearFvgTop := low[2]
  942. ctfBearFvgBot := high
  943. ctfBearFvgBar := bar_index
  944.  
  945. bool inCtfBullFvg = not na(ctfBullFvgBot) and low <= ctfBullFvgTop and low >= ctfBullFvgBot
  946. bool inCtfBearFvg = not na(ctfBearFvgTop) and high >= ctfBearFvgBot and high <= ctfBearFvgTop
  947.  
  948. var int lastCtfFvgDeliverLong = -10000
  949. var int lastCtfFvgDeliverShort = -10000
  950. if inCtfBullFvg
  951. lastCtfFvgDeliverLong := bar_index
  952. if inCtfBearFvg
  953. lastCtfFvgDeliverShort := bar_index
  954.  
  955. reqFvg(string tf) =>
  956. request.security(syminfo.tickerid, tf, [high[3], low[3], high[2], low[2], high[1], low[1], time[1], time[3]], barmerge.gaps_off, barmerge.lookahead_off)
  957.  
  958. [t1h2, t1l2, t1h1, t1l1, t1h0, t1l0, t1t, t1t2] = reqFvg(FVG_TF1)
  959. [t2h2, t2l2, t2h1, t2l1, t2h0, t2l0, t2t, t2t2] = reqFvg(FVG_TF2)
  960. [t3h2, t3l2, t3h1, t3l1, t3h0, t3l0, t3t, t3t2] = reqFvg(FVG_TF3)
  961.  
  962. countFvg(bool bull, string tf) =>
  963. int n = 0
  964. if array.size(fvgs) > 0
  965. for i = 0 to array.size(fvgs) - 1
  966. Fvg f = array.get(fvgs, i)
  967. if f.bull == bull and f.tf == tf and not f.mitigated
  968. n += 1
  969. n
  970.  
  971. dropOldestFvg(bool bull, string tf) =>
  972. int idx = -1
  973. if array.size(fvgs) > 0
  974. for i = 0 to array.size(fvgs) - 1
  975. Fvg f = array.get(fvgs, i)
  976. if f.bull == bull and f.tf == tf
  977. idx := i
  978. break
  979. if idx >= 0
  980. Fvg f = array.remove(fvgs, idx)
  981. if not na(f.bx)
  982. box.delete(f.bx)
  983. if not na(f.lb)
  984. label.delete(f.lb)
  985.  
  986. addFvg(bool bull, float top, float bot, string tf, int startBar) =>
  987. if i_showHtfFvg and not na(top) and not na(bot) and top > bot
  988. Fvg f = Fvg.new(top, bot, startBar, bull, false, tf, na, na)
  989. f.bx := box.new(startBar, top, bar_index + 5, bot, xloc = xloc.bar_index, border_color = i_fvgBorder ? (bull ? C_BULL_FVG : C_BEAR_FVG) : color.new(color.white, 100), border_width = i_fvgBorder ? 1 : 0, bgcolor = bull ? i_fvgBullCol : i_fvgBearCol)
  990. float midY = math.avg(top, bot)
  991. f.lb := label.new(bar_index + 5, midY, tfLabel(tf) + " FVG" + (bull ? "+" : "-"), xloc = xloc.bar_index, style = label.style_label_right, color = color.new(color.white, 100), textcolor = i_fvgLblCol, size = txtSize(i_fvgLblSize))
  992. array.push(fvgs, f)
  993. while countFvg(bull, tf) > i_fvgPerSide
  994. dropOldestFvg(bull, tf)
  995.  
  996. processTf(string tf, float h2, float l2, float h0, float l0, float tTime, float tTime2) =>
  997. bool isNew = ta.change(tTime) != 0
  998. if isNew and not na(h2) and not na(l2)
  999. int startBar = na(tTime2) ? bar_index : findBarIndexByTime(int(tTime2))
  1000. if l0 > h2
  1001. addFvg(true, l0, h2, tf, startBar)
  1002. if h0 < l2
  1003. addFvg(false, l2, h0, tf, startBar)
  1004.  
  1005. if i_showHtfFvg
  1006. processTf(FVG_TF1, t1h2, t1l2, t1h0, t1l0, t1t, t1t2)
  1007. if i_htfMode == "Automatic" or i_manualHTFs >= 2
  1008. processTf(FVG_TF2, t2h2, t2l2, t2h0, t2l0, t2t, t2t2)
  1009. if i_htfMode == "Manual" and i_manualHTFs >= 3
  1010. processTf(FVG_TF3, t3h2, t3l2, t3h0, t3l0, t3t, t3t2)
  1011.  
  1012. var int lastHtfDeliverLong = -10000
  1013. var int lastHtfDeliverShort = -10000
  1014.  
  1015. if array.size(fvgs) > 0
  1016. for i = array.size(fvgs) - 1 to 0
  1017. Fvg f = array.get(fvgs, i)
  1018. if not f.mitigated
  1019. if not na(f.bx)
  1020. box.set_right(f.bx, bar_index + 2)
  1021. if not na(f.lb)
  1022. label.set_x(f.lb, bar_index + 2)
  1023. if low <= f.top and high >= f.bot
  1024. if f.bull
  1025. lastHtfDeliverLong := bar_index
  1026. else
  1027. lastHtfDeliverShort := bar_index
  1028. bool mitigated = f.bull ? close < f.bot : close > f.top
  1029. if mitigated and i_fvgMitigate
  1030. f.mitigated := true
  1031. if not na(f.bx)
  1032. box.delete(f.bx)
  1033. f.bx := na
  1034. if not na(f.lb)
  1035. label.delete(f.lb)
  1036. f.lb := na
  1037. array.remove(fvgs, i)
  1038.  
  1039. var float lastPlPx = na
  1040. var int lastPlBar = na
  1041. var float lastCmpPlPx = na
  1042. var float lastPhPx = na
  1043. var int lastPhBar = na
  1044. var float lastCmpPhPx = na
  1045. var int lastBullSmtBar = -10000
  1046. var int lastBearSmtBar = -10000
  1047.  
  1048. pruneSmt() =>
  1049. while array.size(smts) > i_smtMax
  1050. Smt s = array.shift(smts)
  1051. if not na(s.ln)
  1052. line.delete(s.ln)
  1053. if not na(s.lb)
  1054. label.delete(s.lb)
  1055.  
  1056. drawSmt(bool bull, int b1, float p1, int b2, float p2) =>
  1057. Smt s = Smt.new(b1, b2, p1, p2, bull, na, na)
  1058. if i_showSMT
  1059. color col = bull ? i_smtBullCol : i_smtBearCol
  1060. s.ln := line.new(b1, p1, b2, p2, xloc = xloc.bar_index, color = col, style = lineStyle(bull ? i_smtBullStyle : i_smtBearStyle), width = widthOf(bull ? i_smtBullWidth : i_smtBearWidth))
  1061. if i_smtLabel
  1062. s.lb := label.new(int(math.avg(b1, b2)), bull ? math.min(p1, p2) : math.max(p1, p2), "SMT" + (i_smtSymbol ? " w/ " + SMT_SHORT : ""), xloc = xloc.bar_index, style = bull ? label.style_label_up : label.style_label_down, color = color.new(color.white, 100), textcolor = i_smtLblCol, size = txtSize(i_smtLblSize))
  1063. array.push(smts, s)
  1064. pruneSmt()
  1065.  
  1066. if i_showSMT or i_cisdFromSMT
  1067. if not na(smtPl)
  1068. int thisBar = bar_index - smtLen
  1069. float thisPx = smtPl
  1070. float cmpPx = cmpLow[smtLen]
  1071. if not na(lastPlPx) and not na(lastCmpPlPx)
  1072. bool divA = thisPx > lastPlPx and cmpPx < lastCmpPlPx
  1073. bool divB = thisPx < lastPlPx and cmpPx > lastCmpPlPx
  1074. if divA or divB
  1075. lastBullSmtBar := thisBar
  1076. drawSmt(true, lastPlBar, lastPlPx, thisBar, thisPx)
  1077. lastPlPx := thisPx
  1078. lastPlBar := thisBar
  1079. lastCmpPlPx := cmpPx
  1080.  
  1081. if not na(smtPh)
  1082. int thisBar = bar_index - smtLen
  1083. float thisPx = smtPh
  1084. float cmpPx = cmpHigh[smtLen]
  1085. if not na(lastPhPx) and not na(lastCmpPhPx)
  1086. bool divA = thisPx < lastPhPx and cmpPx > lastCmpPhPx
  1087. bool divB = thisPx > lastPhPx and cmpPx < lastCmpPhPx
  1088. if divA or divB
  1089. lastBearSmtBar := thisBar
  1090. drawSmt(false, lastPhBar, lastPhPx, thisBar, thisPx)
  1091. lastPhPx := thisPx
  1092. lastPhBar := thisBar
  1093. lastCmpPhPx := cmpPx
  1094.  
  1095. var line rtSmtLine = na
  1096. if i_smtRealtime and i_showSMT and barstate.islast
  1097. bool rtBull = low < low[1] and cmpLow > cmpLow[1]
  1098. bool rtBear = high > high[1] and cmpHigh < cmpHigh[1]
  1099. if not na(rtSmtLine)
  1100. line.delete(rtSmtLine)
  1101. rtSmtLine := na
  1102. if rtBull
  1103. rtSmtLine := line.new(bar_index - 1, low[1], bar_index, low, xloc = xloc.bar_index, color = i_smtBullCol, style = line.style_dotted, width = 1)
  1104. else if rtBear
  1105. rtSmtLine := line.new(bar_index - 1, high[1], bar_index, high, xloc = xloc.bar_index, color = i_smtBearCol, style = line.style_dotted, width = 1)
  1106.  
  1107. bool smtRecentBull = bar_index - lastBullSmtBar <= (i_smtLookback + smtLen)
  1108. bool smtRecentBear = bar_index - lastBearSmtBar <= (i_smtLookback + smtLen)
  1109.  
  1110. cm_legExtremeCurrent(int bias) =>
  1111. int temp_shift = 0
  1112. float extreme = open[0]
  1113. int ct0 = close[0] > open[0] ? 1 : close[0] < open[0] ? -1 : 0
  1114. if ct0 != 0 and ct0 == bias
  1115. for i = 1 to 500
  1116. int ctype = close[i] > open[i] ? 1 : close[i] < open[i] ? -1 : 0
  1117. if ctype == 0
  1118. continue
  1119. if ctype != bias
  1120. break
  1121. temp_shift := i
  1122. if bias == 1
  1123. if open[i] < extreme
  1124. extreme := open[i]
  1125. else
  1126. if open[i] > extreme
  1127. extreme := open[i]
  1128. int extreme_shift = 0
  1129. for k = 0 to temp_shift
  1130. if open[k] == extreme
  1131. extreme_shift := k
  1132. break
  1133. [extreme, bar_index - extreme_shift]
  1134.  
  1135. cm_legExtremePrevious(int bias) =>
  1136. bool found = false
  1137. int max_shift = 1
  1138. float extreme = na
  1139. for j = 1 to 500
  1140. int ctype = close[j] > open[j] ? 1 : close[j] < open[j] ? -1 : 0
  1141. if ctype == 0
  1142. continue
  1143. bool matches = ctype == bias
  1144. if not found
  1145. if matches
  1146. found := true
  1147. max_shift := j
  1148. extreme := open[j]
  1149. else
  1150. if not matches
  1151. break
  1152. max_shift := j
  1153. if bias == 1
  1154. if open[j] < extreme
  1155. extreme := open[j]
  1156. else
  1157. if open[j] > extreme
  1158. extreme := open[j]
  1159. int extreme_shift = max_shift
  1160. for k = 1 to max_shift
  1161. if open[k] == extreme
  1162. extreme_shift := k
  1163. break
  1164. [extreme, bar_index - extreme_shift]
  1165.  
  1166. var int cm_bias = 0
  1167. var float cm_level = na
  1168. var int cm_levelBar = na
  1169. var float cm_pivot = na
  1170. var int cm_pivotBar = na
  1171.  
  1172. bool cm_firedBull = false
  1173. bool cm_firedBear = false
  1174.  
  1175. if cm_bias == 0 and bar_index > 10
  1176. int seedType = close > open ? 1 : close < open ? -1 : 0
  1177. if seedType == 0
  1178. for k = 1 to 50
  1179. seedType := close[k] > open[k] ? 1 : close[k] < open[k] ? -1 : 0
  1180. if seedType != 0
  1181. break
  1182. if seedType != 0
  1183. cm_bias := seedType
  1184. [oPrice, oBar] = cm_legExtremeCurrent(seedType)
  1185. cm_level := oPrice
  1186. cm_levelBar := oBar
  1187. cm_pivot := seedType == 1 ? high : low
  1188. cm_pivotBar := bar_index
  1189.  
  1190. int cm_cType = close > open ? 1 : close < open ? -1 : 0
  1191.  
  1192. if cm_bias == 1 and high > cm_pivot
  1193. cm_pivot := high
  1194. cm_pivotBar := bar_index
  1195. float p = na
  1196. int pb = na
  1197. if cm_cType == 1
  1198. [pp, ppb] = cm_legExtremeCurrent(1)
  1199. p := pp
  1200. pb := ppb
  1201. else
  1202. [pp, ppb] = cm_legExtremePrevious(1)
  1203. p := pp
  1204. pb := ppb
  1205. cm_level := p
  1206. cm_levelBar := pb
  1207. else if cm_bias == -1 and low < cm_pivot
  1208. cm_pivot := low
  1209. cm_pivotBar := bar_index
  1210. float p2 = na
  1211. int pb2 = na
  1212. if cm_cType == -1
  1213. [pp, ppb] = cm_legExtremeCurrent(-1)
  1214. p2 := pp
  1215. pb2 := ppb
  1216. else
  1217. [pp, ppb] = cm_legExtremePrevious(-1)
  1218. p2 := pp
  1219. pb2 := ppb
  1220. cm_level := p2
  1221. cm_levelBar := pb2
  1222.  
  1223. bool cm_bullFlip = cm_bias == -1 and close > cm_level
  1224. bool cm_bearFlip = cm_bias == 1 and close < cm_level
  1225.  
  1226. float pendBullLevel = na
  1227. float pendBullExt = na
  1228. float pendBullBodyExt = na
  1229. int pendBullExtB = na
  1230. int pendBullBodyExtB = na
  1231. int pendBullStart = na
  1232. int pendBullEnd = na
  1233.  
  1234. float pendBearLevel = na
  1235. float pendBearExt = na
  1236. float pendBearBodyExt = na
  1237. int pendBearExtB = na
  1238. int pendBearBodyExtB = na
  1239. int pendBearStart = na
  1240. int pendBearEnd = na
  1241.  
  1242. if cm_bullFlip
  1243. pendBullLevel := cm_level
  1244. pendBullExt := cm_pivot
  1245. pendBullBodyExt := cm_pivot
  1246. pendBullExtB := cm_pivotBar
  1247. pendBullBodyExtB := cm_pivotBar
  1248. pendBullStart := cm_levelBar
  1249. pendBullEnd := bar_index
  1250. cm_firedBull := true
  1251.  
  1252. if cm_bearFlip
  1253. pendBearLevel := cm_level
  1254. pendBearExt := cm_pivot
  1255. pendBearBodyExt := cm_pivot
  1256. pendBearExtB := cm_pivotBar
  1257. pendBearBodyExtB := cm_pivotBar
  1258. pendBearStart := cm_levelBar
  1259. pendBearEnd := bar_index
  1260. cm_firedBear := true
  1261.  
  1262. if cm_bullFlip or cm_bearFlip
  1263. int newBias = cm_bullFlip ? 1 : -1
  1264. cm_bias := newBias
  1265. [np, npb] = cm_legExtremeCurrent(newBias)
  1266. cm_level := np
  1267. cm_levelBar := npb
  1268. cm_pivot := newBias == 1 ? high : low
  1269. cm_pivotBar := bar_index
  1270.  
  1271. int GATE_WINDOW = math.max(i_maxConfirmBars, 12)
  1272.  
  1273. validLongOrigin() =>
  1274. bool swept = (i_ctfSweeps and bar_index - lastSweepSellBar <= GATE_WINDOW) or (bar_index - htfSweepSellBar <= GATE_WINDOW)
  1275. bool fvg = i_ctfFvgDeliver and bar_index - lastCtfFvgDeliverLong <= GATE_WINDOW
  1276. bool smt = i_cisdFromSMT and smtRecentBull
  1277. [swept or fvg, swept, fvg, smt]
  1278.  
  1279. validShortOrigin() =>
  1280. bool swept = (i_ctfSweeps and bar_index - lastSweepBuyBar <= GATE_WINDOW) or (bar_index - htfSweepBuyBar <= GATE_WINDOW)
  1281. bool fvg = i_ctfFvgDeliver and bar_index - lastCtfFvgDeliverShort <= GATE_WINDOW
  1282. bool smt = i_cisdFromSMT and smtRecentBear
  1283. [swept or fvg, swept, fvg, smt]
  1284.  
  1285. proximityBlocked(array<Cisd> arr, float level) =>
  1286. bool blocked = false
  1287. if i_ignoreProx and array.size(arr) > 0 and not na(atr)
  1288. for i = 0 to array.size(arr) - 1
  1289. Cisd c = array.get(arr, i)
  1290. if not c.invalidated and math.abs(c.level - level) < atr * i_proxATR
  1291. blocked := true
  1292. break
  1293. blocked
  1294.  
  1295. gradeSetup(bool bull, bool sweptLiq, bool pda, bool volOk, bool sessSweep, bool targets, bool smt) =>
  1296. int enabled = 0
  1297. int hits = 0
  1298. if i_ckSweep
  1299. enabled += 1
  1300. hits += sweptLiq ? 1 : 0
  1301. if i_ckPDA
  1302. enabled += 1
  1303. hits += pda ? 1 : 0
  1304. if i_ckVolume
  1305. enabled += 1
  1306. hits += volOk ? 1 : 0
  1307. if i_ckSession
  1308. enabled += 1
  1309. hits += sessSweep ? 1 : 0
  1310. if i_ckTargets
  1311. enabled += 1
  1312. hits += targets ? 1 : 0
  1313. if i_ckSMT
  1314. enabled += 1
  1315. hits += smt ? 1 : 0
  1316. float ratio = enabled == 0 ? 0.0 : hits / enabled
  1317. int g = ratio >= 0.95 ? 7 : ratio >= 0.80 ? 6 : ratio >= 0.65 ? 5 : ratio >= 0.45 ? 4 : ratio >= 0.25 ? 3 : 0
  1318. g
  1319.  
  1320. contractsFor(float entry, float sl) =>
  1321. float dist = math.abs(entry - sl)
  1322. float pv = syminfo.pointvalue
  1323. int n = 0
  1324. if dist > 0 and pv > 0
  1325. n := int(math.floor(i_riskUSD / (dist * pv)))
  1326. math.max(n, 0)
  1327.  
  1328. riskFor(float entry, float sl, int qty) =>
  1329. math.abs(entry - sl) * syminfo.pointvalue * qty
  1330.  
  1331. deleteCisd(Cisd c) =>
  1332. if not na(c.ln)
  1333. line.delete(c.ln)
  1334. c.ln := na
  1335. if not na(c.lb)
  1336. label.delete(c.lb)
  1337. c.lb := na
  1338. if not na(c.slLn)
  1339. line.delete(c.slLn)
  1340. c.slLn := na
  1341. if not na(c.slLb)
  1342. label.delete(c.slLb)
  1343. c.slLb := na
  1344.  
  1345. pruneCisd(array<Cisd> arr) =>
  1346. while array.size(arr) > i_setupsShown
  1347. Cisd c = array.shift(arr)
  1348. deleteCisd(c)
  1349.  
  1350. buildTooltip(Cisd c) =>
  1351. string t = (c.bull ? "BULLISH" : "BEARISH") + " CISD ยท " + tfLabel(c.tf) + "\n"
  1352. t += "Grade: " + gradeText(c.grade) + "\n"
  1353. t += "Entry: " + str.tostring(c.level, format.mintick) + "\n"
  1354. t += "Stop : " + str.tostring(c.slPrice, format.mintick) + "\n"
  1355. t += "Dist : " + str.tostring(math.abs(c.level - c.slPrice), format.mintick) + "\n"
  1356. if i_sizingOn
  1357. t += "Size : " + str.tostring(c.contracts) + " contracts (~$" + str.tostring(math.round(riskFor(c.level, c.slPrice, c.contracts))) + ")\n"
  1358. if not na(c.target)
  1359. float rr = math.abs(c.target - c.level) / math.max(math.abs(c.level - c.slPrice), syminfo.mintick)
  1360. t += "Target: " + str.tostring(c.target, format.mintick) + " (" + str.tostring(rr, "#.##") + "R)\n"
  1361. t += "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n"
  1362. t += (c.ckSweep ? "โœ…" : "โŒ") + " Liquidity Sweep\n"
  1363. t += (c.ckPDA ? "โœ…" : "โŒ") + " HTF PDA Delivery\n"
  1364. t += (c.ckVol ? "โœ…" : "โŒ") + " Volume\n"
  1365. t += (c.ckSession ? "โœ…" : "โŒ") + " Session Sweep\n"
  1366. t += (c.ckTargets ? "โœ…" : "โŒ") + " Clear Targets\n"
  1367. t += (c.ckSMT ? "โœ…" : "โŒ") + " SMT"
  1368. t
  1369.  
  1370. renderCisd(Cisd c) =>
  1371. color col = c.bull ? i_longCol : i_shortCol
  1372. bool isCtf = c.tf == timeframe.period
  1373. string lbTxt = tfLabel(c.tf) + " CISD" + (c.bull ? "+" : "-")
  1374. if c.potential
  1375. lbTxt := "Potential " + lbTxt
  1376. if na(c.ln)
  1377. c.ln := line.new(c.startBar, c.level, bar_index + 3, c.level, xloc = xloc.bar_index, color = col, style = c.potential ? line.style_dashed : line.style_solid, width = i_cisdWidth)
  1378. else
  1379. line.set_xy1(c.ln, c.startBar, c.level)
  1380. line.set_xy2(c.ln, math.min(bar_index + 3, c.startBar + i_cisdExtend), c.level)
  1381. line.set_style(c.ln, c.potential ? line.style_dashed : line.style_solid)
  1382. line.set_color(c.ln, col)
  1383.  
  1384. bool wantLabel = not (isCtf and i_disableCtfLbl and not c.potential)
  1385. if wantLabel
  1386. if na(c.lb)
  1387. c.lb := label.new(line.get_x2(c.ln), c.level, lbTxt, xloc = xloc.bar_index, style = label.style_label_left, color = color.new(color.white, 100), textcolor = col, size = txtSize(i_cisdLblSize), tooltip = buildTooltip(c))
  1388. else
  1389. label.set_xy(c.lb, line.get_x2(c.ln), c.level)
  1390. label.set_text(c.lb, lbTxt + (i_sizingOn and not i_hoverOnly ? " " + str.tostring(c.contracts) + "c" : ""))
  1391. label.set_tooltip(c.lb, buildTooltip(c))
  1392. else if not na(c.lb)
  1393. label.delete(c.lb)
  1394. c.lb := na
  1395.  
  1396. int slEndBar = c.slBar + i_slExtendBars
  1397. if i_showSL and not na(c.slPrice) and isCtf
  1398. if na(c.slLn)
  1399. c.slLn := line.new(c.slBar, c.slPrice, slEndBar, c.slPrice, xloc = xloc.bar_index, color = i_slCol, style = lineStyle(i_slStyle), width = 1)
  1400. c.slLb := label.new(slEndBar, c.slPrice, "SL", xloc = xloc.bar_index, style = label.style_label_left, color = color.new(color.white, 100), textcolor = i_slCol, size = txtSize(i_cisdLblSize))
  1401. else
  1402. line.set_xy1(c.slLn, c.slBar, c.slPrice)
  1403. line.set_xy2(c.slLn, slEndBar, c.slPrice)
  1404. label.set_xy(c.slLb, slEndBar, c.slPrice)
  1405. else
  1406. if not na(c.slLn)
  1407. line.delete(c.slLn)
  1408. c.slLn := na
  1409. if not na(c.slLb)
  1410. label.delete(c.slLb)
  1411. c.slLb := na
  1412.  
  1413. c
  1414.  
  1415. makeCisd(bool bull, float level, float ext, float bodyExt, int startB, int endB, int slB, bool potential, string tf, bool sweptLiq, bool pda, bool volOk, bool sessSweep, bool smt) =>
  1416. float sl = i_slPlacement == "Wick" ? ext : bodyExt
  1417. int actualSlBar = na(slB) ? startB : slB
  1418. float tgt = bull ? nearestTargetAbove() : nearestTargetBelow()
  1419. float dist = math.abs(level - sl)
  1420. bool clearTargets = not na(tgt) and dist > 0 and (math.abs(tgt - level) / dist) >= i_minRR
  1421. int g = gradeSetup(bull, sweptLiq, pda, volOk, sessSweep, clearTargets, smt)
  1422. Cisd c = Cisd.new(level, ext, bodyExt, startB, endB, actualSlBar, potential ? na : bar_index, bull, not potential, false, potential, tf, g, sweptLiq, pda, volOk, sessSweep, clearTargets, smt, tgt, 0, sl, na, na, na, na)
  1423. c.contracts := i_sizingOn ? contractsFor(level, sl) : 0
  1424. c
  1425.  
  1426. qualifies(Cisd c) =>
  1427. bool dirOk = c.bull ? biasAllowsLong : biasAllowsShort
  1428. bool gradeOk = c.grade >= gradeRank(i_minGrade)
  1429. dirOk and gradeOk
  1430.  
  1431. var int bullFiredBar = -10000
  1432. var bool newBullCisd = false
  1433. var bool newBearCisd = false
  1434. newBullCisd := false
  1435. newBearCisd := false
  1436.  
  1437. if i_showCISD and cm_firedBull and biasAllowsLong
  1438. [ok, swept, fvg, smt] = validLongOrigin()
  1439. if ok and not proximityBlocked(cisdBull, pendBullLevel)
  1440. bool pda = bar_index - lastHtfDeliverLong <= GATE_WINDOW
  1441. bool sess = bar_index - lastSessSweepBar <= GATE_WINDOW and not lastSessSweepWasHigh
  1442. Cisd c = makeCisd(true, pendBullLevel, pendBullExt, pendBullBodyExt, pendBullStart, pendBullEnd, pendBullExtB, false, timeframe.period, swept, pda, volSpike, sess, smt)
  1443. if qualifies(c)
  1444. array.push(cisdBull, c)
  1445. pruneCisd(cisdBull)
  1446. newBullCisd := true
  1447. bullFiredBar := bar_index
  1448. lastGradeVal := c.grade
  1449. lastGradeIsBull := true
  1450.  
  1451. if i_showCISD and cm_firedBear and biasAllowsShort
  1452. [ok, swept, fvg, smt] = validShortOrigin()
  1453. if ok and not proximityBlocked(cisdBear, pendBearLevel)
  1454. bool pda = bar_index - lastHtfDeliverShort <= GATE_WINDOW
  1455. bool sess = bar_index - lastSessSweepBar <= GATE_WINDOW and lastSessSweepWasHigh
  1456. Cisd c = makeCisd(false, pendBearLevel, pendBearExt, pendBearBodyExt, pendBearStart, pendBearEnd, pendBearExtB, false, timeframe.period, swept, pda, volSpike, sess, smt)
  1457. if qualifies(c)
  1458. array.push(cisdBear, c)
  1459. pruneCisd(cisdBear)
  1460. newBearCisd := true
  1461. lastGradeVal := c.grade
  1462. lastGradeIsBull := false
  1463.  
  1464. var line potBullLn = na
  1465. var label potBullLb = na
  1466. var line potBearLn = na
  1467. var label potBearLb = na
  1468.  
  1469. var int lastPotBullBar = -10000
  1470. var int lastPotBearBar = -10000
  1471. var bool newPotBull = false
  1472. var bool newPotBear = false
  1473. newPotBull := false
  1474. newPotBear := false
  1475.  
  1476. if barstate.islast
  1477. if not na(potBullLn)
  1478. line.delete(potBullLn)
  1479. potBullLn := na
  1480. if not na(potBullLb)
  1481. label.delete(potBullLb)
  1482. potBullLb := na
  1483. if not na(potBearLn)
  1484. line.delete(potBearLn)
  1485. potBearLn := na
  1486. if not na(potBearLb)
  1487. label.delete(potBearLb)
  1488. potBearLb := na
  1489.  
  1490. if i_showCISD and i_showPotential
  1491. if cm_bias == -1 and biasAllowsLong and close < cm_level
  1492. [ok, swept, fvg, smt] = validLongOrigin()
  1493. if ok
  1494. float sl = cm_pivot
  1495. int qty = i_sizingOn ? contractsFor(cm_level, sl) : 0
  1496. potBullLn := line.new(cm_levelBar, cm_level, bar_index + 5, cm_level, xloc = xloc.bar_index, color = color.new(i_longCol, 25), style = line.style_dashed, width = i_cisdWidth)
  1497. string t = "Potential " + tfLabel(timeframe.period) + " CISD+\nClose above " + str.tostring(cm_level, format.mintick) + " to confirm\nSL " + str.tostring(sl, format.mintick) + (i_sizingOn ? "\nSize " + str.tostring(qty) + " contracts" : "")
  1498. potBullLb := label.new(bar_index + 5, cm_level, "Potential " + tfLabel(timeframe.period) + " CISD+" + (i_sizingOn and not i_hoverOnly ? " " + str.tostring(qty) + "c" : ""), xloc = xloc.bar_index, style = label.style_label_left, color = color.new(color.white, 100), textcolor = i_longCol, size = txtSize(i_cisdLblSize), tooltip = t)
  1499. if lastPotBullBar != cm_levelBar
  1500. newPotBull := true
  1501. lastPotBullBar := cm_levelBar
  1502. if cm_bias == 1 and biasAllowsShort and close > cm_level
  1503. [ok, swept, fvg, smt] = validShortOrigin()
  1504. if ok
  1505. float sl = cm_pivot
  1506. int qty = i_sizingOn ? contractsFor(cm_level, sl) : 0
  1507. potBearLn := line.new(cm_levelBar, cm_level, bar_index + 5, cm_level, xloc = xloc.bar_index, color = color.new(i_shortCol, 25), style = line.style_dashed, width = i_cisdWidth)
  1508. string t = "Potential " + tfLabel(timeframe.period) + " CISD-\nClose below " + str.tostring(cm_level, format.mintick) + " to confirm\nSL " + str.tostring(sl, format.mintick) + (i_sizingOn ? "\nSize " + str.tostring(qty) + " contracts" : "")
  1509. potBearLb := label.new(bar_index + 5, cm_level, "Potential " + tfLabel(timeframe.period) + " CISD-" + (i_sizingOn and not i_hoverOnly ? " " + str.tostring(qty) + "c" : ""), xloc = xloc.bar_index, style = label.style_label_left, color = color.new(color.white, 100), textcolor = i_shortCol, size = txtSize(i_cisdLblSize), tooltip = t)
  1510. if lastPotBearBar != cm_levelBar
  1511. newPotBear := true
  1512. lastPotBearBar := cm_levelBar
  1513.  
  1514. maintain(array<Cisd> arr) =>
  1515. if array.size(arr) > 0
  1516. for i = array.size(arr) - 1 to 0
  1517. Cisd c = array.get(arr, i)
  1518. bool killed = c.bull ? close < c.slPrice : close > c.slPrice
  1519. if killed and not c.invalidated
  1520. c.invalidated := true
  1521. if i_hideInvalid
  1522. deleteCisd(c)
  1523. array.remove(arr, i)
  1524. continue
  1525. else
  1526. if not na(c.ln)
  1527. line.set_color(c.ln, color.new(color.gray, 55))
  1528. line.set_style(c.ln, line.style_dotted)
  1529. if not c.invalidated
  1530. renderCisd(c)
  1531.  
  1532. maintain(cisdBull)
  1533. maintain(cisdBear)
  1534.  
  1535. htfCisdCalc() =>
  1536. bool dn = close < open
  1537. bool up = close > open
  1538. var int dStart = na
  1539. var float dOpen = na
  1540. var float dLow = na
  1541. var float dBody = na
  1542. var float dStartT = na
  1543. var int uStart = na
  1544. var float uOpen = na
  1545. var float uHigh = na
  1546. var float uBody = na
  1547. var float uStartT = na
  1548.  
  1549. if dn
  1550. if not dn[1]
  1551. dStart := bar_index
  1552. dOpen := open
  1553. dLow := low
  1554. dBody := close
  1555. dStartT := time
  1556. else
  1557. dLow := math.min(nz(dLow, low), low)
  1558. dBody := math.min(nz(dBody, close), close)
  1559. if up
  1560. if not up[1]
  1561. uStart := bar_index
  1562. uOpen := open
  1563. uHigh := high
  1564. uBody := close
  1565. uStartT := time
  1566. else
  1567. uHigh := math.max(nz(uHigh, high), high)
  1568. uBody := math.max(nz(uBody, close), close)
  1569.  
  1570. var float pBullLvl = na
  1571. var float pBullExt = na
  1572. var float pBullBody = na
  1573. var float pBullTime = na
  1574. var float pBearLvl = na
  1575. var float pBearExt = na
  1576. var float pBearBody = na
  1577. var float pBearTime = na
  1578.  
  1579. if dn[1] and not dn
  1580. pBullLvl := dOpen[1]
  1581. pBullExt := dLow[1]
  1582. pBullBody := dBody[1]
  1583. pBullTime := dStartT[1]
  1584. if up[1] and not up
  1585. pBearLvl := uOpen[1]
  1586. pBearExt := uHigh[1]
  1587. pBearBody := uBody[1]
  1588. pBearTime := uStartT[1]
  1589.  
  1590. float confBull = na
  1591. float confBullExt = na
  1592. float confBullBody = na
  1593. float confBear = na
  1594. float confBearExt = na
  1595. float confBearBody = na
  1596.  
  1597. if not na(pBullLvl) and close > pBullLvl and close[1] <= pBullLvl
  1598. confBull := pBullLvl
  1599. confBullExt := pBullExt
  1600. confBullBody := pBullBody
  1601. if not na(pBearLvl) and close < pBearLvl and close[1] >= pBearLvl
  1602. confBear := pBearLvl
  1603. confBearExt := pBearExt
  1604. confBearBody := pBearBody
  1605.  
  1606. [confBull, confBullExt, confBullBody, confBear, confBearExt, confBearBody, pBullLvl, pBearLvl, pBullTime, pBearTime, time]
  1607.  
  1608. [h1cb, h1cbe, h1cbb, h1cs, h1cse, h1csb, h1pb, h1ps, h1pbt, h1pst, h1t] = request.security(syminfo.tickerid, HC_TF1, htfCisdCalc(), barmerge.gaps_off, barmerge.lookahead_off)
  1609. [h2cb, h2cbe, h2cbb, h2cs, h2cse, h2csb, h2pb, h2ps, h2pbt, h2pst, h2t] = request.security(syminfo.tickerid, HC_TF2, htfCisdCalc(), barmerge.gaps_off, barmerge.lookahead_off)
  1610.  
  1611. var bool newHtfCisd = false
  1612. newHtfCisd := false
  1613.  
  1614. htfStartBar(float t) =>
  1615. int result = bar_index
  1616. if not na(t)
  1617. float tfMs = timeframe.in_seconds(timeframe.period) * 1000.0
  1618. int barsAgo = tfMs > 0 ? int(math.round((time - t) / tfMs)) : 0
  1619. result := math.max(bar_index - barsAgo, 0)
  1620. result
  1621.  
  1622. pushHtfCisd(bool bull, float lvl, float ext, float bodyExt, float startTime, string tf) =>
  1623. bool added = false
  1624. if not na(lvl)
  1625. bool dup = false
  1626. if array.size(cisdHtf) > 0
  1627. for i = 0 to array.size(cisdHtf) - 1
  1628. Cisd c = array.get(cisdHtf, i)
  1629. if c.tf == tf and c.bull == bull and math.abs(c.level - lvl) < syminfo.mintick
  1630. dup := true
  1631. break
  1632. if not dup
  1633. bool swept = bull ? (bar_index - lastSweepSellBar <= GATE_WINDOW or bar_index - htfSweepSellBar <= GATE_WINDOW) : (bar_index - lastSweepBuyBar <= GATE_WINDOW or bar_index - htfSweepBuyBar <= GATE_WINDOW)
  1634. bool pda = bull ? bar_index - lastHtfDeliverLong <= GATE_WINDOW : bar_index - lastHtfDeliverShort <= GATE_WINDOW
  1635. bool sess = bar_index - lastSessSweepBar <= GATE_WINDOW and (bull ? not lastSessSweepWasHigh : lastSessSweepWasHigh)
  1636. bool smt = bull ? smtRecentBull : smtRecentBear
  1637. int startB = htfStartBar(startTime)
  1638. Cisd c = makeCisd(bull, lvl, ext, bodyExt, startB, bar_index, startB, false, tf, swept, pda, volSpike, sess, smt)
  1639. if qualifies(c)
  1640. array.push(cisdHtf, c)
  1641. added := true
  1642. while array.size(cisdHtf) > i_setupsShown * 2
  1643. Cisd o = array.shift(cisdHtf)
  1644. deleteCisd(o)
  1645. added
  1646.  
  1647. if i_showHtfCISD
  1648. if ta.change(h1t) != 0 or barstate.islast
  1649. if pushHtfCisd(true, h1cb, h1cbe, h1cbb, h1pbt, HC_TF1)
  1650. newHtfCisd := true
  1651. if pushHtfCisd(false, h1cs, h1cse, h1csb, h1pst, HC_TF1)
  1652. newHtfCisd := true
  1653. if ta.change(h2t) != 0 or barstate.islast
  1654. if pushHtfCisd(true, h2cb, h2cbe, h2cbb, h2pbt, HC_TF2)
  1655. newHtfCisd := true
  1656. if pushHtfCisd(false, h2cs, h2cse, h2csb, h2pst, HC_TF2)
  1657. newHtfCisd := true
  1658. maintain(cisdHtf)
  1659.  
  1660. mergeCtfWithHtf(array<Cisd> ctfArr) =>
  1661. if array.size(ctfArr) > 0 and array.size(cisdHtf) > 0
  1662. for i = 0 to array.size(ctfArr) - 1
  1663. Cisd c = array.get(ctfArr, i)
  1664. if not c.invalidated and not na(c.lb)
  1665. string tfs = tfLabel(c.tf)
  1666. float tol = atr * i_mergeTolATR
  1667. bool merged = false
  1668. for j = 0 to array.size(cisdHtf) - 1
  1669. Cisd h = array.get(cisdHtf, j)
  1670. if h.bull == c.bull and not h.invalidated and math.abs(h.level - c.level) <= tol
  1671. tfs := tfs + "+" + tfLabel(h.tf)
  1672. merged := true
  1673. if not na(h.lb)
  1674. label.delete(h.lb)
  1675. h.lb := na
  1676. if not na(h.ln)
  1677. line.delete(h.ln)
  1678. h.ln := na
  1679. if merged
  1680. string suffix = c.bull ? "+" : "-"
  1681. label.set_text(c.lb, tfs + " CISD" + suffix + (i_sizingOn and not i_hoverOnly ? " " + str.tostring(c.contracts) + "c" : ""))
  1682.  
  1683. if i_showHtfCISD
  1684. mergeCtfWithHtf(cisdBull)
  1685. mergeCtfWithHtf(cisdBear)
  1686.  
  1687. var line hpb1 = na
  1688. var line hps1 = na
  1689. var line hpb2 = na
  1690. var line hps2 = na
  1691. if i_showHtfCISD and i_htfPotential and barstate.islast
  1692. if not na(hpb1)
  1693. line.delete(hpb1)
  1694. hpb1 := na
  1695. if not na(hps1)
  1696. line.delete(hps1)
  1697. hps1 := na
  1698. if not na(hpb2)
  1699. line.delete(hpb2)
  1700. hpb2 := na
  1701. if not na(hps2)
  1702. line.delete(hps2)
  1703. hps2 := na
  1704. if not na(h1pb) and close < h1pb
  1705. hpb1 := line.new(bar_index - 20, h1pb, bar_index + 5, h1pb, xloc = xloc.bar_index, color = color.new(i_longCol, 45), style = lineStyle(i_htfCisdStyle))
  1706. if not na(h1ps) and close > h1ps
  1707. hps1 := line.new(bar_index - 20, h1ps, bar_index + 5, h1ps, xloc = xloc.bar_index, color = color.new(i_shortCol, 45), style = lineStyle(i_htfCisdStyle))
  1708. if not na(h2pb) and close < h2pb
  1709. hpb2 := line.new(bar_index - 20, h2pb, bar_index + 5, h2pb, xloc = xloc.bar_index, color = color.new(i_longCol, 60), style = lineStyle(i_htfCisdStyle))
  1710. if not na(h2ps) and close > h2ps
  1711. hps2 := line.new(bar_index - 20, h2ps, bar_index + 5, h2ps, xloc = xloc.bar_index, color = color.new(i_shortCol, 60), style = lineStyle(i_htfCisdStyle))
  1712.  
  1713. var line tgtLn = na
  1714. var label tgtLb = na
  1715.  
  1716. if i_showTarget and barstate.islast
  1717. if not na(tgtLn)
  1718. line.delete(tgtLn)
  1719. tgtLn := na
  1720. if not na(tgtLb)
  1721. label.delete(tgtLb)
  1722. tgtLb := na
  1723. Cisd ref = na
  1724. if array.size(cisdBull) > 0 and array.size(cisdBear) > 0
  1725. Cisd b = array.get(cisdBull, array.size(cisdBull) - 1)
  1726. Cisd s = array.get(cisdBear, array.size(cisdBear) - 1)
  1727. ref := b.endBar >= s.endBar ? b : s
  1728. else if array.size(cisdBull) > 0
  1729. ref := array.get(cisdBull, array.size(cisdBull) - 1)
  1730. else if array.size(cisdBear) > 0
  1731. ref := array.get(cisdBear, array.size(cisdBear) - 1)
  1732.  
  1733. if not na(ref) and not na(ref.target) and not ref.invalidated
  1734. int tgtEndBar = ref.endBar + i_tgtExtendBars
  1735. int tgtStartBar = math.max(ref.endBar, tgtEndBar - 2)
  1736. tgtLn := line.new(tgtStartBar, ref.target, tgtEndBar, ref.target, xloc = xloc.bar_index, color = color.new(ref.bull ? i_longCol : i_shortCol, 35), style = line.style_solid, width = 2)
  1737. float rr = math.abs(ref.target - ref.level) / math.max(math.abs(ref.level - ref.slPrice), syminfo.mintick)
  1738. tgtLb := label.new(tgtEndBar, ref.target, "TP " + str.tostring(rr, "#.##") + "R", xloc = xloc.bar_index, style = label.style_label_left, color = color.new(color.white, 100), textcolor = ref.bull ? i_longCol : i_shortCol, size = txtSize(i_cisdLblSize))
  1739.  
  1740. var table ck = table.new(tblPosOf(i_tblPos), 2, 10, border_width = 1, border_color = color.new(#26303E, 70))
  1741.  
  1742. activeRef() =>
  1743. Cisd r = na
  1744. if array.size(cisdBull) > 0 and array.size(cisdBear) > 0
  1745. Cisd b = array.get(cisdBull, array.size(cisdBull) - 1)
  1746. Cisd s = array.get(cisdBear, array.size(cisdBear) - 1)
  1747. r := b.endBar >= s.endBar ? b : s
  1748. else if array.size(cisdBull) > 0
  1749. r := array.get(cisdBull, array.size(cisdBull) - 1)
  1750. else if array.size(cisdBear) > 0
  1751. r := array.get(cisdBear, array.size(cisdBear) - 1)
  1752. r
  1753.  
  1754. mark(bool b) =>
  1755. b ? "โœ…" : "โŒ"
  1756.  
  1757. rowTint(bool ok) =>
  1758. i_ckTintRows ? (ok ? i_ckPassCol : i_ckFailCol) : i_cellCol
  1759.  
  1760. biasColor() =>
  1761. switch i_bias
  1762. "Bullish" => color.new(#089981, 0)
  1763. "Bearish" => color.new(#F23645, 0)
  1764. => color.new(#e0e3eb, 0)
  1765.  
  1766. checklistRow(int row, string label, bool ok) =>
  1767. table.cell(ck, 0, row, label, bgcolor = rowTint(ok), text_color = color.new(#b2b5be, 0), text_size = txtSize(i_tblSize), text_halign = text.align_center)
  1768. table.cell(ck, 1, row, mark(ok), bgcolor = rowTint(ok), text_size = txtSize(i_tblSize), text_halign = text.align_center)
  1769.  
  1770. if barstate.islast and i_showChecklist
  1771. table.clear(ck, 0, 0, 1, 9)
  1772. Cisd r = activeRef()
  1773. int row = 0
  1774.  
  1775. table.cell(ck, 0, row, "Bias", bgcolor = i_hdrBg, text_color = i_hdrTxt, text_size = txtSize(i_tblSize), text_halign = text.align_center)
  1776. table.cell(ck, 1, row, i_bias, bgcolor = i_hdrBg, text_color = biasColor(), text_size = txtSize(i_tblSize), text_halign = text.align_center)
  1777. row += 1
  1778.  
  1779. if i_showGrade
  1780. int g = na(r) ? 0 : r.grade
  1781. table.cell(ck, 0, row, "Setup Grade", bgcolor = i_hdrBg, text_color = i_hdrTxt, text_size = txtSize(i_tblSize), text_halign = text.align_center)
  1782. table.cell(ck, 1, row, gradeText(g), bgcolor = i_hdrBg, text_color = gradeColor(g), text_size = txtSize(i_tblSize), text_halign = text.align_center)
  1783. row += 1
  1784.  
  1785. table.cell(ck, 0, row, "Checklist", bgcolor = i_hdrBg, text_color = i_hdrTxt, text_size = txtSize(i_tblSize), text_halign = text.align_center)
  1786. table.cell(ck, 1, row, "Status", bgcolor = i_hdrBg, text_color = i_hdrTxt, text_size = txtSize(i_tblSize), text_halign = text.align_center)
  1787. row += 1
  1788.  
  1789. if i_ckSweep
  1790. checklistRow(row, "Liquidity Sweep", na(r) ? false : r.ckSweep)
  1791. row += 1
  1792. if i_ckPDA
  1793. checklistRow(row, "HTF PDA Delivery", na(r) ? false : r.ckPDA)
  1794. row += 1
  1795. if i_ckVolume
  1796. checklistRow(row, "Volume", na(r) ? false : r.ckVol)
  1797. row += 1
  1798. if i_ckSession
  1799. checklistRow(row, "Session Sweep", na(r) ? false : r.ckSession)
  1800. row += 1
  1801. if i_ckTargets
  1802. checklistRow(row, "Clear Targets", na(r) ? false : r.ckTargets)
  1803. row += 1
  1804. if i_ckSMT
  1805. checklistRow(row, "SMT", na(r) ? false : r.ckSMT)
  1806. row += 1
  1807.  
  1808. var table wm = table.new(tblPosOf(i_wmPos), 1, 4)
  1809.  
  1810. wmDateTxt() =>
  1811. string mm = str.tostring(month(time_close, TZ))
  1812. string dd = str.tostring(dayofmonth(time_close, TZ))
  1813. string yy = str.tostring(year(time_close, TZ))
  1814. dd + " " + mm + " " + yy
  1815.  
  1816. if barstate.islast and i_showInfoBox
  1817. table.clear(wm, 0, 0, 0, 3)
  1818. table.cell(wm, 0, 0, i_wmSite, text_color = i_wmTextCol, text_size = size.small)
  1819. table.cell(wm, 0, 1, i_wmLine1, text_color = i_wmTextCol, text_size = size.normal)
  1820. if i_wmShowDate
  1821. table.cell(wm, 0, 2, syminfo.ticker + " (" + tfLabel(timeframe.period) + ")", text_color = i_wmTextCol, text_size = size.small)
  1822. table.cell(wm, 0, 3, wmDateTxt(), text_color = i_wmTextCol, text_size = size.tiny)
  1823.  
  1824. inAlertWindow() =>
  1825. bool w1 = i_alertS1 and not na(time(timeframe.period, i_alertS1Win, TZ))
  1826. bool w2 = i_alertS2 and not na(time(timeframe.period, i_alertS2Win, TZ))
  1827. bool w3 = i_alertS3 and not na(time(timeframe.period, i_alertS3Win, TZ))
  1828. bool none = not i_alertS1 and not i_alertS2 and not i_alertS3
  1829. none or w1 or w2 or w3
  1830.  
  1831. string sideTxt = newBullCisd ? "BULLISH" : "BEARISH"
  1832. string gradeTxt = gradeText(lastGradeVal)
  1833.  
  1834. if i_alertsOn and inAlertWindow()
  1835. if i_alertConfirmed and (newBullCisd or newBearCisd)
  1836. alert(i_msgConfirmed + " | " + sideTxt + " | " + syminfo.ticker + " " + tfLabel(timeframe.period) + " | Grade " + gradeTxt + " | Level " + str.tostring(newBullCisd ? close : close, format.mintick), alert.freq_once_per_bar_close)
  1837. if i_alertPotential and (newPotBull or newPotBear)
  1838. alert(i_msgPotential + " | " + (newPotBull ? "BULLISH" : "BEARISH") + " | " + syminfo.ticker + " " + tfLabel(timeframe.period), alert.freq_once_per_bar)
  1839. if i_alertHTF and newHtfCisd
  1840. alert(i_msgHTF + " | " + syminfo.ticker + " | " + tfLabel(HC_TF1) + "/" + tfLabel(HC_TF2), alert.freq_once_per_bar_close)
  1841. if i_alertSweep and (sweptBuyNow or sweptSellNow)
  1842. alert(i_msgSweep + " | " + (sweptBuyNow ? "BUYSIDE" : "SELLSIDE") + " | " + syminfo.ticker + " " + tfLabel(timeframe.period), alert.freq_once_per_bar_close)
  1843. if i_alertSMT and (bar_index == lastBullSmtBar + smtLen or bar_index == lastBearSmtBar + smtLen)
  1844. alert(i_msgSMT + " | " + syminfo.ticker + " vs " + SMT_SHORT, alert.freq_once_per_bar_close)
  1845.  
  1846. alertcondition(newBullCisd, "Bullish CISD confirmed", "Bullish CISD confirmed")
  1847. alertcondition(newBearCisd, "Bearish CISD confirmed", "Bearish CISD confirmed")
  1848. alertcondition(sweptBuyNow, "Buyside liquidity swept", "Buyside liquidity swept")
  1849. alertcondition(sweptSellNow, "Sellside liquidity swept", "Sellside liquidity swept")
  1850.  
  1851. plot(na(atr) ? na : atr, "ATR(14)", display = display.data_window)
  1852. plot(volSMA, "Volume SMA(20)", display = display.data_window)
  1853. plot(lastGradeVal, "Last Grade (numeric)", display = display.data_window)
  1854. plot(array.size(cisdBull), "Active Bullish CISDs", display = display.data_window)
  1855. plot(array.size(cisdBear), "Active Bearish CISDs", display = display.data_window)
  1856. plot(array.size(fvgs), "Active HTF FVGs", display = display.data_window)
  1857. plot(array.size(sessLvls), "Session Levels", display = display.data_window)
  1858. plot(array.size(smts), "SMT Count", display = display.data_window)
Advertisement
Comments
Add Comment
Please, Sign In to add comment