Advertisement
xmd79

Combined Patterns with Filter

Oct 18th, 2023
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. //@version=4
  2. study("Combined Patterns with Filter", overlay=true)
  3.  
  4. // Filter settings
  5. filter = input(true, title="Filter")
  6. filtercutoff = input(7, title="Filter Cutoff")
  7.  
  8. // Morning and Evening Stars
  9. DojiSize = input(0.25, minval=0.01, title="Doji size")
  10. doji(i) => abs(open[i] - close[i]) <= (high[i] - low[i]) * DojiSize
  11. dojifilter = doji(1) and not doji(0) and not doji(2)
  12. bar = abs(open - close)
  13. bar_1 = abs(open[1] - close[1])
  14. bar_2 = abs(open[2] - close[2])
  15. highfilter = filter ? max(high, high[1], high[2]) >= highest(filtercutoff) : true
  16. lowfilter = filter ? min(low, low[1], low[2]) <= lowest(filtercutoff) : true
  17. morning_star = bar > bar_1 and bar_2 > bar_1 and close > close[1] and close > open[1] and open[2] > close[1] and bar > (bar_2 * 0.5)
  18. morning_detected = morning_star or (dojifilter and lowfilter and close[1] < open[1] and close > open[1])
  19. evening_star = bar > bar_1 and bar_2 > bar_1 and close < close[1] and close < open[1] and open[2] < close[1] and bar > (bar_2 * 0.5)
  20. evening_detected = evening_star or (dojifilter and highfilter and close[1] > open[1] and close < open[1])
  21.  
  22. // Tweezer
  23. maxrate = input(1.5, title="Max Rate % Between Wick Sizes") / 100
  24. leveldiff = input(0.2, title="Max Difference in level %") / 100
  25. prd = input(3, title="Highest/Lowest Period")
  26. apartprd = input(12, title="Max Distance between Tweezers", minval=1)
  27. colup = input(color.lime, title="Color", inline="col")
  28. coldn = input(color.red, title="", inline="col")
  29. topwick = high - max(close, open)
  30. bottomwick = min(close, open) - low
  31. aparttweezers_top(len) =>
  32. ret = 0
  33. if topwick > 0
  34. for x = 1 to len
  35. if na(topwick[x]) == false
  36. break
  37. if (max(topwick, topwick[x]) / min(topwick, topwick[x]) <= maxrate and abs(high - high[x]) < max(topwick, topwick[x]) * leveldiff)
  38. ret := x
  39. break
  40. else
  41. if high[x] >= high
  42. ret := 0
  43. break
  44. ret
  45. aparttweezers_bottom(len) =>
  46. ret = 0
  47. if bottomwick > 0
  48. for x = 1 to len
  49. if na(bottomwick[x]) == false
  50. break
  51. if (max(bottomwick, bottomwick[x]) / min(bottomwick, bottomwick[x]) <= maxrate and abs(low - low[x]) < max(bottomwick, bottomwick[x]) * leveldiff)
  52. ret := x
  53. break
  54. else
  55. if low[x] <= low
  56. ret := 0
  57. break
  58. ret
  59. top_tweezer = aparttweezers_top(apartprd)
  60. bottom_tweezer = aparttweezers_bottom(apartprd)
  61.  
  62. // Piercing and Railroad Patterns
  63. piercing_pattern = (close[1] < open[1]) and (close > open) and (close > ((open[1] + close[1]) / 2))
  64. railroad_pattern = (close[1] < open[1]) and (open > close[1]) and (close > open)
  65. significant_wick_threshold = input(50, title="Significant Wick Threshold (%)") / 100
  66. candle_range = high - low
  67. candle_body = abs(close - open)
  68. has_significant_wick = (candle_range - candle_body) / candle_range >= significant_wick_threshold
  69.  
  70. pattern_detected = morning_detected or evening_detected or top_tweezer or bottom_tweezer or piercing_pattern or railroad_pattern
  71. barcolor(pattern_detected and not has_significant_wick ? color.blue : na)
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement