‘Swing Failure Pattern

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #246734 quote
    AragornaAragorna
    Participant
    Average
    Hi, I’ve found this interesting indicator for trading view. It’s be interesting to use it in a system. somone can help for conversion to PRT? thanks in advance
    Alessio
    // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
    // © LuxAlgo
    //@version=5
    indicator( ‘Swing Failure Pattern [LuxAlgo]’, ‘LuxAlgo – Swing Failure Pattern’, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500, overlay = true)
    //———————————————————————————————————————}
    //Settings
    //———————————————————————————————————————{
    sp         =                              ‘            ‘
    len        = input.int      (   5       ,    ‘Swings’      , minval=  1                               )
    bull       = input.bool     ( true      ,  ‘Bullish SFP’                                              )
    bear       = input.bool     ( true      ,  ‘Bearish SFP’                                              )
    iVal       = input.string   (‘None’, ‘Validation’+sp+ ‘   ‘, group=’Volume Validation’
     , options =          [‘Volume outside swing < Threshold’  ,’Volume outside swing > Threshold’,’None’])
    percent    = input.float    (25, ‘Volume Threshold %’      , inline=’valy’, group=’Volume Validation’
     , tooltip =                    ‘% of Total Volume’        , minval=  0   , maxval=100                )
    auto       = input.bool     (true,     ”                  , inline=’auto’, group=’Volume Validation’ )
    mlt        = input.int      (50  ,  ‘      Auto’ + sp      , inline=’auto’, group=’Volume Validation’ )
    res        = input.timeframe(‘1′ , sp +’   LTF’  + sp +’  ‘, inline=’ltf’ , group=’Volume Validation’ )
    prem       = input.bool     (false   ,’    Premium’                       , group=’Volume Validation’
     , tooltip =                        ‘Premium Plan or higher’                                          )
    showDash   = input.bool     (true    , ‘Show Dashboard’                   , group=    ‘Dashboard’     )
    dashLoc    = input.string   (           ‘Top Right’        , ‘Location’
     , options =                [‘Top Right’, ‘Bottom Right’, ‘Bottom Left’]  , group=    ‘Dashboard’     )
    textSize   = input.string   (             ‘Normal’         ,   ‘Size’
     , options =                     [‘Tiny’, ‘Small’, ‘Normal’]              , group=    ‘Dashboard’     )
    dSwingLine = input.bool     (true    ,  ‘Swing Lines’                     , group=      ‘Style’       )
    dOpposLine = input.bool     (true    ,  ‘Confirmation Lines’              , group=      ‘Style’       )
    dSFP_Line  = input.bool     (true    ,  ‘Swing Failure Wick’              , group=      ‘Style’       )
    dSFP_Label = input.bool     (true    ,  ‘Swing Failure Label’             , group=      ‘Style’       )
    colBl      = input.color    (#089981  , ‘Lines / Labels’ , inline=’lin’ , group=      ‘Style’       )
    colBr      = input.color    (#f23645  ,   ”             , inline=’lin’ , group=      ‘Style’
     , tooltip =                         ‘Bullish/Bearish’                                                )
    colBl2     = input.color    (#08998180, ‘SFP Wicks      ‘, inline=’wic’ , group=      ‘Style’       )
    colBr2     = input.color    (#f2364580,   ”             , inline=’wic’ , group=      ‘Style’
     , tooltip =                ‘Wick outside Swing, Bullish/Bearish’                                     )
    //—————————————————————————–}
    //UDT
    //—————————————————————————–{
    type piv
        float swing_prc // price
        int   swing_bix // bar_index
        float oppos_prc // price
        int   oppos_bix // bar_index
        bool  active
        bool  confirmed
        line  swing_line
        line  oppos_line
        line  wicky_line
        label wicky_label
    typeswing
        int   bix
        floatprc
    //—————————————————————————–}
    //Variables
    //—————————————————————————–{
    n   =bar_index
    INV = color(na)
    FGc = chart.fg_color
    table_position=dashLoc==’Bottom Left’?position.bottom_left
      :dashLoc==’Top Right’?position.top_right
      : position.bottom_right
    table_size=textSize==’Tiny’?size.tiny
      :textSize==’Small’?size.small
      : size.normal
    var tb = table.new(table_position, 2, 3
      , bgcolor      = #1e222d
      , border_color = #373a46
      , border_width = 1
      , frame_color  = #373a46
      , frame_width  = 1)
    varswingswingH=swing.new()
    varswingswingL=swing.new()
    var piv pivH     = piv.new()
    var piv pivL     = piv.new()
    validate=iVal!=’None’
    valHigher= iVal == ‘Volume outside swing > Threshold’
    valLower = iVal == ‘Volume outside swing < Threshold’
    //———————————————————————————————————————}
    //Method
    //———————————————————————————————————————{
    method n(float piv) => bool out = not na(piv)
    //———————————————————————————————————————}
    //Execution
    //———————————————————————————————————————{
    tfS  = timeframe.in_seconds(      res       )
    tfC  = timeframe.in_seconds(timeframe.period)
    rs   =auto?tfC/mlt:tfS
    if not validate
        res:=timeframe.period
    else
        rs  := prem ? rs : math.max(60, rs)
        res := timeframe.from_seconds(math.min(tfC, rs))
    ph = ta.pivothigh(len, 1)
    pl = ta.pivotlow (len, 1)
    [ltf_close, ltf_volume] = request.security_lower_tf(syminfo.tickerid, res, [close, volume])
    ltf_size = ltf_close.size()
    ifvalidate
        ifltf_size>0andltf_size[1]==0
            line.new(n, close, n, close + syminfo.mintick, color=color.silver, style=line.style_dotted, extend=extend.both)
    //———————————————————————————————————————}
    //Bearish Pattern
    //———————————————————————————————————————{
    if bear
        ifph.n()
            swingH.bix:=n-1
            swingH.prc:=ph
        sw = swingH.prc
        bx = swingH.bix
        ifhigh>sw
         and open < sw
         and close < sw
            valid = true
            ifvalidate
                ifltf_close.size()>0
                    outsideVolume = 0.
                    totalVolume=ltf_volume.sum()
                    forj=0toltf_close.size()-1
                        if ltf_close.get(j) > sw
                            outsideVolume += ltf_volume.get(j)
                    if(valHigher?100/totalVolume*outsideVolume<percent
                                  :100/totalVolume*outsideVolume>percent
                       )
                        valid := false
                    //if valid
                    //    label.new(n, high, text=str.format(“Total Volume: {0}\nWick Volume: {1}”, totalVolume, outsideVolume))
            ifvalid
                opposL=sw
                opposB = n
                for i = 1 to n – bx -1
                    iflow[i]<opposL
                        opposL := low [i]
                        opposB := n  – i
                if not pivH.confirmed
                    pivH.swing_line .delete()
                    pivH.oppos_line .delete()
                    pivH.wicky_line .delete()
                    pivH.wicky_label.delete()
                pivH := piv.new(sw, bx, opposL, opposB, true, false)
                ifdSwingLine
                    pivH.swing_line  := line.new (bx    , sw    , n, sw    , color=colBr)
                ifdOpposLine
                    pivH.oppos_line  := line.new (opposB, opposL, n, opposL, color=colBr, style=line.style_dotted)
                ifdSFP_Line
                    pivH.wicky_line  := line.new (n     , high  , n, sw    , color=colBr2, width=3)
                if dSFP_Label
                    pivH.wicky_label := label.new(n     , high
                     , style=label.style_label_down
                     , text=’SFP’, textcolor=colBr
                     , color=INV, size=size.normal
                     )
        ifpivH.activeandnotpivH.confirmed
            pivH.swing_line.set_x2(n)
            pivH.oppos_line.set_x2(n)
            if close < pivH.oppos_prc
                pivH.confirmed   := true
                if pivH.wicky_label.get_x() == n
                    pivH.wicky_label.set_text(‘SFP\n▼’)
                else
                    label.new(n, high, style=label.style_label_down, text=’▼’, textcolor=colBr, color=INV, size=size.normal)
        ifn-pivH.swing_bix>500
         or close > pivH.swing_prc
            pivH.active:=false
            if not pivH.confirmed
                pivH.swing_line .delete()
                pivH.oppos_line .delete()
                pivH.wicky_line .delete()
                pivH.wicky_label.delete()
    //———————————————————————————————————————}
    //Bullish Pattern
    //———————————————————————————————————————{
    if bull
        ifpl.n()
            swingL.bix:=n-1
            swingL.prc:=pl
        sw = swingL.prc
        bx = swingL.bix
        iflow  <sw
         and open > sw
         and close > sw
            valid = true
            ifvalidate
                ifltf_close.size()>0
                    outsideVolume = 0.
                    totalVolume=ltf_volume.sum()
                    forj=0toltf_close.size()-1
                        if ltf_close.get(j) < sw
                            outsideVolume += ltf_volume.get(j)
                    if(valHigher?100/totalVolume*outsideVolume<percent
                                  :100/totalVolume*outsideVolume>percent
                       )
                        valid := false
            ifvalid
                opposH=sw
                opposB = n
                for i = 1 to n – bx -1
                    ifhigh[i]>opposH
                        opposH := high[i]
                        opposB := n – i
                if not pivL.confirmed
                    pivL.swing_line .delete()
                    pivL.oppos_line .delete()
                    pivL.wicky_line .delete()
                    pivL.wicky_label.delete()
                pivL := piv.new(sw, bx, opposH, opposB, true, false)
                ifdSwingLine
                    pivL.swing_line  := line.new (bx    , sw    , n, sw    , color=colBl )
                ifdOpposLine
                    pivL.oppos_line  := line.new (opposB, opposH, n, opposH, color=colBl , style=line.style_dotted)
                ifdSFP_Line
                    pivL.wicky_line  := line.new (n     , low   , n, sw    , color=colBl2, width=3)
                if dSFP_Label
                    pivL.wicky_label := label.new(n     , low
                     , style=label.style_label_up
                     , text=’SFP’, textcolor=colBl
                     , color=INV, size=size.normal
                     )
        ifpivL.activeandnotpivL.confirmed
            pivL.swing_line.set_x2(n)
            pivL.oppos_line.set_x2(n)
            if close > pivL.oppos_prc
                pivL.confirmed   := true
                if pivL.wicky_label.get_x() == n
                    pivL.wicky_label.set_text(‘▲\nSFP’)
                else
                    label.new(n, low, style=label.style_label_up, text=’▲’, textcolor=colBl, color=INV, size=size.normal)
        ifn-pivL.swing_bix>500
         or close < pivL.swing_prc
            pivL.active:=false
            if not pivL.confirmed
                pivL.swing_line .delete()
                pivL.oppos_line .delete()
                pivL.wicky_line .delete()
                pivL.wicky_label.delete()
    //———————————————————————————————————————}
    //Dashboard
    //———————————————————————————————————————{
    if barstate.islast and validate and showDash
        tb.cell(0, 0, str.format(“LTF: {0}”, res), text_color=color.white, text_size=table_size)
    //———————————————————————————————————————}
    #246735 quote
    AragornaAragorna
    Participant
    Average

    I add the youtube link where I found it.

    thanks

    #246855 quote
    AragornaAragorna
    Participant
    Average

    Hi Ivan, Hi JS,

    anyone can help me?please!

    #246863 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    You asked for a conversion just 3 days ago, be patient a few more days. Thanks 🙂

    #246866 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Hi, here is the code:

    //--------------------------------------------------//
    // PRC_Swing failure Pattern
    //version = 0
    //07.05.2025
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //--------------------------------------------------//
    // Inputs
    //--------------------------------------------------//
    len=5
    bull=1
    bear=1
    n=barindex
    //--------------------------------------------------//
    // Pivot High-Low calculation
    //--------------------------------------------------//
    src1 = low
    src2 = high
    leftbars=len
    rightbars=1
    //--- Pivots low
    if src1 > src1[rightbars] and lowest[rightbars](src1) > src1[rightbars] and src1[rightbars] < lowest[leftbars](src1)[rightbars+1] then
    $ply[z+1] = src1[rightbars]
    $plx[z+1] = barindex[rightbars]
    z=z+1
    endif
    //--- Pivots high
    if src2 < src2[rightbars] and highest[rightbars](src2)<src2[rightbars] and src2[rightbars]>highest[leftbars](src2)[rightbars+1] then
    $phy[t+1]=src2[rightbars]
    $phx[t+1]=barindex[rightbars]
    t=t+1
    endif
    //--------------------------------------------------//
    // Bearish Pattern
    //--------------------------------------------------//
    if bear then
    if t<>t[1] then
    $swingHbix[s+1]=$phx[t]
    $swingHprc[s+1]=$phy[t]
    s=s+1
    endif
    sw=$swingHprc[s]
    bx=$swingHbix[s]
    if high>sw and open<sw and close<sw then
    
    opposL=sw
    opposB=n
    
    for i=1 to n-bx-1 do
    if low[i]<opposL then
    opposL=low[i]
    opposB=n-i
    endif
    next
    
    if $pivHconfirmed[w]=0 then
    
    $pivHswingbix1[w]=undefined
    $pivHswingprc1[w]=undefined
    $pivHswingbix2[w]=undefined
    $pivHswingprc2[w]=undefined
    
    $pivHopposbix1[w]=undefined
    $pivHopposprc1[w]=undefined
    $pivHopposbix2[w]=undefined
    $pivHopposprc2[w]=undefined
    
    $pivHwickybix1[w]=undefined
    $pivHwickyprc1[w]=undefined
    $pivHwickybix2[w]=undefined
    $pivHwickyprc2[w]=undefined
    endif
    
    $pivHswingbix1[w+1]=bx
    $pivHswingprc1[w+1]=sw
    $pivHswingbix2[w+1]=n
    $pivHswingprc2[w+1]=sw
    
    $pivHopposbix1[w+1]=opposB
    $pivHopposprc1[w+1]=opposL
    $pivHopposbix2[w+1]=n
    $pivHopposprc2[w+1]=opposL
    
    $pivHactive[w+1]=1
    $pivHconfirmed[w+1]=0
    
    $pivHwickybix1[w+1]=n
    $pivHwickyprc1[w+1]=high
    $pivHwickybix2[w+1]=n
    $pivHwickyprc2[w+1]=sw
    
    w=w+1
    endif
    if $pivHactive[w]=1 and $pivHconfirmed[w]=0 then
    
    $pivHswingbix2[w]=n
    $pivHopposbix2[w]=n
    
    if close < $pivHopposprc1[w] then
    $pivHconfirmed[w]=1
    if $pivHwickybix1[w]=n then
    $pivHwickyType[w]=1
    else
    $pivHwickyType[w]=0
    endif
    endif
    endif
    if n-$pivHswingbix1[w]>500 or close>$pivHswingprc1[w] then
    $pivHactive[w]=0
    if $pivHconfirmed[w]=0 then
    
    $pivHswingbix1[w]=undefined
    $pivHswingprc1[w]=undefined
    $pivHswingbix2[w]=undefined
    $pivHswingprc2[w]=undefined
    
    $pivHopposbix1[w]=undefined
    $pivHopposprc1[w]=undefined
    $pivHopposbix2[w]=undefined
    $pivHopposprc2[w]=undefined
    
    $pivHwickybix1[w]=undefined
    $pivHwickyprc1[w]=undefined
    $pivHwickybix2[w]=undefined
    $pivHwickyprc2[w]=undefined
    endif
    endif
    
    endif
    //--------------------------------------------------//
    // Bullish Pattern
    //--------------------------------------------------//
    if bull then
    if z<>z[1] then
    $swingLbix[q+1]=$plx[z]
    $swingLprc[q+1]=$ply[z]
    q=q+1
    endif
    
    sw=$swingLprc[q]
    bx=$swingLbix[q]
    
    if low<sw and open>sw and close>sw then
    
    opposH=sw
    opposBH=n
    
    for i=1 to n-bx-1 do
    if high[i]>opposH then
    opposH=high[i]
    opposBH=n-i
    endif
    next
    
    if $pivLconfirmed[w]=0 then
    
    $pivLswingbix1[w]=undefined
    $pivLswingprc1[w]=undefined
    $pivLswingbix2[w]=undefined
    $pivLswingprc2[w]=undefined
    
    $pivLopposbix1[w]=undefined
    $pivLopposprc1[w]=undefined
    $pivLopposbix2[w]=undefined
    $pivLopposprc2[w]=undefined
    
    $pivLwickybix1[w]=undefined
    $pivLwickyprc1[w]=undefined
    $pivLwickybix2[w]=undefined
    $pivLwickyprc2[w]=undefined
    endif
    
    $pivLswingbix1[w+1]=bx
    $pivLswingprc1[w+1]=sw
    $pivLswingbix2[w+1]=n
    $pivLswingprc2[w+1]=sw
    
    $pivLopposbix1[w+1]=opposBH
    $pivLopposprc1[w+1]=opposH
    $pivLopposbix2[w+1]=n
    $pivLopposprc2[w+1]=opposH
    
    $pivLactive[w+1]=1
    $pivLconfirmed[w+1]=0
    
    $pivLwickybix1[w+1]=n
    $pivLwickyprc1[w+1]=low
    $pivLwickybix2[w+1]=n
    $pivLwickyprc2[w+1]=sw
    
    w=w+1
    endif
    if $pivLactive[w]=1 and $pivLconfirmed[w]=0 then
    
    $pivLswingbix2[w]=n
    $pivLopposbix2[w]=n
    
    if close > $pivLopposprc1[w] then
    $pivLconfirmed[w]=1
    if $pivLwickybix1[w]=n then
    $pivLwickyType[w]=1
    else
    $pivLwickyType[w]=0
    endif
    endif
    endif
    
    if n-$pivLswingbix1[w]>500 or close<$pivLswingprc1[w] then
    $pivLactive[w]=0
    if $pivLconfirmed[w]=0 then
    
    $pivLswingbix1[w]=undefined
    $pivLswingprc1[w]=undefined
    $pivLswingbix2[w]=undefined
    $pivLswingprc2[w]=undefined
    
    $pivLopposbix1[w]=undefined
    $pivLopposprc1[w]=undefined
    $pivLopposbix2[w]=undefined
    $pivLopposprc2[w]=undefined
    
    $pivLwickybix1[w]=undefined
    $pivLwickyprc1[w]=undefined
    $pivLwickybix2[w]=undefined
    $pivLwickyprc2[w]=undefined
    endif
    
    endif
    
    endif
    
    if islastbarupdate then
    
    for i=w downto 1 do
    
    if $pivLwickyType[i]=1 then
    drawtext("SFT▲",$pivLopposbix2[i],$pivLopposprc2[i]-0.25*tr)coloured("GREEN")
    drawsegment($pivLswingbix1[i],$pivLswingprc1[i],$pivLswingbix2[i],$pivLswingprc2[i])style(line)coloured("green")
    drawsegment($pivLopposbix1[i],$pivLopposprc1[i],$pivLopposbix2[i],$pivLopposprc2[i])style(dottedline)coloured("green")
    elsif $pivLconfirmed[i]=1 then
    drawtext("SFT",$pivLwickybix1[i],$pivLwickyprc1[i]-0.35*tr)coloured("GREEN")
    drawtext("▲",$pivLopposbix2[i],$pivLopposprc2[i]-0.25*tr)coloured("GREEN")
    drawsegment($pivLswingbix1[i],$pivLswingprc1[i],$pivLswingbix2[i],$pivLswingprc2[i])style(line)coloured("green")
    drawsegment($pivLopposbix1[i],$pivLopposprc1[i],$pivLopposbix2[i],$pivLopposprc2[i])style(dottedline)coloured("green")
    endif
    //---------------------------------
    
    if $pivHwickyType[i]=1 then
    drawtext("SFT▼",$pivHopposbix2[i],$pivHopposprc2[i]+0.25*tr)coloured("RED")
    drawsegment($pivHswingbix1[i],$pivHswingprc1[i],$pivHswingbix2[i],$pivHswingprc2[i])style(line)coloured("red")
    drawsegment($pivHopposbix1[i],$pivHopposprc1[i],$pivHopposbix2[i],$pivHopposprc2[i])style(dottedline)coloured("red")
    elsif $pivHconfirmed[i]=1 then
    drawtext("SFT",$pivHwickybix1[i],$pivHwickyprc1[i]+0.35*tr)coloured("RED")
    drawtext("▼",$pivHopposbix2[i],$pivHopposprc2[i]+0.25*tr)coloured("RED")
    drawsegment($pivHswingbix1[i],$pivHswingprc1[i],$pivHswingbix2[i],$pivHswingprc2[i])style(line)coloured("red")
    drawsegment($pivHopposbix1[i],$pivHopposprc1[i],$pivHopposbix2[i],$pivHopposprc2[i])style(dottedline)coloured("red")
    endif
    
    next
    endif
    
    //--------------------------------------------------//
    return
    robertogozzi and Razz thanked this post
    #246883 quote
    AragornaAragorna
    Participant
    Average

    thank you very much, it’s perfect. the code is more complex than I thought. Do you think there is a chance to use vectors ofr automated trading? I tried in the past but I couldn’t develop anything. How do you make a simple strategy on it?

     

    kind regards

     

    Alessio

    #246895 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Arrays can actually be already used in automated strategies.

    #246900 quote
    AragornaAragorna
    Participant
    Average

    Can I please ask an example here how to use it? I’ve developed in general strategies but with arrays I’m still struggling.

    thanks in advance

    #246904 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    You can find some useful links at https://www.prorealcode.com/topic/arrays-help-any-documentation/#post-232284.

    To build an array you don’t need any declaration, just begin using its elements and they will be added automatically. Their name must have a leading “$” and end with their index in square brackets. I usually start initializing them (when I am sure they have a fixed number of elements)  on the very first bar, i.e. bar 0:

    // Initialization of the 10 ARRAY elements
    ONCE MaxElements = 10
    IF BarIndex = 0 THEN
       FOR i = 1 TO MaxElements //you can start from 0, up to MaxElements - 1, if preferred
          $myArray[i] = 0
       NEXT
    ENDIF

    This is an array built at runtime, as I can’t predict the number of elements it may contain. LastSet is used to know the number of elements in the array (https://www.prorealcode.com/documentation/lastset/):

    // check if there's at least a 10-pip GAP between the OPEN and the prior CLOSE
    // (within the first 1K bars), assigning its bar number to an array element
    DEFPARAM DrawOnLastBarOnly = True
    arrayIndex = 0
    FOR i = 0 TO 999      //let's start fromn 0, the current bar
       IF abs(open[i] - close[i + 1]) >= 10*PipSize THEN
          $myArray[arrayIndex] = BarIndex
          arrayIndex = arrayIndex + 1
       ENDIF
    NEXT
    TotalElementsScanned = lastset($myArray) + 1  //add 1 as we started from 0
    DrawText("#arrayIndex# GAPS found over #TotalElementsScanned# bars scanned",BarIndex + 10, close)
    RETURN
    Iván González thanked this post
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

‘Swing Failure Pattern


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Aragorna @aragorna Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by robertogozzirobertogozzi
1 year, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/03/2025
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...