Advertisement
xmd79

WT_mtf

Jan 17th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. //@version=5
  2. //
  3. indicator(shorttitle='WT_mtf', title='WaveTrend mtf', overlay=false)
  4. n1 = input(14)
  5. n2 = input(14)
  6. reaction_wt = input.int(defval=1, title='reaction', minval=1)
  7.  
  8. nsc = input(50)
  9. nsv = input(-50)
  10.  
  11. upper = input(true)
  12. lower = input(true)
  13.  
  14. red = #FF0000
  15. green = #0AAC00
  16.  
  17. ap = input(close)
  18. esa = ta.ema(ap, n1)
  19. d = ta.ema(math.abs(ap - esa), n1)
  20. ci = (ap - esa) / (0.015 * d)
  21. tci = ta.ema(ci, n2)
  22.  
  23. wt1 = tci
  24. wt2 = ta.sma(wt1, 4)
  25.  
  26. direction = 0
  27. direction := ta.rising(wt1, reaction_wt) ? 1 : ta.falling(wt1, reaction_wt) ? -1 : nz(direction[1])
  28. cambio_direccion = ta.change(direction, 1)
  29. pcol = direction > 0 ? green : direction < 0 ? red : na
  30.  
  31. plot(wt1, title='WT', color=pcol, linewidth=2, style=plot.style_line, transp=0)
  32.  
  33. plot(0)
  34.  
  35. midpoint = (nsc + nsv) / 2
  36. ploff = (nsc - midpoint) / 8
  37.  
  38. down = ta.crossunder(wt1, wt2) and wt1 >= nsc and upper == true
  39.  
  40. up = ta.crossover(wt1, wt2) and wt1 <= nsv and lower == true
  41. //
  42. plot(down ? wt2[1] + ploff : na, style=plot.style_cross, color=color.new(red, 0), linewidth=3)
  43. plot(up ? wt2[1] - ploff : na, style=plot.style_cross, color=color.new(green, 0), linewidth=3)
  44. //
  45.  
  46. // —————————— Inputs
  47. // ————— Upper TF we will be fetching data from.
  48. higherTf = input.timeframe('240', 'Interval used for security() calls')
  49. // ————— Source we will be fetching from higher TF.
  50. data = wt1
  51. data1 = wt2
  52. // —————————— Determine if current interval is smaller that higher timeframe interval selected in Inputs.
  53. // Get higher interval in ms, using only the smallest values retrieved,
  54. // since occasional situations generate higher than normal intervals.
  55. higherTfInt = 10e20
  56. higherTfInt := math.min(request.security(syminfo.tickerid, higherTf, ta.change(time)), nz(higherTfInt[1], 10e20))
  57. // Get current interval in ms.
  58. currentTfInt = 10e20
  59. currentTfInt := math.min(ta.change(time), nz(currentTfInt[1], 10e20))
  60. // Compare current and higher TF to make sure it is smaller, otherwise our plots don't make sense.
  61. chartOnLowerTf = currentTfInt < higherTfInt
  62. // ————— Find out if higher TF < 1D because we will then append " min" to warning label text.
  63. tfIsintraday = request.security(syminfo.tickerid, higherTf, timeframe.isintraday)
  64.  
  65.  
  66.  
  67. sec1ft = request.security(syminfo.tickerid, higherTf, data[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  68.  
  69. sec1ft1 = request.security(syminfo.tickerid, higherTf, data1[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  70. //
  71. down1 = ta.crossunder(sec1ft, sec1ft1) and sec1ft >= nsc and upper == true
  72.  
  73. up1 = ta.crossover(sec1ft, sec1ft1) and sec1ft <= nsv and lower == true
  74. //
  75. direction1 = 0
  76. direction1 := ta.rising(sec1ft, reaction_wt) ? 1 : ta.falling(sec1ft, reaction_wt) ? -1 : nz(direction1[1])
  77. cambio_direccion1 = ta.change(direction1, 1)
  78. pcol1 = direction1 > 0 ? green : direction1 < 0 ? red : na
  79.  
  80. plot(sec1ft, color=pcol1, linewidth=2, style=plot.style_line, transp=0)
  81. plot(down1 ? sec1ft1[1] + ploff : na, style=plot.style_circles, color=color.new(red, 0), linewidth=5)
  82. plot(up1 ? sec1ft1[1] - ploff : na, style=plot.style_circles, color=color.new(green, 0), linewidth=5)
  83. //
  84. /////// Alerts /////
  85. alertcondition(down, title='down')
  86. alertcondition(up, title='up')
  87. alertcondition(down1, title='down1')
  88. alertcondition(up1, title='up1')
  89.  
  90.  
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement