Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SFP Inquisitor
- // v0.2a
- //
- // coded by Bogdan Vaida
- // Code for Swing High, Swing Low and Swing Failure Pattern.
- // Note that we're still in the alpha version, bugs may appear.
- // Note that the number you set in your Swing History variable
- // will also be the minimum delay you see until the apples appear.
- // This is because we're checking the forward "history" too.
- // The SFP will only check for these conditions:
- // - high above Swing History high and close below it
- // - low below Swing History high and close above it
- // In some cases you may see an apple before the SFP that "doesn't fit"
- // with the SFP conditions. That's because that apple was drawn later and
- // the SFP actually appeared because of the previous apple.
- // 20 candles later.
- // Legend:
- // π - swing high
- // π - swing low
- // π§Ί - candle where the last swing was driven from
- // π - swing failure pattern
- // ππ - hungry scenario: swing low but also a SFP compared to the last swing
- // TODO:
- // - show potential swing highs/lows (where current bar is < Swing History
- // - fix banana happening when a potential swing low exists but didn't have
- // enough forward candles
- //@version=5
- indicator(title='πππ Swing Failure Pattern Inquisitor', shorttitle='SFP-I', overlay=true)
- swingHistory = input.int(20, title='Swing history:', minval=1)
- plotSwings = input(true, title='Plot swings:')
- plotFirstSFPOnly = input(true, title='Plot only first SFP candle:')
- var lastSwingHigh = float(na)
- var lastSwingLow = float(na)
- // Swing Lows and Swing Highs code
- isSwingHigh = false
- isSwingLow = false
- swingHigh = high[swingHistory]
- swingLow = low[swingHistory]
- range_1 = swingHistory * 2
- for i = 0 to range_1 by 1
- isSwingHigh := true
- if i < swingHistory
- if high[i] > swingHigh
- isSwingHigh := false
- break
- if i > swingHistory
- if high[i] >= swingHigh
- isSwingHigh := false
- break
- for i = 0 to range_1 by 1
- isSwingLow := true
- if i < swingHistory
- if low[i] < swingLow
- isSwingLow := false
- break
- if i > swingHistory
- if low[i] <= swingLow
- isSwingLow := false
- break
- // Swing Failure Pattern
- isSwingHighFailure = false
- isSwingLowFailure = false
- lastSwingHigh := isSwingHigh ? swingHigh : lastSwingHigh
- lastSwingLow := isSwingLow ? swingLow : lastSwingLow
- if lastSwingHigh < high and lastSwingHigh > close and ta.barssince(lastSwingHigh) <= swingHistory
- isSwingHighFailure := true
- if plotFirstSFPOnly
- lastSwingHigh := na
- lastSwingHigh
- if lastSwingLow > low and lastSwingLow < close and ta.barssince(lastSwingLow) <= swingHistory
- isSwingLowFailure := true
- if plotFirstSFPOnly
- lastSwingLow := na
- lastSwingLow
- // Debugging
- // barssince(high > swingHigh)
- plotchar(isSwingHighFailure, 'Swing High Failure', '', location.top)
- plotchar(isSwingLowFailure, 'Swing Low Failure', '', location.top)
- plotchar(lastSwingHigh, 'Last Swing High', '', location.top)
- plotchar(lastSwingLow, 'Last Swing Low', '', location.top)
- // Plotting
- plotchar(series=plotSwings ? isSwingHigh : na, char='π', location=location.abovebar, size=size.tiny, offset=-swingHistory)
- plotchar(series=plotSwings ? isSwingLow : na, char='π', location=location.belowbar, size=size.tiny, offset=-swingHistory)
- plotchar(isSwingHighFailure, char='π', location=location.abovebar, size=size.tiny)
- plotchar(isSwingLowFailure, char='π', location=location.belowbar, size=size.tiny)
- // plotchar(swingHigh, char="π§Ί", location=location.abovebar, size=size.tiny) // location where the swing highs were drawn from
- // plotchar(swingLow, char="π§Ί", location=location.belowbar, size=size.tiny) // location where the swing lows were drawn from
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement