ajiim

🎁

Aug 13th, 2026
3,418
4
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 98.75 KB | None | 4 0
  1. //@version=6
  2. indicator("Fractal Model [Pro+]", overlay=true, max_lines_count=500, max_boxes_count=500, max_labels_count=500, max_bars_back=5000)
  3.  
  4. getSMTPair() =>
  5. string ticker = syminfo.ticker
  6. string res = ""
  7. if str.contains(ticker, "MNQ1!")
  8. res := "CME_MINI:MES1!"
  9. else if str.contains(ticker, "MES1!")
  10. res := "CME_MINI:MNQ1!"
  11. else if str.contains(ticker, "MYM1!")
  12. res := "CME_MINI:MNQ1!"
  13. else if str.contains(ticker, "NQ1!") or str.contains(ticker, "NDX") or str.contains(ticker, "QQQ") or ticker == "NQ"
  14. res := "CME_MINI:ES1!"
  15. else if str.contains(ticker, "ES1!") or str.contains(ticker, "SPX") or str.contains(ticker, "SPY") or ticker == "ES"
  16. res := "CME_MINI:NQ1!"
  17. else if str.contains(ticker, "YM1!")
  18. res := "CME_MINI:NQ1!"
  19. else if str.contains(ticker, "RTY1!")
  20. res := "CBOT:YM1!"
  21. else if str.contains(ticker, "NAS100")
  22. res := "SPX500"
  23. else if str.contains(ticker, "SPX500")
  24. res := "NAS100"
  25. else if str.contains(ticker, "US30")
  26. res := "NAS100"
  27. else if str.contains(ticker, "EURUSD")
  28. res := "GBPUSD"
  29. else if str.contains(ticker, "GBPUSD")
  30. res := "EURUSD"
  31. else if str.contains(ticker, "EURCHF")
  32. res := "GBPCHF"
  33. else if str.contains(ticker, "GBPCHF")
  34. res := "EURCHF"
  35. else if str.contains(ticker, "EURCAD")
  36. res := "GBPCAD"
  37. else if str.contains(ticker, "GBPCAD")
  38. res := "EURCAD"
  39. else if str.contains(ticker, "AUDUSD")
  40. res := "NZDUSD"
  41. else if str.contains(ticker, "NZDUSD")
  42. res := "AUDUSD"
  43. else if str.contains(ticker, "EURAUD")
  44. res := "GBPAUD"
  45. else if str.contains(ticker, "GBPAUD")
  46. res := "EURAUD"
  47. else if str.contains(ticker, "AUDCAD")
  48. res := "NZDCAD"
  49. else if str.contains(ticker, "NZDCAD")
  50. res := "AUDCAD"
  51. else if str.contains(ticker, "EURJPY")
  52. res := "GBPJPY"
  53. else if str.contains(ticker, "GBPJPY")
  54. res := "EURJPY"
  55. else if str.contains(ticker, "AUDJPY")
  56. res := "NZDJPY"
  57. else if str.contains(ticker, "NZDJPY")
  58. res := "AUDJPY"
  59. else if str.contains(ticker, "EURNZD")
  60. res := "GBPNZD"
  61. else if str.contains(ticker, "GBPNZD")
  62. res := "EURNZD"
  63. else if str.contains(ticker, "AUDCHF")
  64. res := "NZDCHF"
  65. else if str.contains(ticker, "NZDCHF")
  66. res := "AUDCHF"
  67. else if str.contains(ticker, "CADJPY")
  68. res := "CHFJPY"
  69. else if str.contains(ticker, "CHFJPY")
  70. res := "CADJPY"
  71. else if str.contains(ticker, "USDJPY")
  72. res := "EURJPY"
  73. else if str.contains(ticker, "USDCAD")
  74. res := "EURCAD"
  75. else if str.contains(ticker, "USDCHF")
  76. res := "EURCHF"
  77. else if str.contains(ticker, "6E1!") or ticker == "6E"
  78. res := "CME:6B1!"
  79. else if str.contains(ticker, "6B1!") or ticker == "6B"
  80. res := "CME:6E1!"
  81. else if str.contains(ticker, "6N1!") or ticker == "6N"
  82. res := "CME:6A1!"
  83. else if str.contains(ticker, "6A1!") or ticker == "6A"
  84. res := "CME:6N1!"
  85. else if str.contains(ticker, "XAUUSD")
  86. res := "XAGUSD"
  87. else if str.contains(ticker, "XAGUSD")
  88. res := "XAUUSD"
  89. else if str.contains(ticker, "XAUEUR")
  90. res := "XAUUSD"
  91. else if str.contains(ticker, "XAUGBP")
  92. res := "COMEX:GC1!"
  93. else if str.contains(ticker, "GC1!")
  94. res := "XAGUSD"
  95. else if str.contains(ticker, "XAGEUR")
  96. res := "COMEX:SI1!"
  97. else if str.contains(ticker, "XAGGBP")
  98. res := "COMEX:SI1!"
  99. else if str.contains(ticker, "SIL1!") or str.contains(ticker, "SI1!")
  100. res := "XAGEUR"
  101. else if str.contains(ticker, "CL1!")
  102. res := "NYMEX:RB1!"
  103. else if str.contains(ticker, "RB1!")
  104. res := "NYMEX:HO1!"
  105. else if str.contains(ticker, "HO1!")
  106. res := "NYMEX:CL1!"
  107. else if str.contains(ticker, "MBT1!")
  108. res := "CME:MET1!"
  109. else if str.contains(ticker, "MET1!")
  110. res := "CME:MBT1!"
  111. else if str.contains(ticker, "BTCUSDT") or str.contains(ticker, "BTC")
  112. res := "ETHUSDT"
  113. else if str.contains(ticker, "ETHUSDT") or str.contains(ticker, "ETH")
  114. res := "BTCUSDT"
  115. else
  116. res := "CME_MINI:ES1!"
  117. res
  118.  
  119. var string LINE_STYLE_SOLID = line.style_solid
  120. var string LINE_STYLE_DASHED = line.style_dashed
  121. var string LINE_STYLE_DOTTED = line.style_dotted
  122.  
  123. var string SIZE_TINY = size.tiny
  124. var string SIZE_SMALL = size.small
  125. var string SIZE_NORMAL = size.normal
  126. var string SIZE_LARGE = size.large
  127. var string SIZE_HUGE = size.huge
  128.  
  129. type Candle
  130. float o
  131. float c
  132. float h
  133. float l
  134. int o_idx
  135. int c_idx
  136. int h_idx
  137. int l_idx
  138. box body
  139. line wick_up
  140. line wick_down
  141.  
  142. type Trace
  143. line o
  144. line c
  145. line h
  146. line l
  147. label o_l
  148. label c_l
  149. label h_l
  150. label l_l
  151.  
  152. type Imbalance
  153. box b
  154. int idx
  155.  
  156. type TTFMEvent
  157. bool is_bullish
  158. float invalid_level
  159. int created_bar
  160. int formation_bars
  161. bool failed
  162. bool consolidating
  163. label c2_lbl
  164. label c3_lbl
  165. box tspot_bx
  166. line tspot_ml
  167.  
  168. type LiquidityLine
  169. line ln
  170. float level
  171. bool is_bullish
  172. bool active
  173. int start_bar
  174.  
  175. type SMT
  176. string smtType
  177. string smtPair
  178. float prevChartHigh
  179. float currChartHigh
  180. int prevChartHighTime
  181. int currChartHighTime
  182. float prevChartLow
  183. float currChartLow
  184. int prevChartLowTime
  185. int currChartLowTime
  186. bool confirmed
  187. int creationBar
  188. line smtLine
  189. label smtLabel
  190.  
  191. type CandleSettings
  192. bool show
  193. string htf
  194. int max_display
  195.  
  196. type Settings
  197. int max_sets
  198. color bull_body
  199. color bull_border
  200. color bull_wick
  201. color bear_body
  202. color bear_border
  203. color bear_wick
  204. int offset
  205. int buffer
  206. int htf_buffer
  207. int width
  208. bool trace_show
  209. color trace_o_color
  210. string trace_o_style
  211. int trace_o_size
  212. color trace_c_color
  213. string trace_c_style
  214. int trace_c_size
  215. color trace_h_color
  216. string trace_h_style
  217. int trace_h_size
  218. color trace_l_color
  219. string trace_l_style
  220. int trace_l_size
  221. string trace_anchor
  222. bool label_show
  223. color label_color
  224. string label_size
  225. bool fvg_show
  226. color fvg_color
  227. bool pfvg_show
  228. color pfvg_color
  229. bool pfvg_show_all
  230. int pfvg_max_display
  231. bool pfvg_only_with_tspot
  232. bool vi_show
  233. color vi_color
  234. bool htf_label_show
  235. color htf_label_color
  236. string htf_label_size
  237. bool htf_timer_show
  238. color htf_timer_color
  239. string htf_timer_size
  240. bool htf_line_show
  241. color htf_line_color
  242. int htf_line_width
  243. string htf_line_style
  244. int midline_width
  245. bool show_chart_sweeps
  246.  
  247. type CandleSet
  248. Candle[] candles
  249. Imbalance[] imbalances
  250. CandleSettings settings
  251. label tfName
  252. label tfTimer
  253. line[] htf_starts
  254. float y_shift = 0.0
  255.  
  256. type Helper
  257. string name = "Helper"
  258.  
  259. Settings settings = Settings.new()
  260.  
  261. var CandleSettings SettingsHTF1 = CandleSettings.new()
  262. var CandleSettings SettingsHTF2 = CandleSettings.new()
  263. var CandleSettings SettingsHTF3 = CandleSettings.new()
  264.  
  265. var Candle[] candles_1 = array.new<Candle>(0)
  266. var Candle[] candles_2 = array.new<Candle>(0)
  267. var Candle[] candles_3 = array.new<Candle>(0)
  268.  
  269. var Imbalance[] imbalances_1 = array.new<Imbalance>()
  270. var Imbalance[] imbalances_2 = array.new<Imbalance>()
  271. var Imbalance[] imbalances_3 = array.new<Imbalance>()
  272.  
  273. var CandleSet htf1 = CandleSet.new()
  274. htf1.settings := SettingsHTF1
  275. htf1.candles := candles_1
  276. htf1.imbalances := imbalances_1
  277. htf1.htf_starts := array.new<line>()
  278.  
  279. var CandleSet htf2 = CandleSet.new()
  280. htf2.settings := SettingsHTF2
  281. htf2.candles := candles_2
  282. htf2.imbalances := imbalances_2
  283. htf2.htf_starts := array.new<line>()
  284.  
  285. var CandleSet htf3 = CandleSet.new()
  286. htf3.settings := SettingsHTF3
  287. htf3.candles := candles_3
  288. htf3.imbalances := imbalances_3
  289. htf3.htf_starts := array.new<line>()
  290.  
  291. ui_alerts = input.bool(true, "Alerts?", tooltip="Enable Alerts", group="GENERAL SETTINGS")
  292. ui_history = input.int(2, "History", minval=0, maxval=40, tooltip="Number of previous Fractal Model setups (T-Spot / C2 / C3 / C4 / CISD / Projections) to keep on the chart. 0 = current setup only.", group="GENERAL SETTINGS")
  293.  
  294. ui_fractal = input.string("Automatic...", "Fractal", options=["Automatic...", "Custom"], inline="gen_frac", tooltip="Fractal Mode", group="GENERAL SETTINGS")
  295. ui_c2 = input.bool(true, "C2", inline="gen_frac", group="GENERAL SETTINGS")
  296. ui_c3 = input.bool(true, "C3", inline="gen_frac", group="GENERAL SETTINGS")
  297. ui_c4 = input.bool(true, "C4", inline="gen_frac", tooltip="C settings", group="GENERAL SETTINGS")
  298.  
  299. ui_bias = input.string("Neutral", "Bias", options=["Neutral", "Bullish", "Bearish", "Auto Bias 1", "Auto Bias 2"], inline="gen_bias", tooltip="Bias settings", group="GENERAL SETTINGS")
  300.  
  301. ui_apply_below = input.string("1 hour", "Apply below", options=["1 hour", "4 hours", "Daily"], inline="tf_app", tooltip="Apply Time Filter", group="TIME FILTER")
  302. ui_filter1_en = input.bool(false, "Filter 1", inline="tf_f1", group="TIME FILTER")
  303. ui_filter1_time = input.session("02:00-05:00", "", inline="tf_f1", group="TIME FILTER")
  304. ui_filter2_en = input.bool(false, "Filter 2", inline="tf_f2", group="TIME FILTER")
  305. ui_filter2_time = input.session("08:00-11:00", "", inline="tf_f2", group="TIME FILTER")
  306. ui_filter3_en = input.bool(false, "Filter 3", inline="tf_f3", group="TIME FILTER")
  307. ui_filter3_time = input.session("13:30-16:15", "", inline="tf_f3", group="TIME FILTER")
  308.  
  309. ui_htf_size = input.string("Small", "Size", options=["Small", "Normal", "Large"], inline="htf_sz", group="HTF CANDLES")
  310. ui_htf_hide = input.bool(false, "Hide?", inline="htf_sz", group="HTF CANDLES")
  311.  
  312. ui_offset = input.int(12, "Offset", group="HTF CANDLES")
  313. htf_line_extension = input.float(5.0, "HTF Line Extension (Length)", minval=0.5, step=0.5, group="HTF CANDLES", tooltip="Adjust the vertical line extension from the top and bottom of the HTF candle")
  314.  
  315. ui_body_up = input.color(color.new(#70a880, 0), "Body", inline="htf_bdy", group="HTF CANDLES")
  316. ui_body_dn = input.color(color.new(#000000, 0), "", inline="htf_bdy", group="HTF CANDLES")
  317.  
  318. ui_border_up = input.color(color.new(#5d606b, 0), "Border", inline="htf_brd", group="HTF CANDLES")
  319. ui_border_dn = input.color(color.new(#000000, 0), "", inline="htf_brd", group="HTF CANDLES")
  320.  
  321. ui_wick_up = input.color(color.new(#5d606b, 0), "Wick", inline="htf_wck", group="HTF CANDLES")
  322. ui_wick_dn = input.color(color.new(#5d606b, 0), "", inline="htf_wck", group="HTF CANDLES")
  323.  
  324. ui_show_ttfm = input.bool(true, "Show TTFM Labels?", inline="mdl_ttfm", group="MODEL STYLE")
  325. ui_ttfm_size = input.string("Small", "", options=["Tiny", "Small", "Normal", "Large", "Huge"], inline="mdl_ttfm", group="MODEL STYLE")
  326.  
  327. ui_c1_sweep_col = input.color(color.black, "", inline="mdl_sw", group="MODEL STYLE")
  328. ui_c1_sweep_en = input.bool(true, "Candle 1 Sweep", inline="mdl_sw", group="MODEL STYLE")
  329. ui_c1_sweep_sty = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="mdl_sw", group="MODEL STYLE")
  330. ui_c1_sweep_wid = input.int(1, "Width", inline="mdl_sw", group="MODEL STYLE")
  331.  
  332. ui_bull_cisd_col = input.color(#3b3eff, "", inline="mdl_bu", group="MODEL STYLE")
  333. ui_bull_cisd_en = input.bool(true, "Bullish CISD", inline="mdl_bu", group="MODEL STYLE")
  334. ui_bull_cisd_sty = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="mdl_bu", group="MODEL STYLE")
  335. ui_bull_cisd_wid = input.int(2, "Width", inline="mdl_bu", group="MODEL STYLE")
  336.  
  337. ui_bear_cisd_col = input.color(#f33030, "", inline="mdl_be", group="MODEL STYLE")
  338. ui_bear_cisd_en = input.bool(true, "Bearish CISD", inline="mdl_be", group="MODEL STYLE")
  339. ui_bear_cisd_sty = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="mdl_be", group="MODEL STYLE")
  340. ui_bear_cisd_wid = input.int(2, "Width", inline="mdl_be", group="MODEL STYLE")
  341.  
  342. ui_cisd_max = input.int(2, "CISD Max History", minval=1, group="MODEL STYLE")
  343.  
  344. ui_prot_swing_en = input.bool(true, "Show Protected Swing Dot", inline="mdl_ps", group="MODEL STYLE")
  345. ui_prot_swing_sz = input.string("Small", "Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], inline="mdl_ps", group="MODEL STYLE")
  346.  
  347. ui_eq_sty = input.string("Dotted", "Equilibrium Line Style", options=["Solid", "Dashed", "Dotted"], inline="mdl_eq", group="MODEL STYLE")
  348. ui_eq_wid = input.int(1, "Width", inline="mdl_eq", group="MODEL STYLE")
  349.  
  350. ui_tspot_en = input.bool(true, "T-Spot", inline="mdl_ts", group="MODEL STYLE")
  351. ui_tspot_c1 = input.color(color.new(#00ff33, 95), "", inline="mdl_ts", group="MODEL STYLE")
  352. ui_tspot_c2 = input.color(color.new(#000000, 95), "", inline="mdl_ts", group="MODEL STYLE")
  353.  
  354. ui_proj_en = input.bool(true, "Projections", inline="ob_p1", group="ORDERBLOCK PROJECTIONS")
  355. ui_proj_lvl = input.string("1, 2, 2.5", "", tooltip="Projection Levels", inline="ob_p1", group="ORDERBLOCK PROJECTIONS")
  356.  
  357. ui_proj_lbl_en = input.bool(true, "Labels?", inline="ob_p2", group="ORDERBLOCK PROJECTIONS")
  358. ui_proj_lbl_sz = input.string("Small", "", options=["Tiny", "Small", "Normal", "Large", "Huge"], inline="ob_p2", group="ORDERBLOCK PROJECTIONS")
  359.  
  360. ui_proj_ln_en = input.bool(false, "Lines?", inline="ob_p3", group="ORDERBLOCK PROJECTIONS")
  361. ui_proj_ln_col = input.color(color.gray, "", inline="ob_p3", group="ORDERBLOCK PROJECTIONS")
  362. ui_proj_ln_sty = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="ob_p3", group="ORDERBLOCK PROJECTIONS")
  363. ui_proj_ln_wid = input.int(1, "Width", inline="ob_p3", group="ORDERBLOCK PROJECTIONS")
  364.  
  365. enableSMT = input.bool(true, 'Enable SMT Detection', group = 'SMT Settings')
  366. smtAutoMode = input.bool(true, 'SMT Auto Pair', group = 'SMT Settings')
  367. smtManualPair = input.symbol('', 'SMT Manual Pair', group = 'SMT Settings')
  368. smtLineWidth = input.int(1, 'SMT Line Width', minval = 1, group = 'SMT Settings')
  369. smtKeepOnlyLatest = input.bool(true, 'Keep Only Latest SMTs', group = 'SMT Settings')
  370. smtShowLabel = input.bool(true, 'Show SMT Labels', group = 'SMT Settings')
  371. smtColor = input.color(color.rgb(204, 162, 9), 'SMT Color', group = 'SMT Settings')
  372.  
  373. ui_fl_en = input.bool(true, "", inline="fl_1", group="FORMATION LIQUIDITY")
  374. ui_fl_col = input.color(color.black, "", inline="fl_1", group="FORMATION LIQUIDITY")
  375. ui_fl_sty = input.string("Dotted", "", options=["Solid", "Dashed", "Dotted"], inline="fl_1", group="FORMATION LIQUIDITY")
  376. ui_fl_wid = input.int(1, "Width", inline="fl_1", group="FORMATION LIQUIDITY")
  377. ui_fl_max = input.int(5, "Max Active Lines", group="FORMATION LIQUIDITY", tooltip="Max untouched liquidity lines to display")
  378.  
  379. ui_info_en = input.bool(true, "Show Info?", inline="tbl_1", group="FRACTAL MODEL INFO TABLE")
  380. ui_info_sz = input.string("Small", "", options=["Tiny", "Small", "Normal", "Large", "Huge"], inline="tbl_1", group="FRACTAL MODEL INFO TABLE")
  381. ui_info_brd = input.bool(true, "Border?", tooltip="Show Border", inline="tbl_1", group="FRACTAL MODEL INFO TABLE")
  382.  
  383. ui_tbl_loc_v = input.string("Bottom", "Table Location", options=["Top", "Middle", "Bottom"], inline="tbl_2", group="FRACTAL MODEL INFO TABLE")
  384. ui_tbl_loc_h = input.string("Right", "", options=["Left", "Center", "Right"], inline="tbl_2", group="FRACTAL MODEL INFO TABLE")
  385.  
  386. ui_tbl_ch_en = input.bool(true, "Chart Timeframe", inline="tbl_3", group="FRACTAL MODEL INFO TABLE")
  387. ui_tbl_ast_en = input.bool(true, "Asset", inline="tbl_3", group="FRACTAL MODEL INFO TABLE")
  388.  
  389. ui_tbl_frc_en = input.bool(true, "Fractal", inline="tbl_4", group="FRACTAL MODEL INFO TABLE")
  390. ui_tbl_ttc_en = input.bool(true, "Time to Close", inline="tbl_4", group="FRACTAL MODEL INFO TABLE")
  391. ui_tbl_bias_en = input.bool(true, "Bias", inline="tbl_4", group="FRACTAL MODEL INFO TABLE")
  392. ui_tbl_tf_en = input.bool(false, "Time Filter", inline="tbl_4", group="FRACTAL MODEL INFO TABLE")
  393.  
  394. TEMPLATE_COLOR = color.rgb(0, 0, 0)
  395. htf_mode = ui_fractal == "Automatic..." ? "Auto" : "Custom"
  396. tspot_bias = ui_bias
  397. use_actual_day_change = false
  398.  
  399. layout_mode = input.string("Horizontal Next-to-Each-Other", "HTF Candles Layout", options=["Horizontal Next-to-Each-Other", "Vertical Stacked (Same Offset)"], group="HTF CANDLES")
  400. vertical_gap_mult = input.float(1.2, "Vertical Stacked Gap Multiplier", minval=0.1, step=0.1, group="HTF CANDLES")
  401.  
  402. htf1_max = input.int(6, "Primary HTF Candle Count", minval=1, maxval=50, group="HTF CANDLES")
  403. htf2_max = input.int(4, "Second HTF Candle Count", minval=0, maxval=50, group="HTF CANDLES")
  404. htf3_max = input.int(0, "Third HTF Candle Count", minval=0, maxval=50, group="HTF CANDLES")
  405.  
  406. i_enableSingleHTF = input.bool(false, "Enable Single HTF Mode (Isolate)", group="HTF CANDLES", tooltip="When enabled, only the selected timeframe below will be shown, hiding all other HTF sets.")
  407. i_singleHTFTf = input.string("4 hours", "Single HTF Timeframe", options=["15 minutes", "30 minutes", "45 minutes", "1 hour", "2 hours", "3 hours", "4 hours", "6 hours", "7 hours", "9 hours", "1 day", "1 week", "1 month"], group="HTF CANDLES", tooltip="Select the specific timeframe you want to display on the chart.")
  408. i_singleHTFMax = input.int(6, "Single HTF Candle Count", minval=1, maxval=50, group="HTF CANDLES")
  409.  
  410. float chart_sec = timeframe.in_seconds(timeframe.period)
  411. string h1 = "", string h2 = "", string h3 = ""
  412.  
  413. if htf_mode == "Auto"
  414. if chart_sec <= 60
  415. h1 := "15", h2 := "30", h3 := "60"
  416. else if chart_sec <= 180
  417. h1 := "30", h2 := "60", h3 := "240"
  418. else if chart_sec <= 300
  419. h1 := "60", h2 := "240", h3 := "D"
  420. else if chart_sec <= 900
  421. h1 := "240", h2 := "D", h3 := "W"
  422. else if chart_sec <= 1800
  423. h1 := "240", h2 := "D", h3 := "W"
  424. else if chart_sec <= 3600
  425. h1 := "D", h2 := "W", h3 := "M"
  426. else if chart_sec <= 14400
  427. h1 := "W", h2 := "M", h3 := ""
  428. else if chart_sec <= 86400
  429. h1 := "M", h2 := "", h3 := ""
  430. else
  431. h1 := "M", h2 := "", h3 := ""
  432. else
  433. h1 := "W", h2 := "M", h3 := "D"
  434.  
  435. string resolved_single_tf = switch i_singleHTFTf
  436. "15 minutes" => "15"
  437. "30 minutes" => "30"
  438. "45 minutes" => "45"
  439. "1 hour" => "60"
  440. "2 hours" => "120"
  441. "3 hours" => "180"
  442. "4 hours" => "240"
  443. "6 hours" => "360"
  444. "7 hours" => "420"
  445. "9 hours" => "540"
  446. "1 day" => "D"
  447. "1 week" => "W"
  448. "1 month" => "M"
  449. => "240"
  450.  
  451. int final_htf1_max = htf1_max
  452. int final_htf2_max = htf2_max
  453. int final_htf3_max = htf3_max
  454.  
  455. if i_enableSingleHTF
  456. h1 := resolved_single_tf
  457. h2 := ""
  458. h3 := ""
  459. final_htf1_max := i_singleHTFMax
  460. final_htf2_max := 0
  461. final_htf3_max := 0
  462.  
  463. htf1.settings.show := true
  464. htf1.settings.htf := h1
  465. htf1.settings.max_display := final_htf1_max
  466.  
  467. htf2.settings.show := h2 != "" and final_htf2_max > 0
  468. htf2.settings.htf := h2
  469. htf2.settings.max_display := final_htf2_max
  470.  
  471. htf3.settings.show := h3 != "" and final_htf3_max > 0
  472. htf3.settings.htf := h3
  473. htf3.settings.max_display := final_htf3_max
  474.  
  475. settings.max_sets := 3
  476.  
  477. settings.bull_body := ui_body_up
  478. settings.bear_body := ui_body_dn
  479. settings.bull_border := ui_border_up
  480. settings.bear_border := ui_border_dn
  481. settings.bull_wick := ui_wick_up
  482. settings.bear_wick := ui_wick_dn
  483.  
  484. settings.offset := ui_offset
  485. settings.buffer := 1
  486. settings.htf_buffer := 8
  487. settings.width := 1*2
  488.  
  489. settings.fvg_show := true
  490. settings.fvg_color := color.new(color.gray, 80)
  491. settings.vi_show := true
  492. settings.vi_color := color.new(color.orange, 50)
  493. settings.pfvg_show := false
  494. settings.pfvg_color := color.new(color.blue, 60)
  495. settings.pfvg_show_all := false
  496. settings.pfvg_max_display := 4
  497. settings.pfvg_only_with_tspot := false
  498.  
  499. show_tspot = ui_tspot_en
  500. tspot_bull_box_color = ui_tspot_c1
  501. tspot_bear_box_color = ui_tspot_c2
  502. tspot_line_style = ui_eq_sty == "Solid" ? LINE_STYLE_SOLID : (ui_eq_sty == "Dashed" ? LINE_STYLE_DASHED : LINE_STYLE_DOTTED)
  503. settings.midline_width := ui_eq_wid
  504. tspot_transparency = 90
  505.  
  506. show_tspot_close_line = false
  507. history_max = math.max(ui_history, 1)
  508. show_silver_tspot = false
  509. hide_against_tspots = true
  510. delete_against_tspots = false
  511.  
  512. show_tspot_sweeps = true
  513. usebody_for_confirmation = true
  514. show_confirmation_lines = true
  515. conf_line_color = color.new(#0f33ff, 0)
  516. conf_line_width = 1
  517. confirmation_line_style = LINE_STYLE_SOLID
  518.  
  519. tspot_sweep_label_color = color.white
  520. tspot_sweep_label_size = SIZE_TINY
  521.  
  522. show_ttfm_labels = ui_show_ttfm
  523. ttfm_label_size = ui_ttfm_size == "Tiny" ? SIZE_TINY : ui_ttfm_size == "Small" ? SIZE_SMALL : ui_ttfm_size == "Normal" ? SIZE_NORMAL : ui_ttfm_size == "Large" ? SIZE_LARGE : SIZE_HUGE
  524.  
  525. settings.htf_label_show := true
  526. settings.htf_label_color := color.black
  527. settings.htf_label_size := SIZE_NORMAL
  528. settings.htf_timer_show := true
  529. settings.htf_timer_color := color.black
  530. settings.htf_timer_size := SIZE_NORMAL
  531. settings.htf_line_show := true
  532. settings.htf_line_color := color.rgb(0, 0, 0, 85)
  533. settings.htf_line_width := 1
  534. settings.htf_line_style := LINE_STYLE_SOLID
  535.  
  536. settings.trace_show := false
  537. settings.trace_o_color := color.new(color.gray, 50)
  538. settings.trace_o_style := LINE_STYLE_DOTTED
  539. settings.trace_o_size := 1
  540. settings.trace_c_color := color.new(color.gray, 50)
  541. settings.trace_c_style := LINE_STYLE_DOTTED
  542. settings.trace_c_size := 1
  543. settings.trace_h_color := color.new(color.gray, 50)
  544. settings.trace_h_style := LINE_STYLE_DOTTED
  545. settings.trace_h_size := 1
  546. settings.trace_l_color := color.new(color.gray, 50)
  547. settings.trace_l_style := LINE_STYLE_DOTTED
  548. settings.trace_l_size := 1
  549. settings.trace_anchor := "First Timeframe"
  550.  
  551. settings.label_show := false
  552. settings.label_color := color.new(#eaeaea, 10)
  553. settings.label_size := size.small
  554.  
  555. show_info_table = ui_info_en
  556. table_position = ui_tbl_loc_v + " " + ui_tbl_loc_h
  557. table_bg_color = color.new(color.gray, 100)
  558. table_border_color = ui_info_brd ? color.black : color.new(color.white, 100)
  559. table_text_color = color.black
  560. info_text_size = ui_info_sz == "Tiny" ? SIZE_TINY : ui_info_sz == "Small" ? SIZE_SMALL : ui_info_sz == "Normal" ? SIZE_NORMAL : ui_info_sz == "Large" ? SIZE_LARGE : SIZE_HUGE
  561. table_border_width = ui_info_brd ? 1 : 0
  562. table_frame_color = color.black
  563. table_frame_width = 0
  564.  
  565. show_projections = ui_proj_en
  566. projection_color = ui_proj_ln_col
  567. projection_levels = ui_proj_lvl
  568. extend_latest_projections = true
  569. projection_label_size = ui_proj_lbl_sz == "Tiny" ? SIZE_TINY : ui_proj_lbl_sz == "Small" ? SIZE_SMALL : ui_proj_lbl_sz == "Normal" ? SIZE_NORMAL : ui_proj_lbl_sz == "Large" ? SIZE_LARGE : SIZE_HUGE
  570.  
  571. var float chartPivotHigh = na, var float chartPivotLow = na
  572. var int chartPivotHighTime = na, var int chartPivotLowTime = na
  573. var float smtPivotHigh = na, var float smtPivotLow = na
  574. var float prevChartPivotHigh = na, var float prevChartPivotLow = na
  575. var int prevChartPivotHighTime = na, var int prevChartPivotLowTime = na
  576. var float prevSmtPivotHigh = na, var float prevSmtPivotLow = na
  577.  
  578. var smtArray = array.new<SMT>()
  579. var smtLabels = array.new<label>()
  580. var float prevCH_smt = na, var int prevCHT_smt = na
  581. var float currCH_smt = na, var int currCHT_smt = na
  582. var float prevCL_smt = na, var int prevCLT_smt = na
  583. var float currCL_smt = na, var int currCLT_smt = na
  584. var line liveBearSmtL = na
  585. var line liveBullSmtL = na
  586.  
  587. var line[] htf_lines = array.new_line(0)
  588. var label[] htf_labels = array.new_label(0)
  589. var label[] htf_labels_bottom = array.new_label(0)
  590. var box[] tspot_boxes = array.new_box(0)
  591. var line[] fl_lines = array.new_line(0)
  592. var LiquidityLine[] active_liq_lines = array.new<LiquidityLine>()
  593.  
  594. add_liquidity_line(int s_bar, float level, bool is_bullish, color col, string style_str, int wid, int max_lines) =>
  595. fl_style = style_str == "Dashed" ? line.style_dashed : style_str == "Solid" ? line.style_solid : line.style_dotted
  596. bool exists = false
  597. if array.size(active_liq_lines) > 0
  598. for i = 0 to array.size(active_liq_lines) - 1
  599. LiquidityLine ll = array.get(active_liq_lines, i)
  600. if math.abs(ll.level - level) < 1e-7
  601. exists := true
  602. break
  603. if not exists
  604. line ln = line.new(s_bar, level, bar_index, level, color=col, style=fl_style, width=wid)
  605. LiquidityLine ll = LiquidityLine.new(ln, level, is_bullish, true, s_bar)
  606. array.unshift(active_liq_lines, ll)
  607. if array.size(active_liq_lines) > max_lines
  608. LiquidityLine oldest = array.pop(active_liq_lines)
  609. line.delete(oldest.ln)
  610.  
  611. var line[] tspot_midlines = array.new_line(0)
  612. var line[] tspot_closelines = array.new_line(0)
  613. var line[] sweep_lines = array.new_line(0)
  614. var line[] chart_sweep_lines = array.new_line(0)
  615. var line[] midpoint_lines = array.new_line(0)
  616. var label[] c2_labels = array.new_label(0)
  617.  
  618. var label[] c3_labels = array.new_label(0)
  619. var line[] confirmation_lines = array.new_line(0)
  620. var TTFMEvent[] ttfm_events = array.new<TTFMEvent>()
  621.  
  622. var table info_table = na
  623.  
  624. var bool tspot_touched = false
  625. var string tspot_type = ""
  626. var float tspot_level = 0.0
  627. var int touch_bar = 0
  628. var int last_tspot_start_bar = 0
  629. var float last_pivot_high = na
  630. var float last_pivot_low = na
  631. var int last_pivot_high_bar = 0
  632. var int last_pivot_low_bar = 0
  633.  
  634. var int current_table_rows = 3
  635.  
  636. findLevelBarIndex(target_level, max_bars_back) =>
  637. var int found_bar = 0
  638. for i = 0 to max_bars_back
  639. if high[i] == target_level or low[i] == target_level
  640. found_bar := bar_index - i
  641. break
  642. found_bar
  643.  
  644. find_exact_high_bar(float target_price, int max_back) =>
  645. int found_bar = na
  646. for i = 0 to math.min(max_back, 4999)
  647. if math.abs(high[i] - target_price) < 1e-7
  648. found_bar := bar_index - i
  649. break
  650. found_bar
  651.  
  652. find_exact_low_bar(float target_price, int max_back) =>
  653. int found_bar = na
  654. for i = 0 to math.min(max_back, 4999)
  655. if math.abs(low[i] - target_price) < 1e-7
  656. found_bar := bar_index - i
  657. break
  658. found_bar
  659.  
  660. var array<line> projection_lines = array.new<line>()
  661. var array<label> projection_labels = array.new<label>()
  662. var array<line> cisd_lines = array.new<line>()
  663. var array<label> protected_swing_labels = array.new<label>()
  664.  
  665. detectCISDAndProjections(int c2_bar, float c2_extreme_level, bool is_bullish, int end_bar) =>
  666. series_high = usebody_for_confirmation ? math.max(open[bar_index - c2_bar], close[bar_index - c2_bar]) : c2_extreme_level
  667. series_low = usebody_for_confirmation ? math.min(open[bar_index - c2_bar], close[bar_index - c2_bar]) : c2_extreme_level
  668. series_count = 0
  669.  
  670. series_count := 1
  671.  
  672. float true_extreme_val = is_bullish ? low[bar_index - c2_bar] : high[bar_index - c2_bar]
  673. int true_extreme_bar = c2_bar
  674.  
  675. for i = 1 to 20
  676. check_bar = c2_bar - i
  677. if check_bar < 0
  678. break
  679.  
  680. is_bullish_candle = close[bar_index - check_bar] > open[bar_index - check_bar]
  681.  
  682. if is_bullish
  683. if not is_bullish_candle
  684. candle_high = usebody_for_confirmation ? math.max(open[bar_index - check_bar], close[bar_index - check_bar]) : high[bar_index - check_bar]
  685. candle_low = usebody_for_confirmation ? math.min(open[bar_index - check_bar], close[bar_index - check_bar]) : low[bar_index - check_bar]
  686. series_high := math.max(series_high, candle_high)
  687. series_low := math.min(series_low, candle_low)
  688. if low[bar_index - check_bar] < true_extreme_val
  689. true_extreme_val := low[bar_index - check_bar]
  690. true_extreme_bar := check_bar
  691. series_count += 1
  692. else
  693. break
  694. else
  695. if is_bullish_candle
  696. candle_high = usebody_for_confirmation ? math.max(open[bar_index - check_bar], close[bar_index - check_bar]) : high[bar_index - check_bar]
  697. candle_low = usebody_for_confirmation ? math.min(open[bar_index - check_bar], close[bar_index - check_bar]) : low[bar_index - check_bar]
  698. series_high := math.max(series_high, candle_high)
  699. series_low := math.min(series_low, candle_low)
  700. if high[bar_index - check_bar] > true_extreme_val
  701. true_extreme_val := high[bar_index - check_bar]
  702. true_extreme_bar := check_bar
  703. series_count += 1
  704. else
  705. break
  706.  
  707. series_broken = false
  708. break_bar = 0
  709.  
  710. for i = 0 to (bar_index - c2_bar)
  711. check_bar = c2_bar + i
  712. if check_bar > bar_index
  713. break
  714.  
  715. if is_bullish
  716. if close[bar_index - check_bar] > series_high
  717. series_broken := true
  718. break_bar := check_bar
  719. break
  720. else
  721. if close[bar_index - check_bar] < series_low
  722. series_broken := true
  723. break_bar := check_bar
  724. break
  725.  
  726. if series_broken
  727. bool dir_cisd_enabled = is_bullish ? ui_bull_cisd_en : ui_bear_cisd_en
  728. if dir_cisd_enabled
  729. color dir_cisd_color = is_bullish ? ui_bull_cisd_col : ui_bear_cisd_col
  730. int dir_cisd_width = is_bullish ? ui_bull_cisd_wid : ui_bear_cisd_wid
  731. string dir_cisd_sty = is_bullish ? ui_bull_cisd_sty : ui_bear_cisd_sty
  732. string dir_cisd_style = dir_cisd_sty == "Dashed" ? line.style_dashed : dir_cisd_sty == "Dotted" ? line.style_dotted : line.style_solid
  733.  
  734. series_extreme = is_bullish ? series_high : series_low
  735. last_series_bar = c2_bar - (series_count - 1)
  736. cisd_line = line.new(last_series_bar, series_extreme, break_bar, series_extreme, color=dir_cisd_color, style=dir_cisd_style, width=dir_cisd_width)
  737. array.unshift(cisd_lines, cisd_line)
  738.  
  739. if array.size(cisd_lines) > ui_cisd_max
  740. line.delete(array.pop(cisd_lines))
  741.  
  742. if ui_prot_swing_en
  743. string label_sz_input = ui_prot_swing_sz == "Tiny" ? size.tiny : ui_prot_swing_sz == "Small" ? size.small : ui_prot_swing_sz == "Normal" ? size.normal : ui_prot_swing_sz == "Large" ? size.large : size.huge
  744. string lbl_style = is_bullish ? label.style_label_up : label.style_label_down
  745. prot_swing_lbl = label.new(true_extreme_bar, true_extreme_val, "●", color=color.new(color.white, 100), textcolor=dir_cisd_color, style=lbl_style, size=label_sz_input)
  746. array.unshift(protected_swing_labels, prot_swing_lbl)
  747.  
  748. if array.size(protected_swing_labels) > ui_cisd_max
  749. label.delete(array.pop(protected_swing_labels))
  750.  
  751. if show_projections
  752. if array.size(projection_lines) > 0
  753. for ln in projection_lines
  754. line.delete(ln)
  755. array.clear(projection_lines)
  756. if array.size(projection_labels) > 0
  757. for lbl in projection_labels
  758. label.delete(lbl)
  759. array.clear(projection_labels)
  760.  
  761. series_range = series_high - series_low
  762. if series_range > 0
  763. break_price = is_bullish ? series_high : series_low
  764. left_anchor_bar = c2_bar - (series_count - 1)
  765. levels = str.split(projection_levels, ",")
  766. proj_line_style = ui_proj_ln_sty == "Dashed" ? line.style_dashed : ui_proj_ln_sty == "Solid" ? line.style_solid : line.style_dotted
  767. for i = 0 to array.size(levels) - 1
  768. level_str = str.trim(array.get(levels, i))
  769. if level_str != ""
  770. level = str.tonumber(level_str)
  771. if not na(level)
  772. proj_price = is_bullish ? break_price + (series_range * level) : break_price - (series_range * level)
  773. if ui_proj_ln_en
  774. proj_line = line.new(left_anchor_bar, proj_price, bar_index, proj_price, color=projection_color, style=proj_line_style, width=ui_proj_ln_wid)
  775. array.unshift(projection_lines, proj_line)
  776. if ui_proj_lbl_en
  777. string formatted_level = level > 0 ? "-" + str.tostring(level) : str.tostring(level)
  778. proj_label = label.new(left_anchor_bar, proj_price, formatted_level, color=color.new(color.white, 100), textcolor=projection_color, style=label.style_label_right, size=projection_label_size, text_font_family=font.family_monospace)
  779. array.unshift(projection_labels, proj_label)
  780.  
  781. Helper helper = Helper.new()
  782. var Trace trace = Trace.new()
  783. color color_transparent = #ffffff00
  784.  
  785. var string resolved_bias = "Neutral"
  786.  
  787. method LineStyle(Helper helper, string style) =>
  788. helper.name := style
  789. switch style
  790. '----' => line.style_dashed
  791. '····' => line.style_dotted
  792. => line.style_solid
  793.  
  794. method ValidTimeframe(Helper helper, string HTF) =>
  795. helper.name := HTF
  796. if timeframe.in_seconds(HTF) >= timeframe.in_seconds("1D") and timeframe.in_seconds(HTF) > timeframe.in_seconds()
  797. true
  798. else
  799. n1 = timeframe.in_seconds()
  800. n2 = timeframe.in_seconds(HTF)
  801. n3 = n1 % n2
  802. (n1 < n2 and math.round(n2/n1) == n2/n1)
  803.  
  804. method RemainingTime(Helper helper, string HTF) =>
  805. helper.name := HTF
  806. if barstate.isrealtime
  807. timeRemaining = (time_close(HTF) - timenow)/1000
  808. days = math.floor(timeRemaining / 86400)
  809. hours = math.floor((timeRemaining - (days*86400)) / 3600)
  810. minutes = math.floor((timeRemaining - (days*86400) - (hours*3600))/ 60)
  811. seconds = math.floor(timeRemaining - (days*86400) - (hours*3600) - (minutes*60))
  812.  
  813. r = str.tostring(seconds, "00")
  814. if minutes > 0 or hours > 0 or days > 0
  815. r := str.tostring(minutes, "00") + ":" + r
  816. if hours > 0 or days > 0
  817. r := str.tostring(hours, "00") + ":" + r
  818. if days > 0
  819. r := str.tostring(days) + "D " + r
  820. r
  821. else
  822. "n/a"
  823.  
  824. method HTFName(Helper helper, string HTF) =>
  825. helper.name := "HTFName"
  826. formatted = HTF
  827. seconds = timeframe.in_seconds(HTF)
  828. if seconds < 60
  829. formatted := str.tostring(seconds) + "S"
  830. else if (seconds / 60) < 60
  831. formatted := str.tostring((seconds/60)) + "M"
  832. else if (seconds/60/60) < 24
  833. formatted := str.tostring((seconds/60/60)) + "H"
  834. formatted
  835.  
  836. method GetCurrentTimeframe(Helper helper) =>
  837. helper.name := "GetCurrentTimeframe"
  838. current_seconds = timeframe.in_seconds()
  839. if current_seconds < 60
  840. str.tostring(current_seconds) + "S"
  841. else if (current_seconds / 60) < 60
  842. str.tostring((current_seconds/60)) + "M"
  843. else if (current_seconds/60/60) < 24
  844. str.tostring((current_seconds/60/60)) + "H"
  845. else
  846. str.tostring((current_seconds/60/60/24)) + "D"
  847.  
  848. method GetCurrentBias(Helper helper) =>
  849. helper.name := "GetCurrentBias"
  850. if tspot_bias == "Bullish"
  851. "Bias: Bullish"
  852. else if tspot_bias == "Bearish"
  853. "Bias: Bearish"
  854. else
  855. "Bias: Neutral"
  856.  
  857. method GetHTFBias(Helper helper, Candle last_closed, Candle prev_closed) =>
  858. helper.name := "GetHTFBias"
  859.  
  860. if na(last_closed) or na(prev_closed)
  861. "Bias: Neutral"
  862. else
  863. last_close = last_closed.c
  864. prev_close = prev_closed.c
  865. last_high = last_closed.h
  866. last_low = last_closed.l
  867. prev_high = prev_closed.h
  868. prev_low = prev_closed.l
  869. last_open = last_closed.o
  870.  
  871. swept_high = last_high > prev_high
  872. swept_low = last_low < prev_low
  873.  
  874. if last_close > prev_high
  875. "Bias: Bullish"
  876. else if last_close < prev_low
  877. "Bias: Bearish"
  878. else if swept_high and last_close < prev_high
  879. "Bias: Bearish"
  880. else if swept_low and last_close > prev_low
  881. "Bias: Bullish"
  882. else if not swept_high and not swept_low
  883. "Bias: Neutral"
  884. else if swept_high and swept_low
  885. upper_wick = last_high - math.max(last_open, last_close)
  886. lower_wick = math.min(last_open, last_close) - last_low
  887. if lower_wick > upper_wick
  888. "Bias: Bearish"
  889. else if upper_wick > lower_wick
  890. "Bias: Bullish"
  891. else
  892. "Bias: Neutral"
  893. else
  894. "Bias: Neutral"
  895.  
  896. method GetTablePosition(Helper helper, string position) =>
  897. helper.name := "GetTablePosition"
  898. switch position
  899. 'Top Left' => position.top_left
  900. 'Top Center' => position.top_center
  901. 'Top Right' => position.top_right
  902. 'Middle Left' => position.middle_left
  903. 'Middle Center' => position.middle_center
  904. 'Middle Right' => position.middle_right
  905. 'Bottom Left' => position.bottom_left
  906. 'Bottom Center' => position.bottom_center
  907. 'Bottom Right' => position.bottom_right
  908. => position.top_right
  909.  
  910. method HTFEnabled(Helper helper) =>
  911. helper.name := "HTFEnabled"
  912. int enabled = 0
  913. enabled += htf1.settings.show ? 1 : 0
  914. enabled += htf2.settings.show ? 1 : 0
  915. enabled += htf3.settings.show ? 1 : 0
  916. int last = math.min(enabled, settings.max_sets)
  917. last
  918.  
  919. method CandleSetHigh(Helper helper, Candle[] candles, float h) =>
  920. helper.name := "CandlesSetHigh"
  921. float _h = h
  922. if array.size(candles) > 0
  923. for i = 0 to array.size(candles)-1
  924. Candle c = array.get(candles, i)
  925. if c.h > _h
  926. _h := c.h
  927. _h
  928.  
  929. method CandlesHigh(Helper helper, Candle[] candles) =>
  930. helper.name := "CandlesHigh"
  931. h = 0.0
  932. int cnt = 0
  933. int last = helper.HTFEnabled()
  934.  
  935. if htf1.settings.show and helper.ValidTimeframe(htf1.settings.htf)
  936. h := helper.CandleSetHigh(htf1.candles, h)
  937. cnt += 1
  938. if htf2.settings.show and helper.ValidTimeframe(htf2.settings.htf) and cnt < last
  939. h := helper.CandleSetHigh(htf2.candles, h)
  940. cnt +=1
  941. if htf3.settings.show and helper.ValidTimeframe(htf3.settings.htf) and cnt < last
  942. h := helper.CandleSetHigh(htf3.candles, h)
  943. h
  944.  
  945. if array.size(candles) > 0
  946. for i = 0 to array.size(candles)-1
  947. Candle c = array.get(candles, i)
  948. if c.h > h
  949. h := c.h
  950. h
  951.  
  952. method Reorder(CandleSet candleSet, int offset) =>
  953. size = candleSet.candles.size()
  954. if size > 0
  955. for i = size-1 to 0
  956. Candle candle = candleSet.candles.get(i)
  957. t_buffer = offset + ((settings.width+settings.buffer)*(size-i-1))
  958. box.set_left(candle.body, bar_index + t_buffer)
  959. box.set_right(candle.body, bar_index + settings.width + t_buffer)
  960. line.set_x1(candle.wick_up, bar_index+((settings.width)/2) + t_buffer)
  961. line.set_x2(candle.wick_up, bar_index+((settings.width)/2) + t_buffer)
  962. line.set_x1(candle.wick_down, bar_index+((settings.width)/2) + t_buffer)
  963. line.set_x2(candle.wick_down, bar_index+((settings.width)/2) + t_buffer)
  964. candleSet
  965.  
  966. top = helper.CandleSetHigh(candleSet.candles, 0.0) - candleSet.y_shift
  967. left = bar_index + offset + ((settings.width+settings.buffer)*(size-1))/2
  968.  
  969. if settings.htf_label_show
  970. var label l = candleSet.tfName
  971. string lbl = helper.HTFName(candleSet.settings.htf)
  972. if settings.htf_timer_show
  973. lbl += "\n"
  974. if not na(l)
  975. label.set_xy(l, left, top)
  976. else
  977. l := label.new(left, top, lbl, color=color_transparent, textcolor = settings.htf_label_color, style=label.style_label_down, size = settings.htf_label_size, text_font_family=font.family_monospace)
  978.  
  979. if settings.htf_timer_show
  980. string tmr = "(" + helper.RemainingTime(candleSet.settings.htf) + ")"
  981. if not na(candleSet.tfTimer)
  982. candleSet.tfTimer.set_xy(left, top)
  983. candleSet.tfTimer.set_text(tmr)
  984. else
  985. candleSet.tfTimer := label.new(left, top, tmr, color=color_transparent, textcolor = settings.htf_timer_color, style=label.style_label_down, size = settings.htf_timer_size, text_font_family=font.family_monospace)
  986.  
  987. if candleSet.htf_starts.size() > 0
  988. for i = 0 to candleSet.htf_starts.size() - 1
  989. line l = candleSet.htf_starts.get(i)
  990. if not na(l)
  991. t_buffer = offset + ((settings.width+settings.buffer)*(i))
  992. line.set_x1(l, bar_index + t_buffer)
  993. line.set_x2(l, bar_index + t_buffer)
  994. candleSet
  995.  
  996. method calculateLogMidpoint(float high, float low, float open, float close) =>
  997. float log_high = math.log(high)
  998. float log_low = math.log(low)
  999. float log_open = math.log(open)
  1000. float log_close = math.log(close)
  1001.  
  1002. float body_size = math.abs(log_close - log_open)
  1003. float upper_wick = log_high - math.max(log_open, log_close)
  1004. float lower_wick = math.min(log_open, log_close) - log_low
  1005.  
  1006. float log_mid_level = if math.max(upper_wick, lower_wick) > body_size
  1007. if upper_wick > lower_wick
  1008. log_high - upper_wick/2
  1009. else
  1010. log_low + lower_wick/2
  1011. else
  1012. (log_high + log_low)/2
  1013.  
  1014. math.exp(log_mid_level)
  1015.  
  1016. method FindImbalance(CandleSet candleSet, bool isPrimary, bool drawSweep) =>
  1017. if barstate.isrealtime or barstate.islast
  1018. while candleSet.imbalances.size() > 0
  1019. Imbalance del = candleSet.imbalances.pop()
  1020. box.delete(del.b)
  1021.  
  1022. if candleSet.candles.size() > 3 and settings.fvg_show
  1023. if isPrimary
  1024. for i = 0 to candleSet.candles.size() - 2
  1025. current_candle = candleSet.candles.get(i)
  1026. prev_candle = candleSet.candles.get(i + 1)
  1027. float mid_level = calculateLogMidpoint(prev_candle.h, prev_candle.l, prev_candle.o, prev_candle.c)
  1028. midpoint_line = line.new(box.get_left(prev_candle.body) + settings.width/2, mid_level,box.get_left(current_candle.body) + settings.width/2, mid_level,color=TEMPLATE_COLOR, width=1, style=line.style_dotted)
  1029. midpoint_lines.unshift(midpoint_line)
  1030.  
  1031. if drawSweep
  1032. for i = 0 to candleSet.candles.size() - 2
  1033. current_candle = candleSet.candles.get(i)
  1034. next_candle = candleSet.candles.get(i + 1)
  1035. if current_candle.h > next_candle.h and current_candle.c < next_candle.h
  1036. sweep_line = line.new(box.get_left(next_candle.body) + settings.width/2, next_candle.h, box.get_right(current_candle.body) + settings.width, next_candle.h, color=TEMPLATE_COLOR, width=1)
  1037. sweep_lines.unshift(sweep_line)
  1038. if current_candle.l < next_candle.l and current_candle.c > next_candle.l
  1039. sweep_line = line.new(box.get_left(next_candle.body) + settings.width/2, next_candle.l, box.get_right(current_candle.body) + settings.width, next_candle.l, color=TEMPLATE_COLOR, width=1)
  1040. sweep_lines.unshift(sweep_line)
  1041.  
  1042. if candleSet.candles.size() > 3 and settings.fvg_show
  1043. for i = 0 to candleSet.candles.size() -3
  1044. candle1 = candleSet.candles.get(i)
  1045. candle2 = candleSet.candles.get(i+2)
  1046. candle3 = candleSet.candles.get(i+1)
  1047. if (candle1.l > candle2.h and math.min(candle1.o, candle1.c) > math.max(candle2.o, candle2.c))
  1048. Imbalance imb = Imbalance.new()
  1049. imb.b := box.new(box.get_left(candle2.body), candle2.h, box.get_right(candle1.body), candle1.l, bgcolor=settings.fvg_color, border_color = color_transparent, xloc=xloc.bar_index)
  1050. candleSet.imbalances.push(imb)
  1051. if (candle1.h < candle2.l and math.max(candle1.o, candle1.c) < math.min(candle2.o, candle2.c))
  1052. Imbalance imb = Imbalance.new()
  1053. imb.b := box.new(box.get_right(candle1.body), candle1.h, box.get_left(candle2.body), candle2.l, bgcolor=settings.fvg_color, border_color = color_transparent)
  1054. candleSet.imbalances.push(imb)
  1055. box temp = box.copy(candle3.body)
  1056. box.delete(candle3.body)
  1057. candle3.body := temp
  1058.  
  1059. if candleSet.candles.size() > 2 and settings.vi_show
  1060. for i = 0 to candleSet.candles.size() -2
  1061. candle1 = candleSet.candles.get(i)
  1062. candle2 = candleSet.candles.get(i+1)
  1063. if (candle1.l < candle2.h and math.min(candle1.o, candle1.c) > math.max(candle2.o, candle2.c))
  1064. Imbalance imb = Imbalance.new()
  1065. imb.b := box.new(box.get_left(candle2.body), math.min(candle1.o, candle1.c), box.get_right(candle1.body), math.max(candle2.o, candle2.c), bgcolor=settings.vi_color, border_color = color_transparent)
  1066. candleSet.imbalances.push(imb)
  1067. if (candle1.h > candle2.l and math.max(candle1.o, candle1.c) < math.min(candle2.o, candle2.c))
  1068. Imbalance imb = Imbalance.new()
  1069. imb.b := box.new(box.get_right(candle1.body), math.min(candle2.o, candle2.c), box.get_left(candle2.body), math.max(candle1.o, candle1.c), bgcolor=settings.vi_color, border_color = color_transparent)
  1070. candleSet.imbalances.push(imb)
  1071. candleSet
  1072.  
  1073. barHour = hour(time)
  1074.  
  1075. candleOfDay = math.floor(barHour / 4) + 1
  1076.  
  1077. label_atr = ta.atr(200) / 2
  1078.  
  1079. method Monitor(CandleSet candleSet, bool drawLines) =>
  1080. HTFBarTime = time(candleSet.settings.htf)
  1081. isNewHTFCandle = use_actual_day_change and candleSet.settings.htf == "1D" ? dayofmonth(time) != dayofmonth(time[1]) : ta.change(HTFBarTime) != 0
  1082.  
  1083. if isNewHTFCandle
  1084. if drawLines and settings.htf_line_show
  1085. float visual_offset = label_atr * htf_line_extension
  1086. htf_lines.unshift(line.new(bar_index, high + visual_offset, bar_index, low - visual_offset, color=settings.htf_line_color, style=settings.htf_line_style, width=settings.htf_line_width, extend=extend.none))
  1087.  
  1088. float htf_sec = timeframe.in_seconds(candleSet.settings.htf)
  1089. string timeStr = ""
  1090.  
  1091. if htf_sec >= 2419200
  1092. string m_name = switch month(time)
  1093. 1 => "Jan"
  1094. 2 => "Feb"
  1095. 3 => "Mar"
  1096. 4 => "Apr"
  1097. 5 => "May"
  1098. 6 => "Jun"
  1099. 7 => "Jul"
  1100. 8 => "Aug"
  1101. 9 => "Sep"
  1102. 10 => "Oct"
  1103. 11 => "Nov"
  1104. 12 => "Dec"
  1105. => ""
  1106. timeStr := m_name
  1107. else if htf_sec >= 604800
  1108. string m_name = switch month(time)
  1109. 1 => "Jan"
  1110. 2 => "Feb"
  1111. 3 => "Mar"
  1112. 4 => "Apr"
  1113. 5 => "May"
  1114. 6 => "Jun"
  1115. 7 => "Jul"
  1116. 8 => "Aug"
  1117. 9 => "Sep"
  1118. 10 => "Oct"
  1119. 11 => "Nov"
  1120. 12 => "Dec"
  1121. => ""
  1122. timeStr := str.tostring(dayofmonth(time)) + " " + m_name
  1123. else if htf_sec >= 86400
  1124. string d_name = switch dayofweek(time)
  1125. 1 => "Sun"
  1126. 2 => "Mon"
  1127. 3 => "Tue"
  1128. 4 => "Wed"
  1129. 5 => "Thu"
  1130. 6 => "Fri"
  1131. 7 => "Sat"
  1132. => ""
  1133. timeStr := d_name
  1134. else
  1135. timeStr := str.tostring(hour(time), "00") + ":" + str.tostring(minute(time), "00")
  1136.  
  1137. htf_labels.unshift(label.new(bar_index, high + visual_offset, text=timeStr, color=color.new(color.white, 100), textcolor=settings.htf_line_color, style=label.style_label_down, size=size.tiny))
  1138.  
  1139. if htf_lines.size() > candleSet.settings.max_display
  1140. line.delete(htf_lines.pop())
  1141. if htf_labels.size() > candleSet.settings.max_display
  1142. label.delete(htf_labels.pop())
  1143. if htf_labels_bottom.size() > candleSet.settings.max_display
  1144. label.delete(htf_labels_bottom.pop())
  1145.  
  1146. Candle candle = Candle.new()
  1147. candle.o := open, candle.c := close, candle.h := high, candle.l := low
  1148. candle.o_idx := bar_index, candle.c_idx := bar_index, candle.h_idx := bar_index, candle.l_idx := bar_index
  1149. bull = candle.c > candle.o
  1150. candle.body := box.new(bar_index, math.max(candle.o, candle.c) - candleSet.y_shift, bar_index+2, math.min(candle.o, candle.c) - candleSet.y_shift,
  1151. bull ? settings.bull_border : settings.bear_border, 1, bgcolor = bull ? settings.bull_body : settings.bear_body)
  1152. candle.wick_up := line.new(bar_index+1, candle.h - candleSet.y_shift, bar_index, math.max(candle.o, candle.c) - candleSet.y_shift,
  1153. color=bull ? settings.bull_wick : settings.bear_wick)
  1154. candle.wick_down := line.new(bar_index+1, math.min(candle.o, candle.c) - candleSet.y_shift, bar_index, candle.l - candleSet.y_shift,
  1155. color=bull ? settings.bull_wick : settings.bear_wick)
  1156. candleSet.candles.unshift(candle)
  1157.  
  1158. if candleSet.candles.size() > candleSet.settings.max_display
  1159. Candle del = array.pop(candleSet.candles)
  1160. box.delete(del.body), line.delete(del.wick_up), line.delete(del.wick_down)
  1161.  
  1162. htf_bars = int(timeframe.in_seconds(candleSet.settings.htf) / timeframe.in_seconds())
  1163.  
  1164. if drawLines and candleSet.candles.size() >= 4 and show_tspot
  1165. current_candle = candleSet.candles.get(0)
  1166. last_closed = candleSet.candles.get(1)
  1167. prev_closed = candleSet.candles.get(2)
  1168. prev_prev_closed = candleSet.candles.get(3)
  1169.  
  1170. latest_line = array.get(htf_lines, 0)
  1171. start_bar = line.get_x2(latest_line)
  1172.  
  1173. oktspot_bearish_bias = resolved_bias == "Bearish" or resolved_bias == "Neutral"
  1174. oktspot_bullish_bias = resolved_bias == "Bullish" or resolved_bias == "Neutral"
  1175.  
  1176. if not na(start_bar)
  1177. end_bar = int(start_bar + htf_bars)
  1178. float mid_level = calculateLogMidpoint(prev_closed.h, prev_closed.l, prev_closed.o, prev_closed.c)
  1179. var bool tspot_created = false
  1180. var int last_htf_candle_bar = 0
  1181.  
  1182. if start_bar != last_htf_candle_bar
  1183. tspot_created := false
  1184. last_htf_candle_bar := start_bar
  1185.  
  1186. if not tspot_created and last_closed.h > prev_closed.h and last_closed.c < prev_closed.h and oktspot_bearish_bias and not (last_closed.h > prev_closed.h and last_closed.l < prev_closed.l and last_closed.c > prev_closed.l and last_closed.c < prev_closed.h)
  1187. if ui_fl_en
  1188. exact_start_bar = find_exact_low_bar(prev_closed.l, htf_bars * 5)
  1189. if not na(exact_start_bar)
  1190. add_liquidity_line(exact_start_bar, prev_closed.l, false, ui_fl_col, ui_fl_sty, ui_fl_wid, ui_fl_max)
  1191.  
  1192. if ui_c1_sweep_en
  1193. string c1_style = ui_c1_sweep_sty == "Dashed" ? line.style_dashed : ui_c1_sweep_sty == "Dotted" ? line.style_dotted : line.style_solid
  1194. int real_start_bar = prev_closed.h_idx
  1195. int real_end_bar = last_closed.h_idx
  1196. if real_start_bar > 0 and real_end_bar > 0
  1197. line real_sweep = line.new(real_start_bar, prev_closed.h, real_end_bar, prev_closed.h, color=ui_c1_sweep_col, width=ui_c1_sweep_wid, style=c1_style)
  1198. array.unshift(chart_sweep_lines, real_sweep)
  1199. if array.size(chart_sweep_lines) > 3
  1200. line.delete(array.pop(chart_sweep_lines))
  1201.  
  1202. sweep_mid = calculateLogMidpoint(last_closed.h, last_closed.l, last_closed.o, last_closed.c)
  1203. if last_closed.c < sweep_mid
  1204. box newBox = box.new(start_bar, sweep_mid, end_bar, last_closed.c,
  1205. bgcolor=tspot_bear_box_color,
  1206. border_color=color.new(color.white, 100))
  1207. line newMidline = line.new(start_bar, sweep_mid, end_bar, sweep_mid,
  1208. color=settings.htf_label_color,
  1209. style=tspot_line_style,
  1210. width=settings.midline_width)
  1211. line newCloseline = show_tspot_close_line ? line.new(start_bar, last_closed.c, end_bar, last_closed.c,
  1212. color=settings.htf_label_color,
  1213. style=tspot_line_style,
  1214. width=settings.midline_width) : na
  1215.  
  1216. if show_silver_tspot
  1217. if (candleOfDay == 5 or (candleOfDay == 4 and hour(time, "America/New_York") >= 13)) and last_closed.c < prev_prev_closed.l and last_closed.c < prev_closed.l
  1218. label.new(bar_index, high, "Silver T-Spot", color=color.new(color.white, 100), textcolor=settings.bear_body, style=label.style_label_down, size=tspot_sweep_label_size, text_font_family=font.family_monospace)
  1219.  
  1220. tspot_boxes.unshift(newBox)
  1221. tspot_midlines.unshift(newMidline)
  1222. if not na(newCloseline)
  1223. tspot_closelines.unshift(newCloseline)
  1224. tspot_created := true
  1225.  
  1226. c2_level = last_closed.h
  1227. c2_bar = last_closed.h_idx
  1228.  
  1229. if c2_bar > 0
  1230. detectCISDAndProjections(c2_bar, last_closed.h, false, end_bar)
  1231.  
  1232. if c2_bar > 0 and show_ttfm_labels
  1233. c2_label = label.new(c2_bar, c2_level + label_atr, "C2", color=color.new(color.white, 100), textcolor=color.gray, style=label.style_label_down, size=ttfm_label_size, text_font_family=font.family_monospace)
  1234. array.unshift(c2_labels, c2_label)
  1235. c3_label = label.new(bar_index, sweep_mid + label_atr, "C3", color=color.new(color.white, 100), textcolor=color.gray, style=label.style_label_down, size=ttfm_label_size, text_font_family=font.family_monospace)
  1236. array.unshift(c3_labels, c3_label)
  1237. array.unshift(ttfm_events, TTFMEvent.new(is_bullish=false, invalid_level=c2_level, created_bar=bar_index, formation_bars=htf_bars, failed=false, consolidating=false, c2_lbl=c2_label, c3_lbl=c3_label, tspot_bx=newBox, tspot_ml=newMidline))
  1238.  
  1239. if tspot_boxes.size() > history_max
  1240. box.delete(tspot_boxes.pop())
  1241. line.delete(tspot_midlines.pop())
  1242. if tspot_closelines.size() > 0
  1243. line.delete(tspot_closelines.pop())
  1244.  
  1245. if not tspot_created and last_closed.l < prev_closed.l and last_closed.c > prev_closed.l and oktspot_bullish_bias and not (last_closed.h > prev_closed.h and last_closed.l < prev_closed.l and last_closed.c > prev_closed.l and last_closed.c < prev_closed.h)
  1246. if ui_fl_en
  1247. exact_start_bar = find_exact_high_bar(prev_closed.h, htf_bars * 5)
  1248. if not na(exact_start_bar)
  1249. add_liquidity_line(exact_start_bar, prev_closed.h, true, ui_fl_col, ui_fl_sty, ui_fl_wid, ui_fl_max)
  1250.  
  1251. if ui_c1_sweep_en
  1252. string c1_style = ui_c1_sweep_sty == "Dashed" ? line.style_dashed : ui_c1_sweep_sty == "Dotted" ? line.style_dotted : line.style_solid
  1253. int real_start_bar = prev_closed.l_idx
  1254. int real_end_bar = last_closed.l_idx
  1255. if real_start_bar > 0 and real_end_bar > 0
  1256. line real_sweep = line.new(real_start_bar, prev_closed.l, real_end_bar, prev_closed.l, color=ui_c1_sweep_col, width=ui_c1_sweep_wid, style=c1_style)
  1257. array.unshift(chart_sweep_lines, real_sweep)
  1258. if array.size(chart_sweep_lines) > 3
  1259. line.delete(array.pop(chart_sweep_lines))
  1260.  
  1261. sweep_mid = calculateLogMidpoint(last_closed.h, last_closed.l, last_closed.o, last_closed.c)
  1262. if last_closed.c > sweep_mid
  1263. box newBox = box.new(start_bar, sweep_mid, end_bar, last_closed.c,
  1264. bgcolor=color.new(settings.bull_body, tspot_transparency),
  1265. border_color=color.new(color.white, 100))
  1266. line newMidline = line.new(start_bar, sweep_mid, end_bar, sweep_mid,
  1267. color=settings.htf_label_color,
  1268. style=tspot_line_style,
  1269. width=settings.midline_width)
  1270. line newCloseline = show_tspot_close_line ? line.new(start_bar, last_closed.c, end_bar, last_closed.c,
  1271. color=settings.htf_label_color,
  1272. style=tspot_line_style,
  1273. width=settings.midline_width) : na
  1274.  
  1275. if show_silver_tspot
  1276. if (candleOfDay == 5 or (candleOfDay == 4 and hour(time, "America/New_York") >= 13)) and last_closed.c > prev_prev_closed.h and last_closed.c > prev_closed.h
  1277. label.new(bar_index, low, "Silver T-Spot", color=color.new(color.white, 100), textcolor=settings.bear_body, style=label.style_label_up, size=tspot_sweep_label_size, text_font_family=font.family_monospace)
  1278.  
  1279. tspot_boxes.unshift(newBox)
  1280. tspot_midlines.unshift(newMidline)
  1281. if not na(newCloseline)
  1282. tspot_closelines.unshift(newCloseline)
  1283. tspot_created := true
  1284.  
  1285. c2_level = last_closed.l
  1286. c2_bar = last_closed.l_idx
  1287.  
  1288. if c2_bar > 0
  1289. detectCISDAndProjections(c2_bar, last_closed.l, true, end_bar)
  1290.  
  1291. if c2_bar > 0 and show_ttfm_labels
  1292. c2_label = label.new(c2_bar, c2_level - label_atr, "C2", color=color.new(color.white, 100), textcolor=color.gray, style=label.style_label_down, size=ttfm_label_size, text_font_family=font.family_monospace)
  1293. array.unshift(c2_labels, c2_label)
  1294. c3_label = label.new(bar_index, sweep_mid - label_atr, "C3", color=color.new(color.white, 100), textcolor=color.gray, style=label.style_label_down, size=ttfm_label_size, text_font_family=font.family_monospace)
  1295. array.unshift(c3_labels, c3_label)
  1296. array.unshift(ttfm_events, TTFMEvent.new(is_bullish=true, invalid_level=c2_level, created_bar=bar_index, formation_bars=htf_bars, failed=false, consolidating=false, c2_lbl=c2_label, c3_lbl=c3_label, tspot_bx=newBox, tspot_ml=newMidline))
  1297.  
  1298. if tspot_boxes.size() > history_max
  1299. box.delete(tspot_boxes.pop())
  1300. line.delete(tspot_midlines.pop())
  1301. if tspot_closelines.size() > 0
  1302. line.delete(tspot_closelines.pop())
  1303.  
  1304. if not tspot_created and prev_closed.h > prev_prev_closed.h and last_closed.c < math.max(prev_closed.o, prev_closed.c) and oktspot_bearish_bias and not (last_closed.h > prev_closed.h and last_closed.l < prev_closed.l and last_closed.c > prev_closed.l and last_closed.c < prev_closed.h) and ((prev_closed.c >= calculateLogMidpoint(prev_closed.h, prev_closed.l, prev_closed.o, prev_closed.c)) or (prev_closed.c >= prev_prev_closed.h) or (prev_closed.h > prev_prev_closed.h and prev_closed.l < prev_prev_closed.l and prev_closed.c > prev_prev_closed.l and prev_closed.c < prev_prev_closed.h))
  1305. sweep_mid = calculateLogMidpoint(last_closed.h, last_closed.l, last_closed.o, last_closed.c)
  1306. if last_closed.c < sweep_mid
  1307. box newBox = box.new(start_bar, sweep_mid, end_bar, last_closed.c, bgcolor=color.new(settings.bear_body, tspot_transparency), border_color=color.new(color.white, 100))
  1308. if ui_fl_en
  1309. exact_start_bar = find_exact_low_bar(prev_closed.l, htf_bars * 5)
  1310. if not na(exact_start_bar)
  1311. add_liquidity_line(exact_start_bar, prev_closed.l, false, ui_fl_col, ui_fl_sty, ui_fl_wid, ui_fl_max)
  1312. line newMidline = line.new(start_bar, sweep_mid, end_bar, sweep_mid, color=settings.htf_label_color, style=tspot_line_style, width=settings.midline_width)
  1313. line newCloseline = show_tspot_close_line ? line.new(start_bar, last_closed.c, end_bar, last_closed.c, color=settings.htf_label_color,
  1314. style=tspot_line_style,
  1315. width=settings.midline_width) : na
  1316.  
  1317. if show_silver_tspot
  1318. if (candleOfDay == 5 or (candleOfDay == 4 and hour(time, "America/New_York") >= 13)) and last_closed.c < prev_prev_closed.l and last_closed.c < prev_closed.l
  1319. label.new(bar_index, high, "Silver Expansive T-Spot", color=color.new(color.white, 100), textcolor=settings.bear_body, style=label.style_label_down, size=tspot_sweep_label_size, text_font_family=font.family_monospace)
  1320.  
  1321. tspot_boxes.unshift(newBox)
  1322. tspot_midlines.unshift(newMidline)
  1323. if not na(newCloseline)
  1324. tspot_closelines.unshift(newCloseline)
  1325. tspot_created := true
  1326.  
  1327. c2_level = prev_closed.h
  1328. c2_bar = prev_closed.h_idx
  1329.  
  1330. if c2_bar > 0
  1331. detectCISDAndProjections(c2_bar, prev_closed.h, false, end_bar)
  1332.  
  1333. if c2_bar > 0 and show_ttfm_labels
  1334. c2_label = label.new(c2_bar, c2_level + label_atr, "C2", color=color.new(color.white, 100), textcolor=color.gray, style=label.style_label_down, size=ttfm_label_size, text_font_family=font.family_monospace)
  1335. array.unshift(c2_labels, c2_label)
  1336. c4_label = label.new(bar_index, sweep_mid + label_atr, "C4", color=color.new(color.white, 100), textcolor=color.gray, style=label.style_label_down, size=ttfm_label_size, text_font_family=font.family_monospace)
  1337. array.unshift(c3_labels, c4_label)
  1338. array.unshift(ttfm_events, TTFMEvent.new(is_bullish=false, invalid_level=c2_level, created_bar=bar_index, formation_bars=htf_bars, failed=false, consolidating=false, c2_lbl=c2_label, c3_lbl=c4_label, tspot_bx=newBox, tspot_ml=newMidline))
  1339.  
  1340. if tspot_boxes.size() > history_max
  1341. box.delete(tspot_boxes.pop())
  1342. line.delete(tspot_midlines.pop())
  1343. if tspot_closelines.size() > 0
  1344. line.delete(tspot_closelines.pop())
  1345.  
  1346. if not tspot_created and prev_closed.l < prev_prev_closed.l and last_closed.c > math.min(prev_closed.o, prev_closed.c) and oktspot_bullish_bias and not (last_closed.h > prev_closed.h and last_closed.l < prev_closed.l and last_closed.c > prev_closed.l and last_closed.c < prev_closed.h) and ((prev_closed.c <= calculateLogMidpoint(prev_closed.h, prev_closed.l, prev_closed.o, prev_closed.c)) or (prev_closed.c <= prev_prev_closed.l) or (prev_closed.h > prev_prev_closed.h and prev_closed.l < prev_prev_closed.l and prev_closed.c > prev_prev_closed.l and prev_closed.c < prev_prev_closed.h))
  1347. sweep_mid = calculateLogMidpoint(last_closed.h, last_closed.l, last_closed.o, last_closed.c)
  1348.  
  1349. if last_closed.c > sweep_mid
  1350. box newBox = box.new(start_bar, sweep_mid, end_bar, last_closed.c, bgcolor=color.new(settings.bull_body, tspot_transparency), border_color=color.new(color.white, 100))
  1351. if ui_fl_en
  1352. exact_start_bar = find_exact_high_bar(prev_closed.h, htf_bars * 5)
  1353. if not na(exact_start_bar)
  1354. add_liquidity_line(exact_start_bar, prev_closed.h, true, ui_fl_col, ui_fl_sty, ui_fl_wid, ui_fl_max)
  1355. line newMidline = line.new(start_bar, sweep_mid, end_bar, sweep_mid, color=settings.htf_label_color, style=tspot_line_style, width=settings.midline_width)
  1356. line newCloseline = show_tspot_close_line ? line.new(start_bar, last_closed.c, end_bar, last_closed.c, color=settings.htf_label_color,
  1357. style=tspot_line_style,
  1358. width=settings.midline_width) : na
  1359.  
  1360. if show_silver_tspot
  1361. if (candleOfDay == 5 or (candleOfDay == 4 and hour(time, "America/New_York") >= 13)) and last_closed.c > prev_prev_closed.h and last_closed.c > prev_closed.h
  1362. label.new(bar_index, low, "Silver Expansive T-Spot", color=color.new(color.white, 100), textcolor=settings.bull_body, style=label.style_label_up, size=tspot_sweep_label_size, text_font_family=font.family_monospace)
  1363.  
  1364. tspot_boxes.unshift(newBox)
  1365. tspot_midlines.unshift(newMidline)
  1366. if not na(newCloseline)
  1367. tspot_closelines.unshift(newCloseline)
  1368. tspot_created := true
  1369.  
  1370. c2_level = prev_closed.l
  1371. c2_bar = prev_closed.l_idx
  1372.  
  1373. if c2_bar > 0
  1374. detectCISDAndProjections(c2_bar, prev_closed.l, true, end_bar)
  1375.  
  1376. if c2_bar > 0 and show_ttfm_labels
  1377. c2_label = label.new(c2_bar, c2_level - label_atr, "C2", color=color.new(color.white, 100), textcolor=color.gray, style=label.style_label_down, size=ttfm_label_size, text_font_family=font.family_monospace)
  1378. array.unshift(c2_labels, c2_label)
  1379. c4_label = label.new(bar_index, sweep_mid - label_atr, "C4", color=color.new(color.white, 100), textcolor=color.gray, style=label.style_label_down, size=ttfm_label_size, text_font_family=font.family_monospace)
  1380. array.unshift(c3_labels, c4_label)
  1381. array.unshift(ttfm_events, TTFMEvent.new(is_bullish=true, invalid_level=c2_level, created_bar=bar_index, formation_bars=htf_bars, failed=false, consolidating=false, c2_lbl=c2_label, c3_lbl=c4_label, tspot_bx=newBox, tspot_ml=newMidline))
  1382.  
  1383. if tspot_boxes.size() > history_max
  1384. box.delete(tspot_boxes.pop())
  1385. line.delete(tspot_midlines.pop())
  1386. if tspot_closelines.size() > 0
  1387. line.delete(tspot_closelines.pop())
  1388.  
  1389. if not tspot_created and last_closed.l < mid_level and last_closed.l > prev_closed.o and last_closed.c > prev_closed.h and oktspot_bullish_bias and not (last_closed.h > prev_closed.h and last_closed.l < prev_closed.l and last_closed.c > prev_closed.l and last_closed.c < prev_closed.h)
  1390. sweep_mid = calculateLogMidpoint(last_closed.h, last_closed.l, last_closed.o, last_closed.c)
  1391. if last_closed.c > sweep_mid
  1392. box newBox = box.new(start_bar, sweep_mid, end_bar, last_closed.c,
  1393. bgcolor=color.new(settings.bull_body, tspot_transparency),
  1394. border_color=color.new(color.white, 100))
  1395. line newMidline = line.new(start_bar, sweep_mid, end_bar, sweep_mid,
  1396. color=settings.htf_label_color,
  1397. style=tspot_line_style,
  1398. width=settings.midline_width)
  1399. line newCloseline = show_tspot_close_line ? line.new(start_bar, last_closed.c, end_bar, last_closed.c,
  1400. color=settings.htf_label_color,
  1401. style=tspot_line_style,
  1402. width=settings.midline_width) : na
  1403.  
  1404. if show_silver_tspot
  1405. if (candleOfDay == 5 or (candleOfDay == 4 and hour(time, "America/New_York") >= 13)) and last_closed.c > prev_prev_closed.h and last_closed.c > prev_closed.h
  1406. label.new(bar_index, low, "Silver T-Spot", color=color.new(color.white, 100), textcolor=settings.bull_body, style=label.style_label_up, size=tspot_sweep_label_size, text_font_family=font.family_monospace)
  1407.  
  1408. tspot_boxes.unshift(newBox)
  1409. tspot_midlines.unshift(newMidline)
  1410. if not na(newCloseline)
  1411. tspot_closelines.unshift(newCloseline)
  1412. tspot_created := true
  1413.  
  1414. if tspot_boxes.size() > history_max
  1415. box.delete(tspot_boxes.pop())
  1416. line.delete(tspot_midlines.pop())
  1417. if tspot_closelines.size() > 0
  1418. line.delete(tspot_closelines.pop())
  1419.  
  1420. if not tspot_created and last_closed.h > mid_level and last_closed.h < prev_closed.o and last_closed.c < prev_closed.l and oktspot_bearish_bias and not (last_closed.h > prev_closed.h and last_closed.l < prev_closed.l and last_closed.c > prev_closed.l and last_closed.c < prev_closed.h)
  1421. sweep_mid = calculateLogMidpoint(last_closed.h, last_closed.l, last_closed.o, last_closed.c)
  1422. if last_closed.c < sweep_mid
  1423. box newBox = box.new(start_bar, sweep_mid, end_bar, last_closed.c,
  1424. bgcolor=tspot_bull_box_color,
  1425. border_color=color.new(color.white, 100))
  1426. line newMidline = line.new(start_bar, sweep_mid, end_bar, sweep_mid,
  1427. color=settings.htf_label_color,
  1428. style=tspot_line_style,
  1429. width=settings.midline_width)
  1430. line newCloseline = show_tspot_close_line ? line.new(start_bar, last_closed.c, end_bar, last_closed.c,
  1431. color=settings.htf_label_color,
  1432. style=tspot_line_style,
  1433. width=settings.midline_width) : na
  1434.  
  1435. if show_silver_tspot
  1436. if (candleOfDay == 5 or (candleOfDay == 4 and hour(time, "America/New_York") >= 13)) and last_closed.c < prev_prev_closed.l and last_closed.c < prev_closed.l
  1437. label.new(bar_index, high, "Silver T-Spot", color=color.new(color.white, 100), textcolor=settings.bear_body, style=label.style_label_down, size=tspot_sweep_label_size, text_font_family=font.family_monospace)
  1438.  
  1439. tspot_boxes.unshift(newBox)
  1440. tspot_midlines.unshift(newMidline)
  1441. if not na(newCloseline)
  1442. tspot_closelines.unshift(newCloseline)
  1443. tspot_created := true
  1444.  
  1445. if tspot_boxes.size() > history_max
  1446. box.delete(tspot_boxes.pop())
  1447. line.delete(tspot_midlines.pop())
  1448. if tspot_closelines.size() > 0
  1449. line.delete(tspot_closelines.pop())
  1450.  
  1451. if tspot_created
  1452. while tspot_boxes.size() > history_max
  1453. box.delete(tspot_boxes.pop())
  1454. while tspot_midlines.size() > history_max
  1455. line.delete(tspot_midlines.pop())
  1456. while tspot_closelines.size() > history_max
  1457. line.delete(tspot_closelines.pop())
  1458.  
  1459. while c2_labels.size() > history_max
  1460. label.delete(c2_labels.pop())
  1461. label.delete(c3_labels.pop())
  1462. if ttfm_events.size() > 0
  1463. ttfm_events.pop()
  1464.  
  1465. candleSet
  1466.  
  1467. method Update(CandleSet candleSet, int offset, bool showTrace) =>
  1468. if candleSet.candles.size() > 0
  1469. Candle candle = candleSet.candles.first()
  1470. candle.h_idx := high > candle.h ? bar_index : candle.h_idx
  1471. candle.h := high > candle.h ? high : candle.h
  1472. candle.l_idx := low < candle.l ? bar_index : candle.l_idx
  1473. candle.l := low < candle.l ? low : candle.l
  1474. candle.c := close
  1475. candle.c_idx := bar_index
  1476.  
  1477. bull = candle.c > candle.o
  1478.  
  1479. box.set_top(candle.body, candle.o - candleSet.y_shift)
  1480. box.set_bottom(candle.body, candle.c - candleSet.y_shift)
  1481. box.set_bgcolor(candle.body, bull ? settings.bull_body : settings.bear_body)
  1482. box.set_border_color(candle.body, bull ? settings.bull_border : settings.bear_border)
  1483. line.set_color(candle.wick_up, bull ? settings.bull_wick : settings.bear_wick)
  1484. line.set_color(candle.wick_down, bull ? settings.bull_wick : settings.bear_wick)
  1485. line.set_y1(candle.wick_up, candle.h - candleSet.y_shift)
  1486. line.set_y2(candle.wick_up, math.max(candle.o, candle.c) - candleSet.y_shift)
  1487. line.set_y1(candle.wick_down, candle.l - candleSet.y_shift)
  1488. line.set_y2(candle.wick_down, math.min(candle.o, candle.c) - candleSet.y_shift)
  1489.  
  1490. if barstate.isrealtime or barstate.islast
  1491. candleSet.Reorder(offset)
  1492. candleSet
  1493.  
  1494. resolved_bias := ui_bias
  1495. if ui_bias == "Auto Bias 1" and htf1.candles.size() >= 3
  1496. resolved_bias := helper.GetHTFBias(htf1.candles.get(1), htf1.candles.get(2)) == "Bias: Bullish" ? "Bullish" : (helper.GetHTFBias(htf1.candles.get(1), htf1.candles.get(2)) == "Bias: Bearish" ? "Bearish" : "Neutral")
  1497. else if ui_bias == "Auto Bias 2" and htf2.candles.size() >= 3
  1498. resolved_bias := helper.GetHTFBias(htf2.candles.get(1), htf2.candles.get(2)) == "Bias: Bullish" ? "Bullish" : (helper.GetHTFBias(htf2.candles.get(1), htf2.candles.get(2)) == "Bias: Bearish" ? "Bearish" : "Neutral")
  1499.  
  1500. int cnt = 0
  1501. int last = helper.HTFEnabled()
  1502.  
  1503. pivot_high_open = ta.pivothigh(open, 2, 2)
  1504. pivot_low_open = ta.pivotlow(open, 2, 2)
  1505. pivot_high_close = ta.pivothigh(close, 2, 2)
  1506. pivot_low_close = ta.pivotlow(close, 2, 2)
  1507. pivot_high_high = ta.pivothigh(high, 2, 2)
  1508. pivot_low_low = ta.pivotlow(low, 2, 2)
  1509.  
  1510. pivot_high = usebody_for_confirmation ? not na(pivot_high_open) or not na(pivot_high_close) and not na(pivot_high_high) ? (not na(pivot_high_open) ? pivot_high_open : pivot_high_close) : na : pivot_high_high
  1511. pivot_low = usebody_for_confirmation ? not na(pivot_low_open) or not na(pivot_low_close) and not na(pivot_low_low) ? (not na(pivot_low_open) ? pivot_low_open : pivot_low_close) : na : pivot_low_low
  1512.  
  1513. if not na(pivot_high)
  1514. last_pivot_high := usebody_for_confirmation ? math.max(open[2], close[2]) : pivot_high
  1515. last_pivot_high_bar := bar_index[2]
  1516.  
  1517. if not na(pivot_low)
  1518. last_pivot_low := usebody_for_confirmation ? math.min(open[2], close[2]) : pivot_low
  1519. last_pivot_low_bar := bar_index[2]
  1520.  
  1521. tspot_start_bar = 0
  1522. if tspot_boxes.size() > 0
  1523. latest_tspot = tspot_boxes.get(0)
  1524. latest_midline = tspot_midlines.get(0)
  1525. tspot_top = box.get_top(latest_tspot)
  1526. tspot_bottom = box.get_bottom(latest_tspot)
  1527. tspot_start_bar := box.get_left(latest_tspot)
  1528.  
  1529. if tspot_start_bar != last_tspot_start_bar
  1530. tspot_touched := false
  1531.  
  1532. last_tspot_start_bar := tspot_start_bar
  1533.  
  1534. tspot_midline = line.get_y1(latest_midline)
  1535.  
  1536. tspot_type := tspot_midline >= math.max(tspot_top, tspot_bottom) ? "bearish" : "bullish"
  1537.  
  1538. tspot_touch_level = tspot_type == "bearish" ? math.min(tspot_top, tspot_bottom) : math.max(tspot_top, tspot_bottom)
  1539.  
  1540. if tspot_type == "bearish"
  1541. if (high > tspot_touch_level or open > tspot_touch_level) and close < tspot_touch_level
  1542. tspot_touched := true
  1543. tspot_level := tspot_touch_level
  1544. touch_bar := bar_index
  1545. else
  1546. if (low < tspot_touch_level or open < tspot_touch_level) and close > tspot_touch_level
  1547. tspot_touched := true
  1548. tspot_level := tspot_touch_level
  1549. touch_bar := bar_index
  1550.  
  1551. if tspot_touched and show_tspot_sweeps
  1552. if tspot_type == "bullish" and not na(last_pivot_high) and last_pivot_high_bar < touch_bar and close > last_pivot_high and open < last_pivot_high and last_pivot_high > tspot_level
  1553. lowest_low = low[0]
  1554. for i = 0 to (bar_index - last_pivot_high_bar)
  1555. if low[i] < lowest_low
  1556. lowest_low := low[i]
  1557.  
  1558. if show_confirmation_lines
  1559. if confirmation_lines.size() > 0
  1560. for i = 0 to confirmation_lines.size() - 1
  1561. line.delete(confirmation_lines.get(i))
  1562. array.clear(confirmation_lines)
  1563.  
  1564. color dynamic_conf_color = ui_bull_cisd_col
  1565. int dynamic_conf_width = ui_bull_cisd_wid
  1566. string dynamic_conf_style = ui_bull_cisd_sty == "Dashed" ? line.style_dashed : ui_bull_cisd_sty == "Dotted" ? line.style_dotted : line.style_solid
  1567.  
  1568. new_confirmation_line = line.new(last_pivot_high_bar, last_pivot_high, bar_index, last_pivot_high, color=dynamic_conf_color, width=dynamic_conf_width, style=dynamic_conf_style)
  1569. array.push(confirmation_lines, new_confirmation_line)
  1570.  
  1571. tspot_touched := false
  1572.  
  1573. if tspot_type == "bearish" and not na(last_pivot_low) and last_pivot_low_bar < touch_bar and close < last_pivot_low and open > last_pivot_low and last_pivot_low < tspot_level
  1574. highest_high = high[0]
  1575. for i = 0 to (bar_index - last_pivot_low_bar)
  1576. if high[i] > highest_high
  1577. highest_high := high[i]
  1578.  
  1579. if show_confirmation_lines
  1580. if confirmation_lines.size() > 0
  1581. for i = 0 to confirmation_lines.size() - 1
  1582. line.delete(confirmation_lines.get(i))
  1583. array.clear(confirmation_lines)
  1584.  
  1585. color dynamic_conf_color = ui_bear_cisd_col
  1586. int dynamic_conf_width = ui_bear_cisd_wid
  1587. string dynamic_conf_style = ui_bear_cisd_sty == "Dashed" ? line.style_dashed : ui_bear_cisd_sty == "Dotted" ? line.style_dotted : line.style_solid
  1588.  
  1589. new_confirmation_line = line.new(last_pivot_low_bar, last_pivot_low, bar_index, last_pivot_low, color=dynamic_conf_color, width=dynamic_conf_width, style=dynamic_conf_style)
  1590. array.push(confirmation_lines, new_confirmation_line)
  1591.  
  1592. tspot_touched := false
  1593.  
  1594. if hide_against_tspots and tspot_boxes.size() > 0
  1595. for i = 0 to tspot_boxes.size() - 1
  1596. current_box = tspot_boxes.get(i)
  1597. current_midline = tspot_midlines.get(i)
  1598. current_closeline = i < tspot_closelines.size() ? tspot_closelines.get(i) : na
  1599. box_top = box.get_top(current_box)
  1600. box_bottom = box.get_bottom(current_box)
  1601. midline_price = line.get_y1(current_midline)
  1602.  
  1603. if box_top > box_bottom and close > midline_price
  1604. box.set_bgcolor(current_box, color.new(color.white, 100))
  1605. box.set_border_color(current_box, color.new(color.white, 100))
  1606. line.set_color(current_midline, color.new(settings.htf_label_color, 100))
  1607. if not na(current_closeline)
  1608. line.set_color(current_closeline, color.new(settings.htf_label_color, 100))
  1609.  
  1610. else if box_bottom > box_top and close < midline_price
  1611. box.set_bgcolor(current_box, color.new(color.white, 100))
  1612. box.set_border_color(current_box, color.new(color.white, 100))
  1613. line.set_color(current_midline, color.new(settings.htf_label_color, 100))
  1614. if not na(current_closeline)
  1615. line.set_color(current_closeline, color.new(settings.htf_label_color, 100))
  1616.  
  1617. else
  1618. if box_top > box_bottom
  1619. box.set_bgcolor(current_box, tspot_bear_box_color)
  1620. box.set_border_color(current_box, color.new(color.white, 100))
  1621. line.set_color(current_midline, settings.htf_label_color)
  1622. if not na(current_closeline)
  1623. line.set_color(current_closeline, settings.htf_label_color)
  1624. else
  1625. box.set_bgcolor(current_box, tspot_bull_box_color)
  1626. box.set_border_color(current_box, color.new(color.white, 100))
  1627. line.set_color(current_midline, settings.htf_label_color)
  1628. if not na(current_closeline)
  1629. line.set_color(current_closeline, settings.htf_label_color)
  1630.  
  1631. if delete_against_tspots and tspot_boxes.size() > 1
  1632. bool[] bearish_traded_against = array.new<bool>(tspot_boxes.size(), false)
  1633. bool[] bullish_traded_against = array.new<bool>(tspot_boxes.size(), false)
  1634.  
  1635. for i = 0 to tspot_boxes.size() - 1
  1636. current_box = tspot_boxes.get(i)
  1637. current_midline = tspot_midlines.get(i)
  1638. box_top = box.get_top(current_box)
  1639. box_bottom = box.get_bottom(current_box)
  1640. midline_price = line.get_y1(current_midline)
  1641.  
  1642. if box_top > box_bottom
  1643. traded_against = false
  1644. for j = 0 to 100
  1645. if bar_index - j >= box.get_left(current_box)
  1646. if close[j] > midline_price
  1647. traded_against := true
  1648. break
  1649. array.set(bearish_traded_against, i, traded_against)
  1650.  
  1651. else if box_bottom > box_top
  1652. traded_against = false
  1653. for j = 0 to 100
  1654. if bar_index - j >= box.get_left(current_box)
  1655. if close[j] < midline_price
  1656. traded_against := true
  1657. break
  1658. array.set(bullish_traded_against, i, traded_against)
  1659.  
  1660. latest_bearish_index = -1
  1661. latest_bullish_index = -1
  1662.  
  1663. for i = 0 to tspot_boxes.size() - 1
  1664. current_box = tspot_boxes.get(i)
  1665. box_top = box.get_top(current_box)
  1666. box_bottom = box.get_bottom(current_box)
  1667.  
  1668. if box_top > box_bottom
  1669. if latest_bearish_index == -1 or box.get_left(tspot_boxes.get(latest_bearish_index)) < box.get_left(current_box)
  1670. latest_bearish_index := i
  1671. else if box_bottom > box_top
  1672. if latest_bullish_index == -1 or box.get_left(tspot_boxes.get(latest_bullish_index)) < box.get_left(current_box)
  1673. latest_bullish_index := i
  1674.  
  1675. for i = tspot_boxes.size() - 1 to 0
  1676. current_box = tspot_boxes.get(i)
  1677. box_top = box.get_top(current_box)
  1678. box_bottom = box.get_bottom(current_box)
  1679.  
  1680. should_delete = false
  1681.  
  1682. if box_top > box_bottom
  1683. if i != latest_bearish_index and array.get(bearish_traded_against, i)
  1684. should_delete := true
  1685. else if box_bottom > box_top
  1686. if i != latest_bullish_index and array.get(bullish_traded_against, i)
  1687. should_delete := true
  1688.  
  1689. if should_delete
  1690. box.delete(tspot_boxes.get(i))
  1691. line.delete(tspot_midlines.get(i))
  1692. if i < tspot_closelines.size()
  1693. line.delete(tspot_closelines.get(i))
  1694.  
  1695. array.remove(tspot_boxes, i)
  1696. array.remove(tspot_midlines, i)
  1697. if i < tspot_closelines.size()
  1698. array.remove(tspot_closelines, i)
  1699. array.remove(bearish_traded_against, i)
  1700. array.remove(bullish_traded_against, i)
  1701.  
  1702. newPeriod_smt = timeframe.change(h1)
  1703.  
  1704. if enableSMT and bar_index > last_bar_index - 4500 and h1 != ""
  1705. sPair = smtAutoMode ? getSMTPair() : str.tostring(smtManualPair)
  1706. if sPair != ""
  1707. [sH_htf, sL_htf, sH1_htf, sL1_htf] = request.security(sPair, h1, [high, low, high[1], low[1]], lookahead = barmerge.lookahead_off)
  1708. [sH_piv, sL_piv] = request.security(sPair, timeframe.period, [high[3], low[3]], lookahead = barmerge.lookahead_off)
  1709.  
  1710. chartPivDir = not na(ta.pivothigh(3, 3)) ? 1 : not na(ta.pivotlow(3, 3)) ? -1 : 0
  1711.  
  1712. [htfClose, htfOpen, htfHigh, htfLow, htfHigh1, htfLow1] = request.security(syminfo.tickerid, h1, [close, open, high, low, high[1], low[1]], lookahead = barmerge.lookahead_off)
  1713.  
  1714. bearD_htf = (not na(htfClose) and htfClose < htfOpen) and htfHigh < htfHigh1 and sH_htf > sH1_htf
  1715. bullD_htf = (not na(htfClose) and htfClose > htfOpen) and htfLow > htfLow1 and sL_htf < sL1_htf
  1716.  
  1717. if high >= currCH_smt or na(currCH_smt)
  1718. currCH_smt := high, currCHT_smt := time
  1719. if low <= currCL_smt or na(currCL_smt)
  1720. currCL_smt := low, currCLT_smt := time
  1721.  
  1722. if newPeriod_smt
  1723. if bearD_htf[1]
  1724. smtArray.push(SMT.new("BEARISH", sPair, prevCH_smt, currCH_smt, prevCHT_smt, currCHT_smt, na, na, na, na, true, bar_index, na, na))
  1725. if bullD_htf[1]
  1726. smtArray.push(SMT.new("BULLISH", sPair, na, na, na, na, prevCL_smt, currCL_smt, prevCLT_smt, currCLT_smt, true, bar_index, na, na))
  1727. prevCH_smt := currCH_smt, prevCHT_smt := currCHT_smt
  1728. prevCL_smt := currCL_smt, prevCLT_smt := currCLT_smt
  1729. currCH_smt := high, currCHT_smt := time
  1730. currCL_smt := low, currCLT_smt := time
  1731. line.delete(liveBearSmtL), liveBearSmtL := na
  1732. line.delete(liveBullSmtL), liveBullSmtL := na
  1733.  
  1734. if chartPivDir == 1
  1735. if not na(chartPivotHigh)
  1736. prevChartPivotHigh := chartPivotHigh
  1737. prevChartPivotHighTime := chartPivotHighTime
  1738. chartPivotHigh := high[3], chartPivotHighTime := time[3]
  1739.  
  1740. if not na(smtPivotHigh)
  1741. prevSmtPivotHigh := smtPivotHigh
  1742. smtPivotHigh := sH_piv
  1743.  
  1744. if not na(prevChartPivotHigh) and chartPivotHigh > prevChartPivotHigh and smtPivotHigh < prevSmtPivotHigh
  1745. smtArray.push(SMT.new("BEARISH", sPair, prevChartPivotHigh, chartPivotHigh, prevChartPivotHighTime, chartPivotHighTime, na, na, na, na, true, bar_index, na, na))
  1746.  
  1747. if chartPivDir == -1
  1748. if not na(chartPivotLow)
  1749. prevChartPivotLow := chartPivotLow
  1750. prevChartPivotLowTime := chartPivotLowTime
  1751. chartPivotLow := low[3], chartPivotLowTime := time[3]
  1752.  
  1753. if not na(smtPivotLow)
  1754. prevSmtPivotLow := smtPivotLow
  1755. smtPivotLow := sL_piv
  1756.  
  1757. if not na(prevChartPivotLow) and chartPivotLow < prevChartPivotLow and smtPivotLow > prevSmtPivotLow
  1758. smtArray.push(SMT.new("BULLISH", sPair, na, na, na, na, prevChartPivotLow, chartPivotLow, prevChartPivotLowTime, chartPivotLowTime, true, bar_index, na, na))
  1759.  
  1760. int htf_offset = settings.offset
  1761.  
  1762. if (barstate.isrealtime or barstate.islast) and ttfm_events.size() > 0
  1763. for i = 0 to ttfm_events.size() - 1
  1764. TTFMEvent ev = ttfm_events.get(i)
  1765. if not ev.failed
  1766. bool just_failed = ev.is_bullish ? close < ev.invalid_level : close > ev.invalid_level
  1767. if just_failed
  1768. ev.failed := true
  1769.  
  1770. box.delete(ev.tspot_bx)
  1771. line.delete(ev.tspot_ml)
  1772. if i == 0
  1773. if array.size(projection_lines) > 0
  1774. for ln in projection_lines
  1775. line.delete(ln)
  1776. array.clear(projection_lines)
  1777. if array.size(projection_labels) > 0
  1778. for lbl in projection_labels
  1779. label.delete(lbl)
  1780. array.clear(projection_labels)
  1781. if array.size(protected_swing_labels) > 0
  1782. label.delete(array.shift(protected_swing_labels))
  1783. else if (bar_index - ev.created_bar) >= math.max(ev.formation_bars, 1)
  1784. ev.consolidating := true
  1785. color state_color = ev.failed ? color.red : ev.consolidating ? color.orange : color.gray
  1786. if not na(ev.c2_lbl)
  1787. label.set_textcolor(ev.c2_lbl, state_color)
  1788. if not na(ev.c3_lbl)
  1789. label.set_textcolor(ev.c3_lbl, state_color)
  1790.  
  1791. if array.size(active_liq_lines) > 0
  1792. for i = array.size(active_liq_lines) - 1 to 0
  1793. LiquidityLine ll = array.get(active_liq_lines, i)
  1794. if ll.active
  1795. line.set_x2(ll.ln, bar_index)
  1796. bool touched = false
  1797. if ll.is_bullish
  1798. if high >= ll.level and bar_index > ll.start_bar
  1799. touched := true
  1800. else
  1801. if low <= ll.level and bar_index > ll.start_bar
  1802. touched := true
  1803. if touched
  1804. ll.active := false
  1805. line.delete(ll.ln)
  1806. array.remove(active_liq_lines, i)
  1807.  
  1808. if barstate.isrealtime or barstate.islast
  1809. while midpoint_lines.size() > 0
  1810. line.delete(midpoint_lines.pop())
  1811. while sweep_lines.size() > 0
  1812. line.delete(sweep_lines.pop())
  1813.  
  1814. chart_range = ta.highest(high, 200) - ta.lowest(low, 200)
  1815. shift_amount = chart_range * vertical_gap_mult
  1816.  
  1817. htf1.y_shift := 0.0
  1818. htf2.y_shift := layout_mode == "Vertical Stacked (Same Offset)" ? shift_amount : 0.0
  1819. htf3.y_shift := layout_mode == "Vertical Stacked (Same Offset)" ? shift_amount * 2 : 0.0
  1820.  
  1821. if htf1.settings.show and helper.ValidTimeframe(htf1.settings.htf) and bar_index > last_bar_index - 1000
  1822. bool showTrace = settings.trace_anchor == "First Timeframe"
  1823. htf1.Monitor(true).Update(htf_offset, showTrace).FindImbalance(true, ui_c1_sweep_en)
  1824.  
  1825. if htf_lines.size() > 0 and htf1.candles.size() > 0
  1826. float visual_offset = label_atr * htf_line_extension
  1827. float current_htf_high = htf1.candles.first().h + visual_offset
  1828. float current_htf_low = htf1.candles.first().l - visual_offset
  1829.  
  1830. line.set_y1(htf_lines.get(0), current_htf_high)
  1831. line.set_y2(htf_lines.get(0), current_htf_low)
  1832.  
  1833. if htf_labels.size() > 0
  1834. label.set_y(htf_labels.get(0), current_htf_high)
  1835. if htf_labels_bottom.size() > 0
  1836. label.set_y(htf_labels_bottom.get(0), current_htf_low)
  1837.  
  1838. cnt += 1
  1839. if layout_mode == "Vertical Stacked (Same Offset)"
  1840. htf_offset := settings.offset
  1841. else
  1842. htf_offset += (htf1.candles.size() * settings.width) + (htf1.candles.size() > 0 ? (htf1.candles.size()-1) * settings.buffer : 0) + settings.htf_buffer
  1843.  
  1844. if htf2.settings.show and helper.ValidTimeframe(htf2.settings.htf) and cnt < last
  1845. htf2.Monitor(false).Update(htf_offset, false).FindImbalance(false, ui_c1_sweep_en)
  1846. cnt += 1
  1847. if layout_mode == "Vertical Stacked (Same Offset)"
  1848. htf_offset := settings.offset
  1849. else
  1850. htf_offset += (htf2.candles.size() * settings.width) + (htf2.candles.size() > 0 ? (htf2.candles.size()-1) * settings.buffer : 0) + settings.htf_buffer
  1851.  
  1852. if htf3.settings.show and helper.ValidTimeframe(htf3.settings.htf) and cnt < last
  1853. htf3.Monitor(false).Update(htf_offset, false).FindImbalance(false, ui_c1_sweep_en)
  1854. cnt += 1
  1855. if layout_mode == "Vertical Stacked (Same Offset)"
  1856. htf_offset := settings.offset
  1857. else
  1858. htf_offset += (htf3.candles.size() * settings.width) + (htf3.candles.size() > 0 ? (htf3.candles.size()-1) * settings.buffer : 0) + settings.htf_buffer
  1859.  
  1860. if show_info_table and htf1.candles.size() > 0 and (barstate.islast or barstate.isrealtime)
  1861. title_text = helper.GetCurrentTimeframe() + "-" + helper.HTFName(htf1.settings.htf) + " Model"
  1862. timer_text = helper.RemainingTime(htf1.settings.htf)
  1863. asset_text = syminfo.ticker
  1864. chart_tf_text = helper.GetCurrentTimeframe()
  1865.  
  1866. bias_text = "Bias: Neutral"
  1867. if htf1.candles.size() >= 3
  1868. last_closed = htf1.candles.get(1)
  1869. prev_closed = htf1.candles.get(2)
  1870. bias_text := helper.GetHTFBias(last_closed, prev_closed)
  1871.  
  1872. filter_text = "All Day"
  1873. if ui_filter1_en or ui_filter2_en or ui_filter3_en
  1874. string ft = ""
  1875. if ui_filter1_en
  1876. ft := ft + ui_filter1_time
  1877. if ui_filter2_en
  1878. ft := ft + (ft == "" ? "" : ", ") + ui_filter2_time
  1879. if ui_filter3_en
  1880. ft := ft + (ft == "" ? "" : ", ") + ui_filter3_time
  1881. filter_text := ft
  1882.  
  1883. int table_rows = (ui_tbl_frc_en ? 1 : 0) + (ui_tbl_ast_en ? 1 : 0) + (ui_tbl_ch_en ? 1 : 0) + (ui_tbl_ttc_en ? 1 : 0) + (ui_tbl_bias_en ? 1 : 0) + (ui_tbl_tf_en ? 1 : 0)
  1884. table_rows := math.max(table_rows, 1)
  1885.  
  1886. if na(info_table) or current_table_rows != table_rows
  1887. if not na(info_table)
  1888. table.delete(info_table)
  1889. info_table := table.new(helper.GetTablePosition(table_position), 1, table_rows,
  1890. bgcolor=table_bg_color,
  1891. border_width=table_border_width,
  1892. border_color=table_border_color,
  1893. frame_width=table_frame_width,
  1894. frame_color=table_frame_color)
  1895. current_table_rows := table_rows
  1896.  
  1897. int row = 0
  1898. if ui_tbl_frc_en
  1899. table.cell(info_table, 0, row, title_text, text_color=table_text_color, text_size=info_text_size, text_font_family=font.family_monospace, bgcolor=table_bg_color)
  1900. row += 1
  1901. if ui_tbl_ast_en
  1902. table.cell(info_table, 0, row, asset_text, text_color=table_text_color, text_size=info_text_size, text_font_family=font.family_monospace, bgcolor=table_bg_color)
  1903. row += 1
  1904. if ui_tbl_ch_en
  1905. table.cell(info_table, 0, row, chart_tf_text, text_color=table_text_color, text_size=info_text_size, text_font_family=font.family_monospace, bgcolor=table_bg_color)
  1906. row += 1
  1907. if ui_tbl_ttc_en
  1908. table.cell(info_table, 0, row, timer_text, text_color=table_text_color, text_size=info_text_size, text_font_family=font.family_monospace, bgcolor=table_bg_color)
  1909. row += 1
  1910. if ui_tbl_bias_en
  1911. table.cell(info_table, 0, row, bias_text, text_color=table_text_color, text_size=info_text_size, text_font_family=font.family_monospace, bgcolor=table_bg_color)
  1912. row += 1
  1913. if ui_tbl_tf_en
  1914. table.cell(info_table, 0, row, filter_text, text_color=table_text_color, text_size=info_text_size, text_font_family=font.family_monospace, bgcolor=table_bg_color)
  1915. row += 1
  1916.  
  1917. if enableSMT and bar_index > last_bar_index - 4500
  1918. if smtKeepOnlyLatest and array.size(smtArray) > 0
  1919. int latestBearIdx = -1
  1920. int latestBullIdx = -1
  1921. int maxBearBar = -1
  1922. int maxBullBar = -1
  1923.  
  1924. for i = 0 to array.size(smtArray) - 1
  1925. s_check = array.get(smtArray, i)
  1926. if s_check.smtType == "BEARISH" and s_check.creationBar > maxBearBar
  1927. maxBearBar := s_check.creationBar
  1928. latestBearIdx := i
  1929. else if s_check.smtType == "BULLISH" and s_check.creationBar > maxBullBar
  1930. maxBullBar := s_check.creationBar
  1931. latestBullIdx := i
  1932.  
  1933. for i = array.size(smtArray) - 1 to 0
  1934. if (array.get(smtArray, i).smtType == "BEARISH" and i != latestBearIdx) or (array.get(smtArray, i).smtType == "BULLISH" and i != latestBullIdx)
  1935. s_del = array.remove(smtArray, i)
  1936. line.delete(s_del.smtLine)
  1937.  
  1938. if barstate.islast or barstate.isrealtime
  1939. int szL = array.size(smtLabels)
  1940. if szL > 0
  1941. for i = 0 to szL - 1
  1942. label.delete(array.get(smtLabels, i))
  1943. array.clear(smtLabels)
  1944.  
  1945. int szA = array.size(smtArray)
  1946. if szA > 0
  1947. for i = szA - 1 to 0
  1948. s = array.get(smtArray, i)
  1949. if bar_index - s.creationBar > 2500
  1950. line.delete(s.smtLine)
  1951. array.remove(smtArray, i)
  1952. continue
  1953.  
  1954. isB = s.smtType == "BEARISH"
  1955. c = smtColor
  1956.  
  1957. p1T = isB ? s.prevChartHighTime : s.prevChartLowTime
  1958. p1P = isB ? s.prevChartHigh : s.prevChartLow
  1959. p2T = isB ? s.currChartHighTime : s.currChartLowTime
  1960. p2P = isB ? s.currChartHigh : s.currChartLow
  1961.  
  1962. if not na(p1T) and not na(p2T)
  1963. if na(s.smtLine)
  1964. s.smtLine := line.new(p1T, p1P, p2T, p2P, xloc=xloc.bar_time, color=c, width=smtLineWidth)
  1965. else
  1966. line.set_xy1(s.smtLine, p1T, p1P)
  1967. line.set_xy2(s.smtLine, p2T, p2P)
  1968. line.set_color(s.smtLine, c)
  1969.  
  1970. if smtShowLabel
  1971. string cleanName = s.smtPair
  1972. if str.contains(cleanName, ":")
  1973. cleanName := array.get(str.split(cleanName, ":"), array.size(str.split(cleanName, ":")) - 1)
  1974. cleanName := str.replace_all(cleanName, ".P", ""), cleanName := str.replace_all(cleanName, "1!", "")
  1975.  
  1976. labelStyle = isB ? label.style_label_down : label.style_label_up
  1977.  
  1978. newL = label.new((p1T+p2T)/2, (p1P+p2P)/2, cleanName,
  1979. color=color.new(color.white, 100),
  1980. textcolor=c,
  1981. style=labelStyle,
  1982. size=size.small,
  1983. xloc=xloc.bar_time)
  1984. array.push(smtLabels, newL)
Advertisement
Comments
  • potent123
    30 days
    # text 0.10 KB | 0 0
    1. PLEASE WHICH TIMEZONE THAT IS USED IN THE FACTAL MODEL PRO+ ABOVE.IS IT NEW YORK TIMEZONE -4 OR WHAT
Add Comment
Please, Sign In to add comment