xmd79

CryptoSignalScanner - MACD Multiple Time Frames

Mar 15th, 2023
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.51 KB | None | 0 0
  1. //@version=5
  2. // CryptoSignalScanner.com by SEOCO
  3. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  4.  
  5. indicator(title='CryptoSignalScanner - MACD Multiple Time Frames', shorttitle='MACD MTF')
  6.  
  7. //-------------------------------------------------------------------------------------------------------------
  8. // MACD Inputs Settings ---------------------------------------------------------------------------------------
  9. //-------------------------------------------------------------------------------------------------------------
  10. fast_length = input.int(title='Fast Length', defval=12, group='MACD Settings')
  11. slow_length = input.int(title='Slow Length', defval=26, group='MACD Settings')
  12. src = input.source(title='Source', defval=close, group='MACD Settings')
  13. signal_length = input.int(title='Signal Smoothing', minval=1, maxval=50, defval=9, group='MACD Settings')
  14.  
  15. //-------------------------------------------------------------------------------------------------------------
  16. // MACD Input Display Settings --------------------------------------------------------------------------------
  17. //-------------------------------------------------------------------------------------------------------------
  18. show_macd_average = input.bool(true, title='Show MACD Average Line', group='Display Settings')
  19. show_signal_average = input.bool(false, title='Show Signal Average Line', group='Display Settings')
  20. show_macd_default = input.bool(true, title='Show MACD Line Current Timeframe', group='Display Settings')
  21. show_signal_default = input.bool(true, title='Show Signal Line Current Timeframe', group='Display Settings')
  22. show_macd_15m = input.bool(true, title='Show 15 minutes MACD Line', group='Display Settings')
  23. show_signal_15m = input.bool(false, title='Show 15 minutes Signal Line', group='Display Settings')
  24. show_macd_30m = input.bool(true, title='Show 30 minutes MACD Line', group='Display Settings')
  25. show_signal_30m = input.bool(false, title='Show 30 minutes Signal Line', group='Display Settings')
  26. show_macd_1h = input.bool(true, title='Show 1 hour MACD Line', group='Display Settings')
  27. show_signal_1h = input.bool(false, title='Show 1 hour Signal Line', group='Display Settings')
  28. show_macd_2h = input.bool(true, title='Show 2 hour MACD Line', group='Display Settings')
  29. show_signal_2h = input.bool(false, title='Show 2 hour Signal Line', group='Display Settings')
  30. show_macd_4h = input.bool(true, title='Show 4 hour MACD Line', group='Display Settings')
  31. show_signal_4h = input.bool(false, title='Show 4 hour Signal Line', group='Display Settings')
  32.  
  33. //-------------------------------------------------------------------------------------------------------------
  34. // Define Default Colors --------------------------------------------------------------------------------------
  35. //-------------------------------------------------------------------------------------------------------------
  36. col_grow_above = #26A69A
  37. col_grow_below = #FFCDD2
  38. col_fall_above = #B2DFDB
  39. col_fall_below = #EF5350
  40. col_macd = #0094ff
  41. col_signal = #ff6a00
  42. col_base = #f4b77d
  43. col_macd_avg = #f4b77d //#3498DB
  44. col_signal_avg = #E74C3C
  45.  
  46. transparent = color.new(color.white, 100)
  47. col_macd_average = show_macd_average ? col_base : transparent
  48. col_macd_default = show_macd_default ? col_macd : transparent
  49. col_macd_15m = show_macd_15m ? col_macd : transparent
  50. col_macd_30m = show_macd_30m ? col_macd : transparent
  51. col_macd_1h = show_macd_1h ? col_macd : transparent
  52. col_macd_2h = show_macd_2h ? col_macd : transparent
  53. col_macd_4h = show_macd_4h ? col_macd : transparent
  54.  
  55. col_signal_average = show_signal_average ? col_signal_avg : transparent
  56. col_signal_default = show_signal_default ? col_signal : transparent
  57. col_signal_15m = show_signal_15m ? col_signal : transparent
  58. col_signal_30m = show_signal_30m ? col_signal : transparent
  59. col_signal_1h = show_signal_1h ? col_signal : transparent
  60. col_signal_2h = show_signal_2h ? col_signal : transparent
  61. col_signal_4h = show_signal_4h ? col_signal : transparent
  62.  
  63. //-------------------------------------------------------------------------------------------------------------
  64. //Calculate MACD Line -----------------------------------------------------------------------------------------
  65. //-------------------------------------------------------------------------------------------------------------
  66. macd = ta.ema(src, fast_length) - ta.ema(src, slow_length)
  67. macd_15m = request.security(syminfo.tickerid, '15', ta.ema(src, fast_length) - ta.ema(src, slow_length))
  68. macd_30m = request.security(syminfo.tickerid, '30', ta.ema(src, fast_length) - ta.ema(src, slow_length))
  69. macd_1h = request.security(syminfo.tickerid, '60', ta.ema(src, fast_length) - ta.ema(src, slow_length))
  70. macd_2h = request.security(syminfo.tickerid, '120', ta.ema(src, fast_length) - ta.ema(src, slow_length))
  71. macd_4h = request.security(syminfo.tickerid, '240', ta.ema(src, fast_length) - ta.ema(src, slow_length))
  72. macd_avg = (macd_15m + macd_30m + macd_1h + macd_2h + macd_4h) / 5
  73.  
  74. //-------------------------------------------------------------------------------------------------------------
  75. // Calculate Signal Line --------------------------------------------------------------------------------------
  76. //-------------------------------------------------------------------------------------------------------------
  77. signal = ta.ema(macd, signal_length)
  78. signal_15m = ta.ema(macd_15m, signal_length)
  79. signal_30m = ta.ema(macd_30m, signal_length)
  80. signal_1h = ta.ema(macd_1h, signal_length)
  81. signal_2h = ta.ema(macd_2h, signal_length)
  82. signal_4h = ta.ema(macd_4h, signal_length)
  83. signal_avg = (signal_15m + signal_30m + signal_1h + signal_2h + signal_4h) / 5
  84.  
  85. //-------------------------------------------------------------------------------------------------------------
  86. // Calculate Histogram ----------------------------------------------------------------------------------------
  87. //-------------------------------------------------------------------------------------------------------------
  88. hist = macd - signal
  89.  
  90. //-------------------------------------------------------------------------------------------------------------
  91. // Plot Lines -------------------------------------------------------------------------------------------------
  92. //-------------------------------------------------------------------------------------------------------------
  93. plot(hist, title='Histogram', style=plot.style_columns, color=hist >= 0 ? hist[1] < hist ? col_grow_above : col_fall_above : hist[1] < hist ? col_grow_below : col_fall_below)
  94. plot(macd, title='MACD', color=col_macd_default, editable=false)
  95. plot(macd_15m, title='MACD 15m', color=col_macd_15m, editable=false)
  96. plot(macd_30m, title='MACD 30m', color=col_macd_30m, editable=false)
  97. plot(macd_1h, title='MACD 1h', color=col_macd_1h, editable=false)
  98. plot(macd_2h, title='MACD 2h', color=col_macd_2h, editable=false)
  99. plot(macd_4h, title='MACD 4h', color=col_macd_4h, editable=false)
  100. plot(macd_avg, title='MACD Average', color=col_macd_average, linewidth=3, editable=false)
  101.  
  102. plot(signal, title='Signal', color=col_signal_default, editable=false)
  103. plot(signal_15m, title='Signal 15m', color=col_signal_15m, editable=false)
  104. plot(signal_30m, title='Signal 30m', color=col_signal_30m, editable=false)
  105. plot(signal_1h, title='Signal 1h', color=col_signal_1h, editable=false)
  106. plot(signal_2h, title='Signal 2h', color=col_signal_2h, editable=false)
  107. plot(signal_4h, title='Signal 4h', color=col_signal_4h, editable=false)
  108. plot(signal_avg, title='Signal Average', color=col_signal_average, linewidth=3, editable=false)
  109.  
  110.  
  111.  
  112.  
Advertisement
Add Comment
Please, Sign In to add comment