Advertisement
xmd79

Swing Failure Pattern Inquisitor

Jan 17th, 2023
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. // SFP Inquisitor
  2. // v0.2a
  3. //
  4. // coded by Bogdan Vaida
  5.  
  6. // Code for Swing High, Swing Low and Swing Failure Pattern.
  7. // Note that we're still in the alpha version, bugs may appear.
  8.  
  9. // Note that the number you set in your Swing History variable
  10. // will also be the minimum delay you see until the apples appear.
  11. // This is because we're checking the forward "history" too.
  12.  
  13. // The SFP will only check for these conditions:
  14. // - high above Swing History high and close below it
  15. // - low below Swing History high and close above it
  16.  
  17. // In some cases you may see an apple before the SFP that "doesn't fit"
  18. // with the SFP conditions. That's because that apple was drawn later and
  19. // the SFP actually appeared because of the previous apple.
  20. // 20 candles later.
  21.  
  22. // Legend:
  23. // 🍏 - swing high
  24. // 🍎 - swing low
  25. // 🧺 - candle where the last swing was driven from
  26. // 🍌 - swing failure pattern
  27. // 🍎🍌 - hungry scenario: swing low but also a SFP compared to the last swing
  28.  
  29. // TODO:
  30. // - show potential swing highs/lows (where current bar is < Swing History
  31. // - fix banana happening when a potential swing low exists but didn't have
  32. // enough forward candles
  33.  
  34. //@version=5
  35.  
  36. indicator(title='🍏🍎🍌 Swing Failure Pattern Inquisitor', shorttitle='SFP-I', overlay=true)
  37.  
  38. swingHistory = input.int(20, title='Swing history:', minval=1)
  39. plotSwings = input(true, title='Plot swings:')
  40. plotFirstSFPOnly = input(true, title='Plot only first SFP candle:')
  41.  
  42. var lastSwingHigh = float(na)
  43. var lastSwingLow = float(na)
  44.  
  45. // Swing Lows and Swing Highs code
  46. isSwingHigh = false
  47. isSwingLow = false
  48. swingHigh = high[swingHistory]
  49. swingLow = low[swingHistory]
  50. range_1 = swingHistory * 2
  51.  
  52. for i = 0 to range_1 by 1
  53. isSwingHigh := true
  54. if i < swingHistory
  55. if high[i] > swingHigh
  56. isSwingHigh := false
  57. break
  58. if i > swingHistory
  59. if high[i] >= swingHigh
  60. isSwingHigh := false
  61. break
  62.  
  63. for i = 0 to range_1 by 1
  64. isSwingLow := true
  65. if i < swingHistory
  66. if low[i] < swingLow
  67. isSwingLow := false
  68. break
  69. if i > swingHistory
  70. if low[i] <= swingLow
  71. isSwingLow := false
  72. break
  73.  
  74. // Swing Failure Pattern
  75. isSwingHighFailure = false
  76. isSwingLowFailure = false
  77.  
  78. lastSwingHigh := isSwingHigh ? swingHigh : lastSwingHigh
  79. lastSwingLow := isSwingLow ? swingLow : lastSwingLow
  80.  
  81. if lastSwingHigh < high and lastSwingHigh > close and ta.barssince(lastSwingHigh) <= swingHistory
  82. isSwingHighFailure := true
  83. if plotFirstSFPOnly
  84. lastSwingHigh := na
  85. lastSwingHigh
  86.  
  87. if lastSwingLow > low and lastSwingLow < close and ta.barssince(lastSwingLow) <= swingHistory
  88. isSwingLowFailure := true
  89. if plotFirstSFPOnly
  90. lastSwingLow := na
  91. lastSwingLow
  92.  
  93. // Debugging
  94. // barssince(high > swingHigh)
  95. plotchar(isSwingHighFailure, 'Swing High Failure', '', location.top)
  96. plotchar(isSwingLowFailure, 'Swing Low Failure', '', location.top)
  97. plotchar(lastSwingHigh, 'Last Swing High', '', location.top)
  98. plotchar(lastSwingLow, 'Last Swing Low', '', location.top)
  99.  
  100. // Plotting
  101. plotchar(series=plotSwings ? isSwingHigh : na, char='🍏', location=location.abovebar, size=size.tiny, offset=-swingHistory)
  102. plotchar(series=plotSwings ? isSwingLow : na, char='🍎', location=location.belowbar, size=size.tiny, offset=-swingHistory)
  103. plotchar(isSwingHighFailure, char='🍌', location=location.abovebar, size=size.tiny)
  104. plotchar(isSwingLowFailure, char='🍌', location=location.belowbar, size=size.tiny)
  105. // plotchar(swingHigh, char="🧺", location=location.abovebar, size=size.tiny) // location where the swing highs were drawn from
  106. // plotchar(swingLow, char="🧺", location=location.belowbar, size=size.tiny) // location where the swing lows were drawn from
  107.  
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement