safwan092

Untitled

Aug 11th, 2025
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 74.80 KB | None | 0 0
  1. //@version=5
  2.  
  3. //text inputs
  4. textVPosition = 'middle'
  5. textHPosition = 'center'
  6. symVPosition = 'top'
  7. symHPosition = 'left'
  8. width = 0
  9. height = 0
  10. c_title = #b2b5be80
  11. s_title = 'large'
  12. a_title = 'center'
  13. c_subtitle = #b2b5be80
  14. s_subtitle = 'normal'
  15. a_subtitle = 'center'
  16. c_bg = color.new(color.blue, 100)
  17.  
  18. indicator("Lux Algo Signals & Overlays [6.3]", "Lux Algo Signals & Overlays [6.3]", overlay = true, max_labels_count = 500)
  19. //import Libraries
  20. //Import libraries
  21. import ayvaliktrading/EyopsTelegram/1 as LAF
  22. import ayvaliktrading/JoinUsEyopsTelegram/1 as kernels
  23.  
  24. // # ============================[GET USERS INPUT]============================ #
  25. groupBasic = "BASIC SETTINGS"
  26. showSignals = input(true, "Show Signals", inline = "1", group = groupBasic, tooltip = "Enables or disables the signals")
  27. signalPresets = input.string("None", "Presets / Filters", ["None", "Trend Trader [Preset]","Scalper [Preset]", "Swing Trader [Preset]", "Contrarian Trader [Preset]", "Smart Trail [Filter]", "Trend Tracer [Filter]", "Trend Strength [Filter]", "Trend Catcher [Filter]", "Neo Cloud [Filter]"],tooltip = "Automatically sets settings or filters for a given category", group= groupBasic)
  28. signalMode = input.string("Confirmation + Exits", "Signal Mode", ["Confirmation + Exits", "Contrarian + Exits", "None"],tooltip = "Changes the Mode of the signals" ,group = groupBasic)
  29. signalClassifier = input(true,"AI Signal Classifer",tooltip = "Shows signal quality from 1-4 on signals" ,group = groupBasic)
  30. sensitivity = input.float(5, "Signal Sensitivity ", minval = 1, maxval = 26,step=0.1, tooltip = "Changes the sensetivity of the signals, the lower this setting the more short term signals you will get, while a higher number will result in longer term signals.",group = groupBasic)
  31. atrLength = input.int(10, "Signal Tuner ", minval = 1, maxval = 25,step=1,tooltip = "Alows you to tune your signals, the higher the number the more refined but laggier the signal" ,group = groupBasic)
  32. candleColorType = input.string("Confirmation Simple", "Candle Coloring", ["Confirmation Simple","Confirmation Gradient","Contrarian Gradient","None"],tooltip = "Changes the type of signal coloring", group = groupBasic)
  33.  
  34. // Indicator Overlay Settings
  35. groupOverlay = "INDICATOR OVERLAY"
  36. smartTrail = input(true, "Smart Trail", inline = "1", group = groupOverlay)
  37. trendCatcher = input(false, "Trend Catcher", inline = "2", group = groupOverlay)
  38. neoCloud = input(false, "Neo Cloud", inline = "3", group = groupOverlay)
  39. reversalZone = input(true, "Reversal Zones", inline = "1", group = groupOverlay)
  40. trendTracer = input(false, "Trend Tracer", inline = "2", group = groupOverlay)
  41. showDashboard = input(true, "Dashboard", inline = "3", group = groupOverlay)
  42. showTrailingStoploss = input(false, "Trailing Stoploss", inline = "4", group = groupOverlay)
  43. showMovingAverage = input(false, "AI Moving Average", inline = "4", group = groupOverlay)
  44. showSessions = input(false, "Sessions", inline = "5", group = groupOverlay)
  45.  
  46. // Advanced Settings
  47. groupAdvanced = "ADVANCED SETTINGS"
  48. takeProfitBoxes = input.string("Off", "TP/SL Points", options=["Off","On"], inline = "2", tooltip = "Shows Take Profit and Stop Loss areas",group = groupAdvanced)
  49. takeProfitStopLossDistance = input.int(5,"", minval = 1, maxval = 10, inline = "2", group=groupAdvanced)
  50. autopilotMode = input.string("Off", "Autopilot Sensivity",["Off","Short-Term", "Mid-Term", "Long-Term"],tooltip = "Sets automatic settings for signals and improves their quality" ,inline = "3", group = groupAdvanced)
  51. dashboardLocation = input.string("Bottom Right","Dashboard Location", ["Top Right","Bottom Right","Bottom Left"], inline = "4",tooltip = "Changes dashboard positions" ,group = groupAdvanced)
  52. dashboardSize = input.string("Normal","Dashboard Size", ["Tiny","Small","Normal","Large"], inline = "5",tooltip = "Changes the size of the dashboard" ,group = groupAdvanced)
  53.  
  54. if (signalPresets == "Trend Trader [Preset]")
  55. smartTrail := true
  56. trendCatcher := true
  57. neoCloud := true
  58. trendTracer := true
  59. smartTrail := true
  60. if (signalPresets == "Scalper [Preset]")
  61. sensitivity := 4
  62. smartTrail := true
  63. trendTracer := true
  64. candleColorType := "Confirmation Gradient"
  65. if (signalPresets == "Swing Trader [Preset]")
  66. sensitivity := 18
  67. neoCloud := true
  68. candleColorType := "Confirmation Simple"
  69. if (signalPresets == "Contrarian Trader [Preset]")
  70. reversalZone := true
  71. smartTrail := true
  72. candleColorType := "Contrarian Gradient"
  73.  
  74.  
  75. n = bar_index
  76.  
  77.  
  78.  
  79. // # ============================[BUY/SELL SIGNALS]============================ #
  80. //------------------------------------------------------------------------------
  81. //Settings
  82. //-----------------------------------------------------------------------------{
  83. //-----------------------------------------------------------------------------}
  84.  
  85. // # ============================[SESSIONS]============================ #
  86. show_sesa = true
  87. sesa_txt = 'New York'
  88. sesa_ses = '1300-2200'
  89. sesa_css = #ff5d00
  90.  
  91. sesa_range = true
  92. sesa_tl = false
  93. sesa_avg = false
  94. sesa_vwap = false
  95. sesa_maxmin = false
  96.  
  97. //Session B
  98. show_sesb = true
  99. sesb_txt = 'London'
  100. sesb_ses = '0700-1600'
  101. sesb_css = #2157f3
  102.  
  103. sesb_range = true
  104. sesb_tl = false
  105. sesb_avg = false
  106. sesb_vwap = false
  107. sesb_maxmin = false
  108.  
  109.  
  110.  
  111. //Timezones
  112. tz_incr = 0
  113. use_exchange = false
  114.  
  115. //Ranges Options
  116. bg_transp = 90
  117. show_outline = true
  118. show_txt = true
  119.  
  120. //Dashboard
  121. show_ses_div = false
  122. show_day_div = false
  123.  
  124. //-----------------------------------------------------------------------------}
  125. //Functions
  126. //-----------------------------------------------------------------------------{
  127.  
  128. //Get session average
  129. get_avg(session)=>
  130. var len = 1
  131. var float csma = na
  132. var float sma = na
  133.  
  134. if session > session[1]
  135. len := 1
  136. csma := close
  137.  
  138. if session and session == session[1] and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  139. len += 1
  140. csma += close
  141. sma := csma / len
  142.  
  143. sma
  144.  
  145. //Get trendline coordinates
  146. get_linreg(session)=>
  147. var len = 1
  148. var float cwma = na
  149. var float csma = na
  150. var float csma2 = na
  151.  
  152. var float y1 = na
  153. var float y2 = na
  154. var float stdev = na
  155. var float r2 = na
  156.  
  157. if session > session[1]
  158. len := 1
  159. cwma := close
  160. csma := close
  161. csma2 := close * close
  162.  
  163. if session and session == session[1] and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  164. len += 1
  165. csma += close
  166. csma2 += close * close
  167. cwma += close * len
  168.  
  169. sma = csma / len
  170. wma = cwma / (len * (len + 1) / 2)
  171.  
  172. cov = (wma - sma) * (len+1)/2
  173. stdev := math.sqrt(csma2 / len - sma * sma)
  174. r2 := cov / (stdev * (math.sqrt(len*len - 1) / (2 * math.sqrt(3))))
  175.  
  176. y1 := 4 * sma - 3 * wma
  177. y2 := 3 * wma - 2 * sma
  178.  
  179. [y1 , y2, stdev, r2]
  180.  
  181. //Session Vwap
  182. get_vwap(session) =>
  183. var float num = na
  184. var float den = na
  185.  
  186. if session > session[1] and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  187. num := close * volume
  188. den := volume
  189.  
  190. else if session and session == session[1] and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  191. num += close * volume
  192. den += volume
  193. else
  194. num := na
  195.  
  196. [num, den]
  197.  
  198. //Set line
  199. set_line(session, y1, y2, session_css)=>
  200. var line tl = na
  201.  
  202. if session > session[1] and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  203. tl := line.new(n, close, n, close, color = session_css)
  204.  
  205. if session and session == session[1] and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  206. line.set_y1(tl, y1)
  207. line.set_xy2(tl, n, y2)
  208.  
  209. //Set session range
  210. get_range(session, session_name, session_css)=>
  211. var t = 0
  212. var max = high
  213. var min = low
  214. var box bx = na
  215. var label lbl = na
  216.  
  217. if session > session[1] and showSessions and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  218. t := time
  219. max := high
  220. min := low
  221.  
  222. bx := box.new(n, max, n, min
  223. , bgcolor = color.new(session_css, bg_transp)
  224. , border_color = show_outline ? session_css : na
  225. , border_style = line.style_dotted)
  226.  
  227. if show_txt and showSessions and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  228. lbl := label.new(t, max, session_name
  229. , xloc = xloc.bar_time
  230. , textcolor = session_css
  231. , style = label.style_label_down
  232. , color = color.new(color.white, 100)
  233. , size = size.tiny)
  234.  
  235. if session and session == session[1] and showSessions and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  236. max := math.max(high, max)
  237. min := math.min(low, min)
  238.  
  239. box.set_top(bx, max)
  240. box.set_rightbottom(bx, n, min)
  241.  
  242. if show_txt
  243. label.set_xy(lbl, int(math.avg(t, time)), max)
  244.  
  245. [session ? na : max, session ? na : min]
  246.  
  247. //-----------------------------------------------------------------------------}
  248. //Sessions
  249. //-----------------------------------------------------------------------------{
  250. tf = timeframe.period
  251.  
  252. var tz = use_exchange ? syminfo.timezone :
  253. str.format('UTC{0}{1}', tz_incr >= 0 ? '+' : '-', math.abs(tz_incr))
  254.  
  255. is_sesa = math.sign(nz(time(tf, sesa_ses, tz)))
  256. is_sesb = math.sign(nz(time(tf, sesb_ses, tz)))
  257.  
  258. //-----------------------------------------------------------------------------}
  259. //Dashboard
  260. //-----------------------------------------------------------------------------{
  261.  
  262. var float max_sesa = na
  263. var float min_sesa = na
  264. var float max_sesb = na
  265. var float min_sesb = na
  266. var float max_sesc = na
  267. var float min_sesc = na
  268. var float max_sesd = na
  269. var float min_sesd = na
  270.  
  271. //Ranges
  272. if show_sesa and sesa_range and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  273. [max, min] = get_range(is_sesa, sesa_txt, sesa_css)
  274. max_sesa := max
  275. min_sesa := min
  276.  
  277. if show_sesb and sesb_range and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  278. [max, min] = get_range(is_sesb, sesb_txt, sesb_css)
  279. max_sesb := max
  280. min_sesb := min
  281.  
  282. //Trendlines
  283. //Mean
  284. if show_sesa and sesa_avg and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  285. avg = get_avg(is_sesa)
  286. set_line(is_sesa, avg, avg, sesa_css)
  287.  
  288. if show_sesb and sesb_avg and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  289. avg = get_avg(is_sesb)
  290. set_line(is_sesb, avg, avg, sesb_css)
  291.  
  292. //VWAP
  293. //-----------------------------------------------------------------------------}
  294. //Plots
  295. //-----------------------------------------------------------------------------{
  296. //Plot max/min
  297. plot(showSessions and sesa_maxmin and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? max_sesa : na, 'Session A Maximum', sesa_css, 1, plot.style_linebr, editable = false)
  298. plot(showSessions and sesa_maxmin and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? min_sesa : na, 'Session A Minimum', sesa_css, 1, plot.style_linebr, editable = false)
  299.  
  300. plot(showSessions and sesb_maxmin and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? max_sesb : na, 'Session B Maximum', sesb_css, 1, plot.style_linebr, editable = false)
  301. plot(showSessions and sesb_maxmin and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? min_sesb : na, 'Session B Minimum', sesb_css, 1, plot.style_linebr, editable = false)
  302.  
  303. //Plot Divider A
  304. plotshape(is_sesa and show_ses_div and show_sesa and showSessions, "Β·"
  305. , shape.square
  306. , location.bottom
  307. , na
  308. , text = "."
  309. , textcolor = sesa_css
  310. , size = size.tiny
  311. , display = display.all - display.status_line
  312. , editable = false)
  313.  
  314. plotshape(is_sesa != is_sesa[1] and show_ses_div and show_sesa and showSessions, "NYE"
  315. , shape.labelup
  316. , location.bottom
  317. , na
  318. , text = "❚"
  319. , textcolor = sesa_css
  320. , size = size.tiny
  321. , display = display.all - display.status_line
  322. , editable = false)
  323.  
  324. //Plot Divider B
  325. plotshape(is_sesb and show_ses_div and show_sesb and showSessions, "Β·"
  326. , shape.labelup
  327. , location.bottom
  328. , na
  329. , text = "."
  330. , textcolor = sesb_css
  331. , size = size.tiny
  332. , display = display.all - display.status_line
  333. , editable = false)
  334.  
  335. plotshape(is_sesb != is_sesb[1] and show_ses_div and show_sesb and showSessions, "LDN"
  336. , shape.labelup
  337. , location.bottom
  338. , na
  339. , text = "❚"
  340. , textcolor = sesb_css
  341. , size = size.tiny
  342. , display = display.all - display.status_line
  343. , editable = false)
  344.  
  345.  
  346. // # ============================[FUNCTIONS]============================ #
  347.  
  348.  
  349. type bar
  350. float o = open
  351. float h = high
  352. float l = low
  353. float c = close
  354. float v = volume
  355. int i = bar_index
  356.  
  357. bar b = bar.new()
  358. nzV = nz(b.v)
  359.  
  360. f_calcV() =>
  361. uV = 0.0
  362. dV = 0.0
  363.  
  364. switch
  365. (b.c - b.l) > (b.h - b.c) => uV := nzV
  366. (b.c - b.l) < (b.h - b.c) => dV := -nzV
  367. b.c > b.o => uV := nzV
  368. b.c < b.o => dV := -nzV
  369. b.c > nz(b.c[1]) => uV := nzV
  370. b.c < nz(b.c[1]) => dV := -nzV
  371. nz(uV[1]) > 0 => uV := uV + nzV
  372. nz(dV[1]) < 0 => dV := dV - nzV
  373.  
  374. [uV, dV]
  375.  
  376.  
  377.  
  378.  
  379. // # ============================[CONSTANT VARIABLES]============================ #
  380. sma4 = ta.sma(close, 4)
  381. sma5 = ta.sma(close, 5)
  382. sma9 = ta.sma(close, 9)
  383. ema50 = ta.ema(close, 50)
  384. ema200 = ta.ema(close, 200)
  385.  
  386. bullishSignalColor = #59e08a
  387. bearishSignalColor = #ff5959
  388.  
  389. dashboardRedText = #ee787d
  390. dashboardGreenText = #42bda8
  391. dashboardGreenBackground = #284444
  392. dashboardRedBackground = #49343e
  393.  
  394. // # ============================[CANDLE COLORING]============================ #
  395. macdFastLength = 12
  396. macdSlowLength = 26
  397. macdSignalLength = 9
  398.  
  399. if (candleColorType != 'Confirmation Simple')
  400. macdFastLength := 10
  401. macdSlowLength := 25
  402. macdSignalLength:=8
  403.  
  404. [MacdX, signalX, histX] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
  405.  
  406. //candle color scheme
  407. greenHigh = #4ce653
  408. greenMidHigh =#4ce653
  409. greenMidLow =#4ce653
  410. greenLow = #56328f
  411.  
  412. // Yellow
  413. yellowLow = #56328e
  414.  
  415. // 4 level of red
  416. redHigh = #ff0000
  417. redMidHigh = #ff0000
  418. redMidLow = #ff0000
  419. redLow = #56328f
  420.  
  421. if (candleColorType == 'Confirmation Gradient')
  422. greenHigh := #01d70c
  423. greenMidHigh := #269444
  424. greenMidLow :=#4f966c
  425. greenLow := #425970
  426.  
  427. // Yellow
  428. yellowLow := #513a88
  429.  
  430. // 4 level of red
  431. redHigh := #ff0000
  432. redMidHigh := #c21637
  433. redMidLow := #c33252
  434. redLow := #8e215f
  435. if (candleColorType == 'Contrarian Gradient')
  436. redHigh := #01d70c
  437. redMidHigh := #269444
  438. redMidLow :=#4f966c
  439. redLow := #425970
  440.  
  441. // Yellow
  442. yellowLow := #513a88
  443.  
  444. // 4 level of red
  445. greenHigh := #ff0000
  446. greenMidHigh := #c21637
  447. greenMidLow := #c33252
  448. greenLow := #8e215f
  449.  
  450. // Default color
  451. candleBody = yellowLow
  452.  
  453. if histX > 0
  454. if histX > histX[1] and histX[1] > 0 and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  455. candleBody := greenLow
  456.  
  457. if histX < 0
  458. if histX < histX[1] and histX[1] < 0 and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  459. candleBody := redLow
  460.  
  461. // Bullish trend
  462. if MacdX > 0 and histX > 0
  463. candleBody := greenMidLow
  464.  
  465. if histX > histX[1] and MacdX[1] > 0 and histX[1] > 0 and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  466. candleBody := greenMidHigh
  467.  
  468. if histX > histX[2] and MacdX[2] > 0 and histX[2] > 0 and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  469. candleBody := greenHigh
  470.  
  471. // Bearish trend
  472. if MacdX < 0 and histX < 0
  473. candleBody := redMidLow
  474.  
  475. if histX < histX[1] and MacdX[1] < 0 and histX[1] < 0 and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  476. candleBody := redMidHigh
  477.  
  478. if histX < histX[2] and MacdX[2] < 0 and histX[2] < 0 and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  479. candleBody := redHigh
  480.  
  481. barcolor(candleColorType == 'None' ? na : candleBody, editable = false)
  482.  
  483. // # ============================[SMART TRAIL]============================ #
  484. [smartTrailLine, fillerLine, smartTrailDirection] = LAF.getSmartTrail(10, 6, 8)
  485. smartTrail1 = plot(smartTrail and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? smartTrailLine : na, "Smart Trail", style = plot.style_line, color = smartTrailDirection== 'long' ? color.new(#2157f9, 0) : smartTrailDirection == 'short' ? color.new(#ff1100, 0) : na, editable = false)
  486. smartTrail2 = plot(smartTrail and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? fillerLine : na, "Fib 2", style = plot.style_line, transp = 100, editable = false)
  487. fill(smartTrail1, smartTrail2, color = smartTrailDirection == 'long' ? color.new(#2157f9, 80) : smartTrailDirection == 'short' ? color.new(#ff1100, 80) : na, editable = false)
  488.  
  489. // # ============================[TREND CATCHER]============================ #
  490. [trendCatcherLine, trendCatcherColor] = LAF.getTrendCatcher()
  491. newTrendCatcherColor = trendCatcherColor == color.blue ? #02ff65 : #ff1100
  492. plot(trendCatcher and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? trendCatcherLine : na, title='Trend Catcher', linewidth=2, color=newTrendCatcherColor, editable = false)
  493.  
  494. // # ============================[NEO CLOUD]============================ #
  495.  
  496. // # ============================[REVERSAL ZONES]============================ #
  497.  
  498. // # ============================[TREND TRACER]============================ #
  499. [trendTracerLine, trendTracerDirection] = LAF.getTrendTracer()
  500. plot(trendTracer and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? trendTracerLine : na, title='Trend Tracer', linewidth=2, style=plot.style_cross, color = trendTracerDirection, editable = false)
  501.  
  502. // # ============================[DASHBOARD COMPONENTS|]============================ #
  503.  
  504. trendStrengthMetric = math.abs(LAF.getTrendStrengthMetric(14, 'RMA', 21, 'EMA'))
  505. trendStrengthMetric := trendStrengthMetric*2.5
  506. trendIndication = trendStrengthMetric > 30 and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center' ? "πŸ”₯" : "❄️"
  507. trendStrengthCellColor = newTrendCatcherColor == #02ff65 ? dashboardGreenBackground : dashboardRedBackground
  508. trendStrengthTextColor = trendStrengthCellColor == dashboardGreenBackground ? dashboardGreenText : dashboardRedText
  509.  
  510. volatilityMetric = LAF.getVolatilityMetric()
  511. volatilityMetric2 = ta.sma(LAF.getVolatilityMetric(), 8)
  512. volatilityText = volatilityMetric < 30 ? 'Stable' : volatilityMetric < 80 ? 'Moderate' : 'Volatile'
  513. volatilityEmoji = volatilityMetric2 > volatilityMetric ? 'πŸ“‰' : 'πŸ“ˆ'
  514. volatilityCellColor = newTrendCatcherColor == #02ff65 ? dashboardGreenBackground : dashboardRedBackground
  515. VolatilityTextColor = trendStrengthCellColor == dashboardGreenBackground ? dashboardGreenText : dashboardRedText
  516.  
  517. squeezeMetric = LAF.getSqueezeMetric(45, 20)
  518. squeezeIsHigh = squeezeMetric >= 80 ? true : false
  519. squeezeCellColor = trendTracerDirection == #02ff65 ? #1a3a3e : #482632
  520. squeezeTextColor = trendTracerDirection != #02ff65 ? #ed3544 : #0a907a
  521. // and textVPosition == 'middle' and textHPosition == 'center' and c_title == #b2b5be80 and s_title == 'large' and a_title == 'center' and c_subtitle == #b2b5be80 and s_subtitle == 'normal' and a_subtitle == 'center'
  522. //
  523. [uV, dV] = f_calcV()
  524.  
  525. totalVolume = uV + math.abs(dV)
  526. //volumecolor = totalVolume >= 50 ? bullish : bearish
  527. volumeCellColor = dashboardRedBackground
  528. volumeTextColor = totalVolume >= 50 ? dashboardGreenText : dashboardRedText
  529. if (totalVolume >= 50)
  530. totalVolume := totalVolume*2
  531. volumeCellColor := dashboardGreenBackground
  532. else
  533. totalVolume := totalVolume*-2
  534.  
  535. volumeSentiment = totalVolume
  536.  
  537.  
  538. table_position = dashboardLocation == 'Bottom Left' ? position.bottom_left
  539. : dashboardLocation == 'Top Right' ? position.top_right
  540. : position.bottom_right
  541.  
  542. table_size = dashboardSize == 'Tiny' ? size.tiny
  543. : dashboardSize == 'Small' ? size.small
  544. : size.normal
  545.  
  546. tb = table.new(table_position, 7, 7
  547. , bgcolor = #1e222d
  548. , border_color = #373a46
  549. , border_width = 1
  550. , frame_color = #373a46
  551. , frame_width = 1)
  552.  
  553. if showDashboard
  554. if barstate.islast
  555. tb.cell(0, 2, autopilotMode == 'Off' ? "πŸ”Ž Optimal Sensivity" : "✈️ Autopilot Enabled", text_color = color.white, text_size = table_size, text_halign = text.align_left)
  556. tb.cell(0, 3, str.tostring(trendIndication) + "Trend Strength", text_color = color.white, text_size = table_size, text_halign = text.align_left)
  557. tb.cell(0, 4, volatilityEmoji+ " Lux Volatility", text_color = color.white, text_size = table_size, text_halign = text.align_left)
  558. tb.cell(0, 5, "πŸ”ƒ Squeeze", text_color = color.white, text_size = table_size, text_halign = text.align_left)
  559. tb.cell(0, 6, "πŸ’§ Volume Sentiment", text_color = color.white, text_size = table_size, text_halign = text.align_left)
  560.  
  561. tb.cell(1, 2, autopilotMode, text_color = color.white, text_size = table_size)
  562. tb.cell(1, 3, str.tostring(trendStrengthMetric, format.percent), text_color=trendStrengthTextColor, text_size=table_size, bgcolor = trendStrengthCellColor)
  563. tb.cell(1, 4, volatilityText, text_color = VolatilityTextColor, text_size = table_size, bgcolor = volatilityCellColor)
  564. tb.cell(1, 5, str.tostring(squeezeMetric, format.percent), text_color= squeezeTextColor, text_size=table_size, bgcolor = squeezeCellColor)
  565. tb.cell(1, 6, str.tostring(math.min(volumeSentiment, 100.), format.percent), text_color = volumeTextColor, text_size = table_size, bgcolor = volumeCellColor)
  566.  
  567.  
  568.  
  569.  
  570.  
  571. //************************************************************************************************************
  572. // REV ZONES
  573. //************************************************************************************************************
  574.  
  575. indiSet = false
  576. source = hlc3
  577. type = 'SuperSmoother'
  578. length = 100
  579. innermult = 1.0
  580. outermult = 2.415
  581.  
  582. ChartSet = false
  583. drawchannel = true
  584. displayzone = true
  585. zonetransp = 60
  586. displayline = true
  587.  
  588. MTFSet = false
  589. enable_mtf = true
  590. mtf_disp_typ = 'On Hover'
  591. mtf_typ = 'Auto'
  592. mtf_lvl1 = 'D'
  593. mtf_lvl2 = 'W'
  594.  
  595. //************************************************************************************************************
  596. // Functions Start {
  597. //************************************************************************************************************
  598. var pi = 2 * math.asin(1)
  599. var mult = pi * innermult
  600. var mult2 = pi * outermult
  601. var gradsize = 0.5
  602. var gradtransp = zonetransp
  603.  
  604. //-----------------------
  605. // Ehler SwissArmyKnife Function
  606. //-----------------------
  607. SAK_smoothing(_type, _src, _length) =>
  608. c0 = 1.0
  609. c1 = 0.0
  610. b0 = 1.0
  611. b1 = 0.0
  612. b2 = 0.0
  613. a1 = 0.0
  614. a2 = 0.0
  615. alpha = 0.0
  616. beta = 0.0
  617. gamma = 0.0
  618. cycle = 2 * pi / _length
  619.  
  620. if _type == 'Ehlers EMA'
  621. alpha := (math.cos(cycle) + math.sin(cycle) - 1) / math.cos(cycle)
  622. b0 := alpha
  623. a1 := 1 - alpha
  624. a1
  625. if _type == 'Gaussian'
  626. beta := 2.415 * (1 - math.cos(cycle))
  627. alpha := -beta + math.sqrt(beta * beta + 2 * beta)
  628. c0 := alpha * alpha
  629. a1 := 2 * (1 - alpha)
  630. a2 := -(1 - alpha) * (1 - alpha)
  631. a2
  632. if _type == 'Butterworth'
  633. beta := 2.415 * (1 - math.cos(cycle))
  634. alpha := -beta + math.sqrt(beta * beta + 2 * beta)
  635. c0 := alpha * alpha / 4
  636. b1 := 2
  637. b2 := 1
  638. a1 := 2 * (1 - alpha)
  639. a2 := -(1 - alpha) * (1 - alpha)
  640. a2
  641. if _type == 'BandStop'
  642. beta := math.cos(cycle)
  643. gamma := 1 / math.cos(cycle * 2 * 0.1) // delta default to 0.1. Acceptable delta -- 0.05<d<0.5
  644. alpha := gamma - math.sqrt(gamma * gamma - 1)
  645. c0 := (1 + alpha) / 2
  646. b1 := -2 * beta
  647. b2 := 1
  648. a1 := beta * (1 + alpha)
  649. a2 := -alpha
  650. a2
  651. if _type == 'SMA'
  652. c1 := 1 / _length
  653. b0 := 1 / _length
  654. a1 := 1
  655. a1
  656. if _type == 'EMA'
  657. alpha := 2 / (_length + 1)
  658. b0 := alpha
  659. a1 := 1 - alpha
  660. a1
  661. if _type == 'RMA'
  662. alpha := 1 / _length
  663. b0 := alpha
  664. a1 := 1 - alpha
  665. a1
  666.  
  667. _Input = _src
  668. _Output = 0.0
  669. _Output := c0 * (b0 * _Input + b1 * nz(_Input[1]) + b2 * nz(_Input[2])) + a1 * nz(_Output[1]) + a2 * nz(_Output[2]) - c1 * nz(_Input[_length])
  670. _Output
  671.  
  672. //-----------------------
  673. // SuperSmoother Function
  674. //-----------------------
  675. supersmoother(_src, _length) =>
  676. s_a1 = math.exp(-math.sqrt(2) * pi / _length)
  677. s_b1 = 2 * s_a1 * math.cos(math.sqrt(2) * pi / _length)
  678. s_c3 = -math.pow(s_a1, 2)
  679. s_c2 = s_b1
  680. s_c1 = 1 - s_c2 - s_c3
  681. ss = 0.0
  682. ss := s_c1 * _src + s_c2 * nz(ss[1], _src[1]) + s_c3 * nz(ss[2], _src[2])
  683. ss
  684.  
  685. //-----------------------
  686. // Auto TimeFrame Function
  687. //-----------------------
  688. // β€”β€”β€”β€”β€” Converts current chart resolution into a float minutes value.
  689. f_resInMinutes() =>
  690. _resInMinutes = timeframe.multiplier * (timeframe.isseconds ? 1. / 60 : timeframe.isminutes ? 1. : timeframe.isdaily ? 60. * 24 : timeframe.isweekly ? 60. * 24 * 7 : timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
  691. _resInMinutes
  692.  
  693. get_tf(_lvl) =>
  694. y = f_resInMinutes()
  695. z = timeframe.period
  696. if mtf_typ == 'Auto'
  697. if y < 1
  698. z := _lvl == 1 ? '1' : _lvl == 2 ? '5' : z
  699. z
  700. else if y <= 3
  701. z := _lvl == 1 ? '5' : _lvl == 2 ? '15' : z
  702. z
  703. else if y <= 10
  704. z := _lvl == 1 ? '15' : _lvl == 2 ? '60' : z
  705. z
  706. else if y <= 30
  707. z := _lvl == 1 ? '60' : _lvl == 2 ? '240' : z
  708. z
  709. else if y <= 120
  710. z := _lvl == 1 ? '240' : _lvl == 2 ? 'D' : z
  711. z
  712. else if y <= 240
  713. z := _lvl == 1 ? 'D' : _lvl == 2 ? 'W' : z
  714. z
  715. else if y <= 1440
  716. z := _lvl == 1 ? 'W' : _lvl == 2 ? 'M' : z
  717. z
  718. else if y <= 10080
  719. z := _lvl == 1 ? 'M' : z
  720. z
  721. else
  722. z := z
  723. z
  724. else
  725. z := _lvl == 1 ? mtf_lvl1 : _lvl == 2 ? mtf_lvl2 : z
  726. z
  727.  
  728. z
  729.  
  730. //-----------------------
  731. // Mean Reversion Channel Function
  732. //-----------------------
  733. get_mrc() =>
  734. v_condition = 0
  735. v_meanline = source
  736. v_meanrange = supersmoother(ta.tr, length)
  737.  
  738. //-- Get Line value
  739. if type == 'SuperSmoother'
  740. v_meanline := supersmoother(source, length)
  741. v_meanline
  742.  
  743. if type != 'SuperSmoother'
  744. v_meanline := SAK_smoothing(type, source, length)
  745. v_meanline
  746.  
  747. v_upband1 = v_meanline + v_meanrange * mult
  748. v_loband1 = v_meanline - v_meanrange * mult
  749. v_upband2 = v_meanline + v_meanrange * mult2
  750. v_loband2 = v_meanline - v_meanrange * mult2
  751.  
  752. //-- Check Condition
  753. if close > v_meanline
  754. v_upband2_1 = v_upband2 + v_meanrange * gradsize * 4
  755. v_upband2_9 = v_upband2 + v_meanrange * gradsize * -4
  756. if high >= v_upband2_9 and high < v_upband2
  757. v_condition := 1
  758. v_condition
  759. else if high >= v_upband2 and high < v_upband2_1
  760. v_condition := 2
  761. v_condition
  762. else if high >= v_upband2_1
  763. v_condition := 3
  764. v_condition
  765. else if close <= v_meanline + v_meanrange
  766. v_condition := 4
  767. v_condition
  768. else
  769. v_condition := 5
  770. v_condition
  771.  
  772. if close < v_meanline
  773. v_loband2_1 = v_loband2 - v_meanrange * gradsize * 4
  774. v_loband2_9 = v_loband2 - v_meanrange * gradsize * -4
  775. if low <= v_loband2_9 and low > v_loband2
  776. v_condition := -1
  777. v_condition
  778. else if low <= v_loband2 and low > v_loband2_1
  779. v_condition := -2
  780. v_condition
  781. else if low <= v_loband2_1
  782. v_condition := -3
  783. v_condition
  784. else if close >= v_meanline + v_meanrange
  785. v_condition := -4
  786. v_condition
  787. else
  788. v_condition := -5
  789. v_condition
  790.  
  791. [v_meanline, v_meanrange, v_upband1, v_loband1, v_upband2, v_loband2, v_condition]
  792.  
  793. //-----------------------
  794. // MTF Analysis
  795. //-----------------------
  796.  
  797. get_stat(_cond) =>
  798. ret = 'Price at Mean Line\n'
  799. if _cond == 1
  800. ret := 'Overbought (Weak)\n'
  801. ret
  802. else if _cond == 2
  803. ret := 'Overbought\n'
  804. ret
  805. else if _cond == 3
  806. ret := 'Overbought (Strong)\n'
  807. ret
  808. else if _cond == 4
  809. ret := 'Price Near Mean\n'
  810. ret
  811. else if _cond == 5
  812. ret := 'Price Above Mean\n'
  813. ret
  814. else if _cond == -1
  815. ret := 'Oversold (Weak)\n'
  816. ret
  817. else if _cond == -2
  818. ret := 'Oversold\n'
  819. ret
  820. else if _cond == -3
  821. ret := 'Oversold (Strong)\n'
  822. ret
  823. else if _cond == -4
  824. ret := 'Price Near Mean\n'
  825. ret
  826. else if _cond == -5
  827. ret := 'Price Below Mean\n'
  828. ret
  829. ret
  830.  
  831. //-----------------------
  832. // Chart Drawing Function
  833. //-----------------------
  834. format_price(x) =>
  835. y = str.tostring(x, '0.00000')
  836. if x > 10
  837. y := str.tostring(x, '0.000')
  838. y
  839. if x > 1000
  840. y := str.tostring(x, '0.00')
  841. y
  842. y
  843.  
  844. f_PriceLine(_ref, linecol) =>
  845. line.new(x1=bar_index, x2=bar_index - 1, y1=_ref, y2=_ref, extend=extend.left, color=linecol)
  846.  
  847. f_MTFLabel(_txt, _yloc) =>
  848. label.new(x=time + math.round(ta.change(time) * 20), y=_yloc, xloc=xloc.bar_time, text=mtf_disp_typ == 'Always Display' ? _txt : 'Check MTF', tooltip=mtf_disp_typ == 'Always Display' ? '' : _txt, color=color.black, textcolor=color.white, size=size.normal, style=mtf_disp_typ == 'On Hover' and displayline ? label.style_label_lower_left : label.style_label_left, textalign=text.align_left)
  849.  
  850. //} Function End
  851.  
  852. //************************************************************************************************************
  853. // Calculate Channel
  854. //************************************************************************************************************
  855. var tf_0 = timeframe.period
  856. var tf_1 = get_tf(1)
  857. var tf_2 = get_tf(2)
  858. textstylist = table.new(textVPosition + '_' + textHPosition, 1, 3)
  859. [meanline, meanrange, upband1, loband1, upband2, loband2, condition] = get_mrc()
  860. [mtf1_meanline, mtf1_meanrange, mtf1_upband1, mtf1_loband1, mtf1_upband2, mtf1_loband2, mtf1_condition] = request.security(syminfo.tickerid, tf_1, get_mrc())
  861. [mtf2_meanline, mtf2_meanrange, mtf2_upband1, mtf2_loband1, mtf2_upband2, mtf2_loband2, mtf2_condition] = request.security(syminfo.tickerid, tf_2, get_mrc())
  862.  
  863. //************************************************************************************************************
  864. // Drawing Start {
  865. //************************************************************************************************************
  866. float p_meanline = drawchannel ? meanline : na
  867. float p_upband1 = drawchannel ? upband1 : na
  868. float p_loband1 = drawchannel ? loband1 : na
  869. float p_upband2 = drawchannel ? upband2 : na
  870. float p_loband2 = drawchannel ? loband2 : na
  871.  
  872. //z = plot(p_meanline, color=color.new(#FFCD00, 0), style=plot.style_line, title=' Mean', linewidth=2)
  873. //x1 = plot(p_upband1, color=color.new(color.green, 50), style=plot.style_circles, title=' R1', linewidth=1)
  874. //x2 = plot(p_loband1, color=color.new(color.green, 50), style=plot.style_circles, title=' S1', linewidth=1)
  875. //y1 = plot(p_upband2, color=color.new(color.red, 50), style=plot.style_line, title=' R2', linewidth=1)
  876. //y2 = plot(p_loband2, color=color.new(color.red, 50), style=plot.style_line, title=' S2', linewidth=1)
  877.  
  878. //-----------------------
  879. // Draw zone
  880. //-----------------------
  881. //---
  882. var color1 = #FF0000
  883. var color2 = #FF4200
  884. var color3 = #FF5D00
  885. var color4 = #FF7400
  886. var color5 = #FF9700
  887. var color6 = #FFAE00
  888. var color7 = #FFC500
  889. var color8 = #FFCD00
  890. //---
  891. float upband2_1 = drawchannel and displayzone ? upband2 + meanrange * gradsize * 4 : na
  892. float loband2_1 = drawchannel and displayzone ? loband2 - meanrange * gradsize * 4 : na
  893. float upband2_2 = drawchannel and displayzone ? upband2 + meanrange * gradsize * 3 : na
  894. float loband2_2 = drawchannel and displayzone ? loband2 - meanrange * gradsize * 3 : na
  895. float upband2_3 = drawchannel and displayzone ? upband2 + meanrange * gradsize * 2 : na
  896. float loband2_3 = drawchannel and displayzone ? loband2 - meanrange * gradsize * 2 : na
  897. float upband2_4 = drawchannel and displayzone ? upband2 + meanrange * gradsize * 1 : na
  898. float loband2_4 = drawchannel and displayzone ? loband2 - meanrange * gradsize * 1 : na
  899. float upband2_5 = drawchannel and displayzone ? upband2 + meanrange * gradsize * 0 : na
  900. float loband2_5 = drawchannel and displayzone ? loband2 - meanrange * gradsize * 0 : na
  901. float upband2_6 = drawchannel and displayzone ? upband2 + meanrange * gradsize * -1 : na
  902. float loband2_6 = drawchannel and displayzone ? loband2 - meanrange * gradsize * -1 : na
  903. float upband2_7 = drawchannel and displayzone ? upband2 + meanrange * gradsize * -2 : na
  904. float loband2_7 = drawchannel and displayzone ? loband2 - meanrange * gradsize * -2 : na
  905. float upband2_8 = drawchannel and displayzone ? upband2 + meanrange * gradsize * -3 : na
  906. float loband2_8 = drawchannel and displayzone ? loband2 - meanrange * gradsize * -3 : na
  907. float upband2_9 = drawchannel and displayzone ? upband2 + meanrange * gradsize * -4 : na
  908. float loband2_9 = drawchannel and displayzone ? loband2 - meanrange * gradsize * -4 : na
  909.  
  910. up1 = plot(reversalZone ? upband2_1 : na, color = color.black, transp = 100, editable = false)
  911. up2 = plot(reversalZone ?upband2_5:na, color = color.black, transp = 100, editable = false)
  912. up3 = plot(reversalZone ?upband2_9:na, color = color.black, transp = 100, editable = false)
  913. dp1 = plot(reversalZone ?loband2_1:na, color = color.black, transp = 100, editable = false)
  914. dp2 = plot(reversalZone ?loband2_5:na, color = color.black, transp = 100, editable = false)
  915. dp3 = plot(reversalZone ?loband2_9:na, color = color.black, transp = 100, editable = false)
  916.  
  917. fill(up1, up2, color = #56202d, transp = 20, editable = false)
  918. fill(up2, up3, color = #3f1d29, transp = 60, editable = false)
  919. fill(dp1, dp2, color = #0f3e3f, transp = 20, editable = false)
  920. fill(dp2, dp3, color = #113135, transp = 60, editable = false)
  921.  
  922. //[upband2_1, upband2_5, upband2_9, loband2_1, loband2_5, loband2_9]
  923. tenkan_len = 365
  924. tenkan_mult = 3
  925.  
  926.  
  927. kijun_len = 365
  928. kijun_mult = 7
  929.  
  930.  
  931. spanB_len = 365
  932. spanB_mult = 15
  933.  
  934.  
  935. offset = 2
  936. //------------------------------------------------------------------------------
  937. avg(src,length,mult)=>
  938. atr = ta.atr(length)*mult
  939. up = hl2 + atr
  940. dn = hl2 - atr
  941. upper = 0.,lower = 0.
  942. upper := src[1] < upper[1] ? math.min(up,upper[1]) : up
  943. lower := src[1] > lower[1] ? math.max(dn,lower[1]) : dn
  944.  
  945. os = 0,max = 0.,min = 0.
  946. os := src > upper ? 1 : src < lower ? 0 : os[1]
  947. spt = os == 1 ? lower : upper
  948. max := ta.cross(src,spt) ? math.max(src,max[1]) : os == 1 ? math.max(src,max[1]) : spt
  949. min := ta.cross(src,spt) ? math.min(src,min[1]) : os == 0 ? math.min(src,min[1]) : spt
  950. math.avg(max,min)
  951. //------------------------------------------------------------------------------
  952. tenkan = avg(close,tenkan_len,tenkan_mult)
  953. kijun = avg(close,kijun_len,kijun_mult)
  954.  
  955.  
  956. senkouA = math.avg(kijun,tenkan)
  957. senkouB = avg(close,spanB_len,spanB_mult)
  958. //------------------------------------------------------------------------------
  959. tenkan_css = #2156f300
  960. kijun_css = #ff5e0000
  961.  
  962.  
  963. cloud_a = color.new(#006989, 47)
  964. cloud_b = color.new(#ff5252, 66)
  965.  
  966.  
  967. chikou_css = #7b1fa2
  968.  
  969.  
  970. plot(neoCloud ? tenkan : na,'Tenkan-Sen',tenkan_css, editable = false)
  971. plot(neoCloud ? kijun : na,'Kijun-Sen',kijun_css, editable = false)
  972.  
  973.  
  974. plot(neoCloud and ta.crossover(tenkan,kijun) ? kijun : na,'Crossover',#2156f300,3,plot.style_circles, editable = false)
  975. plot(neoCloud and ta.crossunder(tenkan,kijun) ? kijun : na,'Crossunder',#ff5e0000,3,plot.style_circles, editable = false)
  976.  
  977.  
  978. A = plot(neoCloud ? senkouA: na,'Senkou Span A',na,offset=offset-1, editable = false)
  979. B = plot(neoCloud ? senkouB : na,'Senkou Span B',na,offset=offset-1, editable = false)
  980. fill(A,B,senkouA > senkouB ? cloud_a : cloud_b)
  981.  
  982. lastNeo = int(senkouA + senkouB)
  983. last5Neo = ta.sma(lastNeo, 2)
  984.  
  985.  
  986.  
  987.  
  988. plot(close,'Chikou',chikou_css,offset=-offset+1,display=display.none, editable = false)
  989.  
  990.  
  991.  
  992.  
  993.  
  994. // Wylicz pozycjΔ™ kwadratu
  995. ltp1 = bar_index
  996. rtp1 = bar_index + 40
  997.  
  998. [lowBound, midBound, highBound] = LAF.getTPSLBoxes(6.0)
  999.  
  1000. // StwΓ³rz rzeczywisty kwadrat
  1001. //tp1box = box.new(left=ltp1, top=ttp1, right=rtp1, bottom=btp1, border_color=#3666f5, border_width=2, border_style=line.style_solid, bgcolor=color.new(#3666f5, 53), text="TP1 : " + str.tostring(close), text_size=size.large, text_color=color.new(#3666f5, 0), text_wrap=text.wrap_auto)
  1002. //var boxes = array.new<box>()
  1003. //boxes.push(box.new(left = ltp1, top = close+highBound, right = rtp1, bottom = close + midBound, border_color=#3666f5, border_width=2, border_style=line.style_solid, bgcolor=color.new(#3666f5, 70), text="TP/SL 2 : " + str.tostring(close), text_size=size.large, text_color=color.new(#3666f5, 0), text_wrap=text.wrap_auto))
  1004. //boxes.push(box.new(left = ltp1, top = close+midBound, right = rtp1, bottom = close + lowBound, border_color=#3666f5, border_width=2, border_style=line.style_solid, bgcolor=color.new(#3666f5, 40), text="TP/SL 1 : " + str.tostring(close), text_size=size.large, text_color=color.new(#3666f5, 0), text_wrap=text.wrap_auto))
  1005.  
  1006. //SL1 = box.new(left = ltp1, top = close-highBound, right = rtp1, bottom = close - midBound, border_color=#3666f5, border_width=2, border_style=line.style_solid, bgcolor=color.new(#3666f5, 70), text="TP/SL 2 : " + str.tostring(close), text_size=size.large, text_color=color.new(#3666f5, 0), text_wrap=text.wrap_auto)
  1007. //SL2 = box.new(left = ltp1, top = close-midBound, right = rtp1, bottom = close - lowBound, border_color=#3666f5, border_width=2, border_style=line.style_solid, bgcolor=color.new(#3666f5, 40), text="TP/SL 1 : " + str.tostring(close), text_size=size.large, text_color=color.new(#3666f5, 0), text_wrap=text.wrap_auto)
  1008.  
  1009.  
  1010. // UsuΕ„ poprzednie ramki
  1011. //box.delete(boxes.shift())
  1012. //box.delete(SL1[1])
  1013. //box.delete(SL2[1])
  1014.  
  1015. //box.delete(boxes.shift())
  1016.  
  1017.  
  1018. // ==== Overview ====
  1019. // ==================
  1020.  
  1021. // WaveTrend 3D (WT3D) is a novel implementation of the famous WaveTrend (WT) indicator and has been completely redesigned from the ground up to address some
  1022. // of the inherent shortcomings associated with the traditional WT algorithm, including:
  1023. // (1) unbounded extremes
  1024. // (2) susceptibility to whipsaw
  1025. // (3) lack of insight into other timeframes
  1026.  
  1027. // Furthermore, WT3D expands upon the original functionality of WT by providing:
  1028. // (1) first-class support for multi-timeframe (MTF) analysis
  1029. // (2) kernel-based regression for trend reversal confirmation
  1030. // (3) various options for signal smoothing and transformation
  1031. // (4) a unique mode for visualizing an input series as a symmetrical, three-dimensional waveform useful for pattern identification and cycle-related analysis
  1032.  
  1033. // Fundamental Assumptions:
  1034. // (1) There exists a probability density function that describes the relative likelihood for a price to visit a given value.
  1035. // (2) The probability density function for price is a function of time.
  1036. // (3) The probability density function can approximate a Gaussian distribution (shown below).
  1037.  
  1038. // ___
  1039. // .::~!:.. |
  1040. // :ΞΞΞΞ~!ΞΞΞ!. |
  1041. // .ΞJΞΞΞΞ~!ΞΞΞ?J^ |
  1042. // :J?ΞΞΞΞΞ~!ΞΞΞΞΞJ^ |
  1043. // :J?ΞΞΞΞΞΞ~!ΞΞΞΞΞΞ??. |
  1044. // :JΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞ?J^ |
  1045. // :JΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞ?J^ [ PRICE ]
  1046. // .:~ΞΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞΞ!!~ |
  1047. // :?~^ΞΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞΞ!^Ξ! |
  1048. // ~:^^^ΞΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞΞ!^^!Ξ. |
  1049. // .Ξ!^^^^ΞΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞΞ!^^^~Ξ~ |
  1050. // .~Ξ~^^^^^ΞΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞΞ!^^^^^!Ξ: |
  1051. // .~Ξ~^^^^^^^ΞΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞΞ!^^^^^^~!!^. |
  1052. // ....::^^!~~^^^^^^^^^ΞΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞΞ!^^^^^^^^^~!^^::...... |
  1053. // ..:::^^^^^^^::::::::::::::ΞΞΞΞΞΞΞΞΞΞ~!ΞΞΞΞΞΞΞΞΞ!::::::::::::^^^^^^^^:::.. |
  1054. //
  1055. // -------------------------------- [ TIME ] -------------------------------|
  1056.  
  1057. // How to use this indicator:
  1058. // - The basic usage of WT3D is similar to how one would use the traditional WT indicator.
  1059. // - Divergences can be spotted by finding "trigger waves", which are small waves that immediately follow a larger wave. These can also be thought of as Lower-Highs and Higher-Lows in the oscillator.
  1060. // - Instead of the SMA-cross in the original WT, the primary mechanism for identifying potential pivots are the crossovers of the fast/normal speed oscillators, denoted by the small red/green circles.
  1061. // - The larger red/green circles represent points where there could be a potential trigger wave for a Divergence. Settings related to Divergence detection can be configured in the "Divergence" section.
  1062. // - For overbought/oversold conditions, the 0.5 and -0.5 levels are convenient since the normal-speed oscillator will only exceed this level ~25% of the time.
  1063. // - For less experienced users, focusing on the three oscillators is recommended since they give critical information from multiple timeframes that can help to identify trends and spot potential divergences.
  1064. // - For more experienced users, this indicator also has many other valuable features, such as Center of Gravity (CoG) smoothing, Kernel Estimate Crossovers, a mirrored mode for cycle analysis, and more.
  1065. // - Note: Additional resources for learning/using the more advanced features of this indicator are a work in progress, but in the meantime, I am happy to answer any questions.
  1066.  
  1067. // ================
  1068. // ==== Inputs ====
  1069. // ================
  1070.  
  1071. // Signal Settings
  1072. src = close
  1073. useMirror = false
  1074. useEma = false
  1075. emaLength = 3
  1076. useCog = false
  1077. cogLength = 6
  1078. oscillatorLookback =20
  1079. quadraticMeanLength = 50
  1080. src := useEma ? ta.ema(src, emaLength) : src
  1081. src := useCog ? ta.cog(src, cogLength) : src
  1082. speedToEmphasize = 'Normal'
  1083. emphasisWidth = 2
  1084. useKernelMA = false
  1085. useKernelEmphasis = false
  1086.  
  1087. // Oscillator Settings
  1088. offset := 0
  1089. showOsc = true
  1090. showOsc := showOsc
  1091. float f_length = 0.75
  1092. float f_smoothing = 0.45
  1093. float n_length = 1.0
  1094. float n_smoothing = 1.0
  1095. float s_length = 1.75
  1096. float s_smoothing = 2.5
  1097.  
  1098. // Divergence Detection
  1099. divThreshold = 30
  1100. sizePercent = 40
  1101.  
  1102. // Overbought/Oversold Zones (Reversal Zones)
  1103. showObOs = false
  1104. invertObOsColors = false
  1105.  
  1106. // Transparencies and Gradients
  1107. areaBackgroundTrans = 128.
  1108. areaForegroundTrans = 64.
  1109. lineBackgroundTrans = 2.6
  1110. lineForegroundTrans = 2.
  1111. customTransparency = 30
  1112. maxStepsForGradient = 8
  1113.  
  1114. // The defaults are colors that Google uses for its Data Science libraries (e.g. TensorFlow). They are considered to be colorblind-safe.
  1115. var color fastBullishColor = color.black
  1116. var color normalBullishColor = color.black
  1117. var color slowBullishColor = color.black
  1118. var color fastBearishColor = color.black
  1119. var color normalBearishColor = color.black
  1120. var color slowBearishColor =color.black
  1121. var color c_bullish = color.black
  1122. var color c_bearish = color.black
  1123.  
  1124. lineBackgroundTrans := lineBackgroundTrans * customTransparency
  1125. areaBackgroundTrans := areaBackgroundTrans * customTransparency
  1126. lineForegroundTrans := lineForegroundTrans * customTransparency
  1127. areaForegroundTrans := areaForegroundTrans * customTransparency
  1128.  
  1129. areaFastTrans = areaBackgroundTrans
  1130. lineFastTrans = lineBackgroundTrans
  1131. areaNormalTrans = areaBackgroundTrans
  1132. lineNormalTrans = lineBackgroundTrans
  1133. areaSlowTrans = areaForegroundTrans
  1134. lineSlowTrans = lineForegroundTrans
  1135.  
  1136. switch speedToEmphasize
  1137. "Slow" =>
  1138. areaFastTrans := areaBackgroundTrans
  1139. lineFastTrans := lineBackgroundTrans
  1140. areaNormalTrans := areaBackgroundTrans
  1141. lineNormalTrans := lineBackgroundTrans
  1142. areaSlowTrans := areaForegroundTrans
  1143. lineSlowTrans := lineForegroundTrans
  1144. "Normal" =>
  1145. areaFastTrans := areaBackgroundTrans
  1146. lineFastTrans := lineBackgroundTrans
  1147. areaNormalTrans := areaForegroundTrans
  1148. lineNormalTrans := lineForegroundTrans
  1149. areaSlowTrans := areaBackgroundTrans
  1150. lineSlowTrans := lineBackgroundTrans
  1151. "Fast" =>
  1152. areaFastTrans := areaForegroundTrans
  1153. lineFastTrans := lineForegroundTrans
  1154. areaNormalTrans := areaBackgroundTrans
  1155. lineNormalTrans := lineBackgroundTrans
  1156. areaSlowTrans := areaBackgroundTrans
  1157. lineSlowTrans := lineBackgroundTrans
  1158. "None" =>
  1159. areaFastTrans := areaBackgroundTrans
  1160. lineFastTrans := lineBackgroundTrans
  1161. areaNormalTrans := areaBackgroundTrans
  1162. lineNormalTrans := lineBackgroundTrans
  1163. areaSlowTrans := areaBackgroundTrans
  1164. lineSlowTrans := lineBackgroundTrans
  1165.  
  1166. // =================================
  1167. // ==== Color Helper Functions =====
  1168. // =================================
  1169.  
  1170. getPlotColor(signal, bullColor, bearColor) =>
  1171. signal >= 0.0 ? bullColor : bearColor
  1172.  
  1173. getAreaColor(signal, useMomentum, bullColor, bearColor) =>
  1174. if useMomentum
  1175. ta.rising(signal, 1) ? bullColor : bearColor
  1176. else
  1177. signal >= 0.0 ? bullColor : bearColor
  1178.  
  1179. getColorGradientFromSteps(_source, _center, _steps, weakColor, strongColor) =>
  1180. var float _qtyAdvDec = 0.
  1181. var float _maxSteps = math.max(1, _steps)
  1182. bool _xUp = ta.crossover(_source, _center)
  1183. bool _xDn = ta.crossunder(_source, _center)
  1184. float _chg = ta.change(_source)
  1185. bool _up = _chg > 0
  1186. bool _dn = _chg < 0
  1187. bool _srcBull = _source > _center
  1188. bool _srcBear = _source < _center
  1189. _qtyAdvDec := _srcBull ? _xUp ? 1 : _up ? math.min(_maxSteps, _qtyAdvDec + 1) : _dn ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _srcBear ? _xDn ? 1 : _dn ? math.min(_maxSteps, _qtyAdvDec + 1) : _up ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _qtyAdvDec
  1190. color colorGradient = color.from_gradient(_qtyAdvDec, 1, _maxSteps, weakColor, strongColor)
  1191. colorGradient
  1192.  
  1193. getColorGradientFromSource(series, _min, _max, weakColor, strongColor) =>
  1194. var float baseLineSeries = _min + (_max - _min) / 2
  1195. color colorGradient = series >= baseLineSeries ? color.from_gradient(value=series, bottom_value=baseLineSeries, top_value=_max, bottom_color=weakColor, top_color=strongColor) : color.from_gradient(series, _min, baseLineSeries, strongColor, weakColor)
  1196. colorGradient
  1197.  
  1198. // ================================
  1199. // ==== Main Helper Functions =====
  1200. // ================================
  1201.  
  1202. normalizeDeriv(_src, _quadraticMeanLength) =>
  1203. float derivative = _src - _src[2]
  1204. quadraticMean = math.sqrt(nz(math.sum(math.pow(derivative, 2), _quadraticMeanLength) / _quadraticMeanLength))
  1205. derivative/quadraticMean
  1206.  
  1207. tanh(series float _src) =>
  1208. -1 + 2/(1 + math.exp(-2*_src))
  1209.  
  1210. dualPoleFilter(float _src, float _lookback) =>
  1211. float _omega = -99 * math.pi / (70 * _lookback)
  1212. float _alpha = math.exp(_omega)
  1213. float _beta = -math.pow(_alpha, 2)
  1214. float _gamma = math.cos(_omega) * 2 * _alpha
  1215. float _delta = 1 - _gamma - _beta
  1216. float _slidingAvg = 0.5 * (_src + nz(_src[1], _src))
  1217. float _filter = na
  1218. _filter := (_delta*_slidingAvg) + _gamma*nz(_filter[1]) + _beta*nz(_filter[2])
  1219. _filter
  1220.  
  1221. getOscillator(float src, float smoothingFrequency, int quadraticMeanLength) =>
  1222. nDeriv = normalizeDeriv(src, quadraticMeanLength)
  1223. hyperbolicTangent = tanh(nDeriv)
  1224. result = dualPoleFilter(hyperbolicTangent, smoothingFrequency)
  1225.  
  1226. // =================================
  1227. // ==== Oscillator Calculations ====
  1228. // =================================
  1229.  
  1230. // Fast Oscillator + Mirror
  1231. offsetFast = offset
  1232. f_lookback = f_smoothing * oscillatorLookback
  1233. signalFast = getOscillator(src, f_lookback, quadraticMeanLength)
  1234. seriesFast = f_length*signalFast+offsetFast
  1235. seriesFastMirror = useMirror ? -seriesFast + 2*offsetFast : na
  1236.  
  1237. // Normal Oscillator + Mirror
  1238. offsetNormal = 0
  1239. n_lookback = n_smoothing * oscillatorLookback
  1240. signalNormal = getOscillator(src, n_lookback, quadraticMeanLength)
  1241. seriesNormal = n_length*signalNormal+offsetNormal
  1242. seriesNormalMirror = useMirror ? -seriesNormal + 2*offsetNormal : na
  1243.  
  1244. // Slow Oscillator + Mirror
  1245. offsetSlow = -offset
  1246. s_lookback = s_smoothing * oscillatorLookback
  1247. signalSlow = getOscillator(src, s_lookback, quadraticMeanLength)
  1248. seriesSlow = s_length*signalSlow+offsetSlow
  1249. seriesSlowMirror = useMirror ? -seriesSlow + 2*offsetSlow : na
  1250.  
  1251. // =====================================
  1252. // ==== Color Gradient Calculations ====
  1253. // =====================================
  1254.  
  1255. // Fast Color Gradients (Areas and Lines)
  1256. fastBaseColor = getPlotColor(signalFast, fastBullishColor, fastBearishColor)
  1257. fastBaseColorInverse = getPlotColor(signalFast, fastBearishColor, fastBullishColor)
  1258. fastAreaGradientFromSource = getColorGradientFromSource(seriesFast, -1.+offsetFast, 1+offsetFast, color.new(fastBaseColor, areaFastTrans), fastBaseColor)
  1259. fastAreaGradientFromSteps = getColorGradientFromSteps(seriesFast, offsetFast, maxStepsForGradient, color.new(fastBaseColor, areaFastTrans), fastBaseColor)
  1260. fastLineGradientFromSource = getColorGradientFromSource(seriesFast, -1+offsetFast, 1+offsetFast, color.new(fastBaseColor, lineFastTrans), fastBaseColor)
  1261. fastLineGradientFromSteps = getColorGradientFromSteps(seriesFast, offsetFast, maxStepsForGradient, color.new(fastBaseColor, lineFastTrans), fastBaseColor)
  1262. fastAreaGradientFromSourceInverse = getColorGradientFromSource(seriesFast, -1.+offsetFast, 1+offsetFast, color.new(fastBaseColorInverse, areaFastTrans), fastBaseColorInverse)
  1263. fastAreaGradientFromStepsInverse = getColorGradientFromSteps(seriesFast, offsetFast, maxStepsForGradient, color.new(fastBaseColorInverse, areaFastTrans), fastBaseColorInverse)
  1264.  
  1265. // Normal Color Gradients (Areas and Lines)
  1266. normalBaseColor = getPlotColor(signalNormal, normalBullishColor, normalBearishColor)
  1267. normalBaseColorInverse = getPlotColor(signalNormal, normalBearishColor, normalBullishColor)
  1268. normalAreaGradientFromSource = getColorGradientFromSource(seriesNormal, -1.+offsetNormal, 1.+offsetNormal, color.new(normalBaseColor, areaNormalTrans), normalBaseColor)
  1269. normalAreaGradientFromSteps = getColorGradientFromSteps(seriesNormal, offsetNormal, maxStepsForGradient, color.new(normalBaseColor, areaNormalTrans), normalBaseColor)
  1270. normalLineGradientFromSource = getColorGradientFromSource(seriesNormal, -1+offsetNormal, 1+offsetNormal, color.new(normalBaseColor, lineNormalTrans), normalBaseColor)
  1271. normalLineGradientFromSteps = getColorGradientFromSteps(seriesNormal, offsetNormal, maxStepsForGradient, color.new(normalBaseColor, lineNormalTrans), normalBaseColor)
  1272. normalAreaGradientFromSourceInverse = getColorGradientFromSource(seriesNormal, -1.+offsetNormal, 1.+offsetNormal, color.new(normalBaseColorInverse, areaNormalTrans), normalBaseColorInverse)
  1273. normalAreaGradientFromStepsInverse = getColorGradientFromSteps(seriesNormal, offsetNormal, maxStepsForGradient, color.new(normalBaseColorInverse, areaNormalTrans), normalBaseColorInverse)
  1274.  
  1275. // Slow Color Gradients (Areas and Lines)
  1276. slowBaseColor = getPlotColor(signalSlow, slowBullishColor, slowBearishColor)
  1277. slowBaseColorInverse = getPlotColor(signalSlow, slowBearishColor, slowBullishColor)
  1278. slowAreaGradientFromSource = getColorGradientFromSource(seriesSlow, -1.75+offsetSlow, 1.75+offsetSlow, color.new(slowBaseColor, areaSlowTrans), slowBaseColor)
  1279. slowAreaGradientFromSteps = getColorGradientFromSteps(seriesSlow, offsetSlow, maxStepsForGradient, color.new(slowBaseColor, areaSlowTrans), slowBaseColor)
  1280. slowLineGradientFromSource = getColorGradientFromSource(seriesSlow, -1.75+offsetSlow, 1.75+offsetSlow, color.new(slowBaseColor, lineSlowTrans), slowBaseColor)
  1281. slowLineGradientFromSteps = getColorGradientFromSteps(seriesSlow, offsetSlow, maxStepsForGradient, color.new(slowBaseColor, lineSlowTrans), slowBaseColor)
  1282. slowAreaGradientFromSourceInverse = getColorGradientFromSource(seriesSlow, -1.75+offsetSlow, 1.75+offsetSlow, color.new(slowBaseColorInverse, areaSlowTrans), slowBaseColorInverse)
  1283. slowAreaGradientFromStepsInverse = getColorGradientFromSteps(seriesSlow, offsetSlow, maxStepsForGradient, color.new(slowBaseColorInverse, areaSlowTrans), slowBaseColorInverse)
  1284.  
  1285. // =========================================
  1286. // ==== Plot Parameters and Logic Gates ====
  1287. // =========================================
  1288.  
  1289. // Speed Booleans
  1290. isSlow = speedToEmphasize == "Slow"
  1291. isNormal = speedToEmphasize == "Normal"
  1292. isFast = speedToEmphasize == "Fast"
  1293.  
  1294. // Series Colors
  1295. seriesSlowColor = showOsc or isSlow ? color.new(slowLineGradientFromSource, lineSlowTrans) : na
  1296. seriesNormalColor = showOsc or isNormal ? color.new(normalLineGradientFromSource, lineNormalTrans) : na
  1297. seriesFastColor = showOsc or isFast ? color.new(fastLineGradientFromSource, lineFastTrans) : na
  1298. seriesSlowMirrorColor = useMirror ? seriesSlowColor : na
  1299. seriesNormalMirrorColor = useMirror ? seriesNormalColor : na
  1300. seriesFastMirrorColor = useMirror ? seriesFastColor : na
  1301.  
  1302. // Series Line Widths
  1303. seriesSlowWidth = isSlow ? emphasisWidth : 1
  1304. seriesNormalWidth = isNormal ? emphasisWidth : 1
  1305. seriesFastWidth = isFast ? emphasisWidth : 1
  1306. seriesSlowMirrorWidth = useMirror ? seriesSlowWidth : na
  1307. seriesNormalMirrorWidth = useMirror ? seriesNormalWidth : na
  1308. seriesFastMirrorWidth = useMirror ? seriesFastWidth : na
  1309.  
  1310. // Speed Related Switches
  1311. seriesEmphasis = switch
  1312. isFast => seriesFast
  1313. isNormal => seriesNormal
  1314. isSlow => seriesSlow
  1315. => na
  1316. //
  1317. colorLineEmphasis = switch
  1318. isFast => fastLineGradientFromSource
  1319. isNormal => normalLineGradientFromSource
  1320. isSlow => slowLineGradientFromSource
  1321. => na
  1322.  
  1323. colorAreaEmphasis = switch
  1324. isFast => fastAreaGradientFromSource
  1325. isNormal => normalAreaGradientFromSource
  1326. isSlow => slowAreaGradientFromSource
  1327. => na
  1328.  
  1329. // Crossover Signals
  1330. bearishCross = ta.crossunder(seriesFast, seriesNormal) and seriesNormal > 0
  1331. bullishCross = ta.crossover(seriesFast, seriesNormal) and seriesNormal < 0
  1332. slowBearishMedianCross = ta.crossunder(seriesSlow, 0)
  1333. slowBullishMedianCross = ta.crossover(seriesSlow, 0)
  1334. normalBearishMedianCross = ta.crossunder(seriesNormal, 0)
  1335. normalBullishMedianCross = ta.crossover(seriesNormal, 0)
  1336. fastBearishMedianCross = ta.crossunder(seriesFast, 0)
  1337. fastBullishMedianCross = ta.crossover(seriesFast, 0)
  1338.  
  1339. // Last Crossover Values
  1340. lastBearishCrossValue = ta.valuewhen(condition=bearishCross, source=seriesNormal, occurrence=1)
  1341. lastBullishCrossValue = ta.valuewhen(condition=bullishCross , source=seriesNormal, occurrence=1)
  1342.  
  1343. // Trigger Wave Size Comparison
  1344. triggerWaveFactor = sizePercent/100
  1345. isSmallerBearishCross = bearishCross and seriesNormal < lastBearishCrossValue * triggerWaveFactor
  1346. isSmallerBullishCross = bullishCross and seriesNormal > lastBullishCrossValue * triggerWaveFactor
  1347.  
  1348. // ===========================
  1349. // ==== Kernel Estimators ====
  1350. // ===========================
  1351.  
  1352. // The following kernel estimators are based on the Gaussian Kernel.
  1353.  
  1354. // They are used for:
  1355. // (1) Confirming directional changes in the slow oscillator (i.e. a type of trend filter)
  1356. // (2) Visualizing directional changes as a dynamic ribbon (i.e. an additional oscillator that can crossover with the user specified oscillator of interest)
  1357. // (3) Visualizing transient directional changes while in the midst of a larger uptrend or downtrend (i.e. via color changes on the ribbon)
  1358.  
  1359. // Gaussian Kernel with a lookback of 6 bars, starting on bar 6 of the chart (medium fit)
  1360. yhat0 = kernels.gaussian(seriesEmphasis, 6, 6)
  1361.  
  1362. // Gaussian Kernel with a lookback of 3 bars, starting on bar 2 of the chart (tight fit)
  1363. yhat1 = kernels.gaussian(seriesEmphasis, 3, 2)
  1364.  
  1365. // Trend Assessment based on the relative position of the medium fit kernel to the slow oscillator
  1366. isBearishKernelTrend = yhat0 < seriesSlow
  1367. isBullishKernelTrend = yhat0 > seriesSlow
  1368.  
  1369.  
  1370. // Divergence Signals
  1371. isBearishDivZone = ta.barssince(bearishCross[1]) < divThreshold
  1372. isBullishDivZone = ta.barssince(bullishCross[1]) < divThreshold
  1373.  
  1374. // Crossover Detection
  1375. isBearishTriggerWave = isSmallerBearishCross and isBearishDivZone and isBearishKernelTrend
  1376. isBullishTriggerWave = isSmallerBullishCross and isBullishDivZone and isBullishKernelTrend
  1377.  
  1378. // =======================
  1379. // ==== Plots & Fills ====
  1380.  
  1381.  
  1382. var position = 0
  1383. length := atrLength
  1384.  
  1385.  
  1386. minMult = math.max(sensitivity-4, 1)
  1387. maxMult = math.min(sensitivity, 26)
  1388.  
  1389. if (autopilotMode == "Short Term")
  1390. minMult:=1
  1391. maxMult := 4
  1392. if (autopilotMode == 'Mid Term')
  1393. minMult := 5
  1394. maxMult := 10
  1395. if (autopilotMode == 'Long-Term')
  1396. minMult :=8
  1397. maxMult :=13
  1398.  
  1399.  
  1400. float step = .5
  1401.  
  1402. //Trigger error
  1403. if minMult > maxMult
  1404. runtime.error('Minimum factor is greater than maximum factor in the range')
  1405.  
  1406. float perfAlpha = 10
  1407. fromCluster = 'Best'
  1408.  
  1409. //Optimization
  1410. maxIter = 250
  1411. maxData = 2500
  1412.  
  1413. //Style
  1414. bearCss = color.red
  1415. bullCss = color.teal
  1416.  
  1417. amaBearCss = color.new(color.red, 50)
  1418. amaBullCss = color.new(color.teal, 50)
  1419.  
  1420. showGradient = true
  1421.  
  1422.  
  1423. //Dashboard
  1424. showDash = true
  1425. //dashboardLocation = input.string('Top Right', 'Location', options = ['Top Right', 'Bottom Right', 'Bottom Left'], group = 'Dashboard')
  1426. textSize = 'Small'
  1427.  
  1428. //-----------------------------------------------------------------------------}
  1429. //UDT's
  1430. //-----------------------------------------------------------------------------{
  1431. type supertrend
  1432. float upper = hl2
  1433. float lower = hl2
  1434. float output
  1435. float perf = 0
  1436. float factor
  1437. int trend = 0
  1438.  
  1439. type vector
  1440. array<float> out
  1441.  
  1442. //-----------------------------------------------------------------------------}
  1443. //Supertrend
  1444. //-----------------------------------------------------------------------------{
  1445. var holder = array.new<supertrend>(0)
  1446. var factors = array.new<float>(0)
  1447.  
  1448. //Populate supertrend type array
  1449. if barstate.isfirst
  1450. for i = 0 to int((maxMult - minMult) / step)
  1451. factors.push(minMult + i * step)
  1452. holder.push(supertrend.new())
  1453.  
  1454. atr = ta.atr(length)
  1455.  
  1456. //Compute Supertrend for multiple factors
  1457. k = 0
  1458. for factor in factors
  1459. get_spt = holder.get(k)
  1460.  
  1461. up = hl2 + atr * factor
  1462. dn = hl2 - atr * factor
  1463.  
  1464. get_spt.trend := close > get_spt.upper ? 1 : close < get_spt.lower ? 0 : get_spt.trend
  1465. get_spt.upper := close[1] < get_spt.upper ? math.min(up, get_spt.upper) : up
  1466. get_spt.lower := close[1] > get_spt.lower ? math.max(dn, get_spt.lower) : dn
  1467.  
  1468. diff = nz(math.sign(close[1] - get_spt.output))
  1469. get_spt.perf += 2/(perfAlpha+1) * (nz(close - close[1]) * diff - get_spt.perf)
  1470. get_spt.output := get_spt.trend == 1 ? get_spt.lower : get_spt.upper
  1471. get_spt.factor := factor
  1472. k += 1
  1473.  
  1474. //-----------------------------------------------------------------------------}
  1475. //K-means clustering
  1476. //-----------------------------------------------------------------------------{
  1477. factor_array = array.new<float>(0)
  1478. data = array.new<float>(0)
  1479.  
  1480. //Populate data arrays
  1481. if last_bar_index - bar_index <= maxData
  1482. for element in holder
  1483. data.push(element.perf)
  1484. factor_array.push(element.factor)
  1485.  
  1486. //Intitalize centroids using quartiles
  1487. centroids = array.new<float>(0)
  1488. centroids.push(data.percentile_linear_interpolation(25))
  1489. centroids.push(data.percentile_linear_interpolation(50))
  1490. centroids.push(data.percentile_linear_interpolation(75))
  1491.  
  1492. //Intialize clusters
  1493. var array<vector> factors_clusters = na
  1494. var array<vector> perfclusters = na
  1495.  
  1496. if last_bar_index - bar_index <= maxData
  1497. for _ = 0 to maxIter
  1498. factors_clusters := array.from(vector.new(array.new<float>(0)), vector.new(array.new<float>(0)), vector.new(array.new<float>(0)))
  1499. perfclusters := array.from(vector.new(array.new<float>(0)), vector.new(array.new<float>(0)), vector.new(array.new<float>(0)))
  1500.  
  1501. //Assign value to cluster
  1502. i = 0
  1503. for value in data
  1504. dist = array.new<float>(0)
  1505. for centroid in centroids
  1506. dist.push(math.abs(value - centroid))
  1507.  
  1508. idx = dist.indexof(dist.min())
  1509. perfclusters.get(idx).out.push(value)
  1510. factors_clusters.get(idx).out.push(factor_array.get(i))
  1511. i += 1
  1512.  
  1513. //Update centroids
  1514. new_centroids = array.new<float>(0)
  1515. for cluster_ in perfclusters
  1516. new_centroids.push(cluster_.out.avg())
  1517.  
  1518. //Test if centroid changed
  1519. if new_centroids.get(0) == centroids.get(0) and new_centroids.get(1) == centroids.get(1) and new_centroids.get(2) == centroids.get(2)
  1520. break
  1521.  
  1522. centroids := new_centroids
  1523.  
  1524. //-----------------------------------------------------------------------------}
  1525. //Signals and trailing stop
  1526. //-----------------------------------------------------------------------------{
  1527. //Get associated supertrend
  1528. var float target_factor = na
  1529. var float perf_idx = na
  1530. var float perf_ama = na
  1531.  
  1532. var from = switch fromCluster
  1533. 'Best' => 2
  1534. 'Average' => 1
  1535. 'Worst' => 0
  1536.  
  1537. //Performance index denominator
  1538. den = ta.ema(math.abs(close - close[1]), int(perfAlpha))
  1539.  
  1540. if not na(perfclusters)
  1541. //Get average factors within target cluster
  1542. target_factor := nz(factors_clusters.get(from).out.avg(), target_factor)
  1543.  
  1544. //Get performance index of target cluster
  1545. perf_idx := math.max(nz(perfclusters.get(from).out.avg()), 0) / den
  1546.  
  1547. //Get new supertrend
  1548. var upper = hl2
  1549. var lower = hl2
  1550. var os = 0
  1551.  
  1552. up = hl2 + atr * target_factor
  1553. dn = hl2 - atr * target_factor
  1554. upper := close[1] < upper ? math.min(up, upper) : up
  1555. lower := close[1] > lower ? math.max(dn, lower) : dn
  1556. os := close > upper ? 1 : close < lower ? 0 : os
  1557. ts = os ? lower : upper
  1558.  
  1559. //Get trailing stop adaptive MA
  1560. if na(ts[1]) and not na(ts)
  1561. perf_ama := ts
  1562. else
  1563. perf_ama += perf_idx * (ts - perf_ama)
  1564.  
  1565. //-----------------------------------------------------------------------------}
  1566. //Dashboard
  1567. //-----------------------------------------------------------------------------{
  1568.  
  1569. //-----------------------------------------------------------------------------{
  1570. css = os ? bullCss : bearCss
  1571.  
  1572. plot(showTrailingStoploss ? ts : na, 'Trailing Stop', os != os[1] ? na : css, editable = false)
  1573.  
  1574. plot(showMovingAverage? perf_ama:na, 'Trailing Stop AMA',
  1575. ta.cross(close, perf_ama) ? na
  1576. : close > perf_ama ? amaBullCss : amaBearCss, editable = false)
  1577.  
  1578. //Candle coloring
  1579. //barcolor(showGradient ? color.from_gradient(perf_idx, 0, 1, color.new(css, 80), css) : na)
  1580.  
  1581. //Signals
  1582.  
  1583. if showSignals
  1584. if os > os[1] and (signalPresets != "Smart Trail [Filter]" or smartTrailDirection == 'long') and (signalPresets != "Trend Tracer [Filter]" or trendTracerDirection==#02ff65) and (signalPresets != "Trend Strength [Filter]" or trendStrengthMetric >= 25) and (signalPresets != "Trend Catcher [Filter]" or newTrendCatcherColor == #02ff65) and (signalPresets != "Neo Cloud [Filter]" or int(lastNeo) >= last5Neo)
  1585. int signalStrength = int(perf_idx*10) < 2 ? 1 : int(perf_idx*10) < 4 ? 2 : int(perf_idx*10) < 5 ? 3 : 4
  1586. label.new(n, low-ta.atr(30)/2, signalClassifier ? str.tostring(signalStrength) : ema50 > ema200 ? "β–²+" : "β–²"
  1587. , color = bullCss
  1588. , style = label.style_label_up
  1589. , textcolor = color.white
  1590. , yloc=yloc.belowbar
  1591. , size = size.small)
  1592. position := 1
  1593.  
  1594. if os < os[1] and (signalPresets != "Smart Trail [Filter]" or smartTrailDirection == 'short') and (signalPresets != "Trend Tracer [Filter]" or trendTracerDirection!=#02ff65) and (signalPresets != "Trend Strength [Filter]" or trendStrengthMetric >= 25)and (signalPresets != "Trend Catcher [Filter]" or newTrendCatcherColor != #02ff65) and (signalPresets != "Neo Cloud [Filter]" or int(lastNeo) <=last5Neo)
  1595. int signalStrength = int(perf_idx*10) < 2 ? 1 : int(perf_idx*10) < 4 ? 2 : int(perf_idx*10) < 5 ? 3 : 4
  1596. label.new(n, high+ta.atr(30)/2, signalClassifier ? str.tostring(signalStrength) : ema50 < ema200 ? "β–Ό+" : "β–Ό"
  1597. , color = bearCss
  1598. , style = label.style_label_down
  1599. , textcolor = color.white
  1600. , yloc=yloc.abovebar
  1601. , size = size.small)
  1602. position := -1
  1603.  
  1604.  
  1605. // =======================
  1606.  
  1607. // Signal Plots
  1608. //plot(position == 1 and bearishCross ? high+5 : na, title="Bearish Cross", style=plot.style_cross, linewidth=2, color=c_bearish, offset=-1)
  1609. //plot(position == -1 and bearishCross ? high+5 : na, title="Bearish Cross", style=plot.style_circles, linewidth=2, color=c_bearish, offset=-1)
  1610. //plot(position == 1 and isBearishTriggerWave ? high+5 : na, title="Bearish Trigger Cross", style=plot.style_cross, linewidth=3, color=c_bearish, offset=-1)
  1611. //plot(position == -1 and isBearishTriggerWave ? high+5 : na, title="Bearish Trigger Cross", style=plot.style_circles, linewidth=3, color=c_bearish, offset=-1)
  1612. //plotchar(bearishCross and position == 1, "Long", "βœ–", location.abovebar, color = #4774f5, size = size.tiny, editable = false)
  1613. //plotchar(bearishCross and position == -1, "Long", "β–Ό", location.abovebar, color = c_bearish, size = size.tiny)
  1614. plotchar(isBearishTriggerWave and position == 1, "Long", "βœ–", location.abovebar, color=#4774f5, size = size.tiny, editable = false)
  1615. //plotchar(isBearishTriggerWave and position == -1, "Long", "β–Ό", location.abovebar, color=c_bearish, size = size.small)
  1616.  
  1617.  
  1618.  
  1619. //plot(position == 1 and bullishCross ? low -5: na, title="Bullish Cross", style= plot.style_circles, linewidth=2, color=c_bullish, offset=-1)
  1620. //plot(position == -1 and bullishCross ? low -5: na, title="Bullish Cross", style= plot.style_cross, linewidth=2, color=c_bullish, offset=-1)
  1621. //plot(position == 1 and isBullishTriggerWave ? low -5 : na, title="Bullish Trigger Cross", style=plot.style_circles, linewidth=3, color=c_bullish, offset=-1)
  1622. //plot(position == -1 and isBullishTriggerWave ? low -5 : na, title="Bullish Trigger Cross", style=plot.style_cross, linewidth=3, color=c_bullish, offset=-1)
  1623.  
  1624. //plotchar(bullishCross and position == 1, "Long", "β–²", location.belowbar, color = c_bullish, size = size.tiny)
  1625. //plotchar(bullishCross and position == -1, "Long", "βœ–", location.belowbar, color = #ff7322, size = size.tiny, editable = false)
  1626. //plotchar(isBullishTriggerWave and position == 1, "Long", "β–²", location.belowbar, color=c_bullish, size = size.small)
  1627. plotchar(isBullishTriggerWave and position == -1, "Long", "βœ–", location.belowbar, color=#ff7322, size = size.tiny, editable = false)
  1628.  
  1629.  
  1630. // Shit
  1631. atrMultiplier = input(2, title="ATR Multiplier")
  1632. boxHeightInAtr = atrMultiplier * ta.atr(10)
  1633.  
  1634. // Box TP 1
  1635.  
  1636. [lowb, midb, highb] = LAF.getTPSLBoxes(6.0)
  1637.  
  1638. if (takeProfitBoxes == 'On')
  1639. tp1box = box.new(left=bar_index + 1, top=close + midb, right=bar_index + 18, bottom=close + lowb, border_color=color.new(#3666f5, 0), border_width=2, border_style=line.style_solid, bgcolor=color.new(#3666f5, 55), text="TP/SL 1 : " + str.tostring(close), text_size=size.normal, text_color=color.new(#3666f5, 0))
  1640. bottom_tp1 = box.get_bottom(tp1box)
  1641. box.delete(tp1box[1])
  1642.  
  1643. // Box TP 2
  1644. tp2box = box.new(left=bar_index + 1, top=close+highb, right=bar_index + 18, bottom=close+midb, border_color=color.new(#3666f5, 0), border_width=2, border_style=line.style_solid, bgcolor=color.new(#3666f5, 65), text="TP/SL 2 : " + str.tostring(close), text_size=size.normal, text_color=color.new(#3666f5, 0))
  1645. top_tp2 = box.get_top(tp2box)
  1646. box.delete(tp2box[1])
  1647. // Empty Box
  1648. newBox = box.new(left=bar_index + 18, top=top_tp2, right=bar_index + 200, bottom=bottom_tp1, border_color=color.new(#3666f5, 0), border_width=2, border_style=line.style_solid, bgcolor=color.new(#3666f5, 50), text=" ", text_size=size.normal, text_color=color.new(#3666f5, 0))
  1649. box.delete(newBox[1])
  1650. // SL Box
  1651. slBox = box.new(left=bar_index + 3, top=close-lowb, right=bar_index + 18, bottom=close-midb, border_color=color.new(color.red, 0), border_width=2, border_style=line.style_solid, bgcolor=color.new(color.red, 66), text="TP/SL 2 : " + str.tostring(close), text_size=size.normal, text_color=color.new(color.red, 0))
  1652. bottom_sl = box.get_top(slBox)
  1653. box.delete(slBox[1])
  1654.  
  1655. // SL2 Box
  1656. sl2Box = box.new(left=bar_index + 3, top=close-midb, right=bar_index + 18, bottom=close-highb, border_color=color.new(color.red, 0), border_width=2, border_style=line.style_solid, bgcolor=color.new(color.red, 65), text="TP/SL 1 : " + str.tostring(close), text_size=size.normal, text_color=color.new(color.red, 0))
  1657. bottom_sl2 = box.get_bottom(sl2Box)
  1658. box.delete(sl2Box[1])
  1659.  
  1660. // Empty Box SL
  1661. Slboxem = box.new(left=bar_index + 18, top=bottom_sl, right=bar_index + 200, bottom=bottom_sl2, border_color=color.new(color.red, 0), border_width=2, border_style=line.style_solid, bgcolor=color.new(color.red, 50), text=" ", text_size=size.normal, text_color=color.new(color.red, 0))
  1662. box.delete(Slboxem[1])
  1663. //
  1664. // Line tp Bottom
  1665. var line tpb = na
  1666. isLastBar = barstate.islast
  1667.  
  1668. if (isLastBar)
  1669. tpb := line.new(na, bottom_tp1, na, bottom_tp1, color=color.new(#3666f5, 0), width=2, style=line.style_dashed)
  1670.  
  1671. line.set_xy1(tpb, bar_index[50], bottom_tp1)
  1672. line.set_xy2(tpb, bar_index + 200, bottom_tp1)
  1673. line.delete(tpb[1])
  1674. // Line tp top
  1675. var line tp2Line = na
  1676.  
  1677. if (isLastBar)
  1678. tp2Line := line.new(na, top_tp2, na, top_tp2, color=color.new(#3666f5, 0), width=2, style=line.style_dashed)
  1679.  
  1680. line.set_xy1(tp2Line, bar_index[50], top_tp2)
  1681. line.set_xy2(tp2Line, bar_index + 200, top_tp2)
  1682. line.delete(tp2Line[1])
  1683.  
  1684. // Line SL
  1685. var line slLine = na
  1686.  
  1687. if (isLastBar)
  1688. slLine := line.new(na, bottom_sl, na, bottom_sl, color=color.new(color.red, 0), width=2, style=line.style_dashed)
  1689.  
  1690. line.set_xy1(slLine, bar_index[50], bottom_sl)
  1691. line.set_xy2(slLine, bar_index + 400, bottom_sl)
  1692. line.delete(slLine[1])
  1693. // Line SL2
  1694. var line sl2Line = na
  1695.  
  1696. if (isLastBar)
  1697. sl2Line := line.new(na, bottom_sl2, na, bottom_sl2, color=color.new(color.red, 0), width=2, style=line.style_dashed)
  1698.  
  1699. line.set_xy1(sl2Line, bar_index[50], bottom_sl2)
  1700. line.set_xy2(sl2Line, bar_index + 200, bottom_sl2)
  1701. line.delete(sl2Line[1])
  1702.  
Advertisement
Add Comment
Please, Sign In to add comment