Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw fib retracement using swing indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Draw fib retracement using swing indicator

    I have this bit of code that outputs swing highs and lows. Everything works fine when strength is set to 10 and 20. If I set the strength to 50, I get this error and the strategy shuts down. Testing is currently being done on live data.

    #2
    Hello jableshank,

    Thank you for your post.

    The first thing I would suggest is printing the value of LowBarsAgo right before you try to print Low[LowBarsAgo - what do you get printed for this value?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Hi Kate,
      Thanks for your reply. in the attached photo, the value can be seen where it says "occurred x bars ago"

      Comment


        #4
        Hello jableshank,

        Thank you for your reply.

        To clarify, we want to try printing that LowBarsAgo value before that "The low at" print so we know what it is before using it as the bars ago to retrieve the low from. If that's coming out to a negative number, since SwingLowBar returns a value of -1 if a swing point is not found within the look back period, and you try to use that to get the Low of a bar in the future that doesn't exist yet, you're going to get an error. If you print that value do you see it printing -1 just before the error occurs?

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Print(Swing(50).SwingLowBar(0, 1, 1000)); is returning -1. However Print(Swing(20).SwingLowBar(0, 1, 1000)); returns 41. I'm not too sure why that is as I can set the Swing indicator strength to 50 on the chart and it clearly shows the highs and lows.

          Comment


            #6
            Hello jableshank,

            Thank you for your reply.

            The greater the Strength value the longer it looks back to find a swing low/high, but the swings also last longer the higher the strength. If you add a Swing set to 50 to a chart, you'll see these really long swing plots - it's simply more unlikely that both a swing high or low will be found in that period. I would suggest printing something else if no swing is found, perhaps just a message saying "no swing low found" or something to that effect. But you'll have to check what those BarsAgo values are before printing them or every time no swing low or swing high is found you'll get this error.

            Please let us know if we may be of further assistance to you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            89 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            135 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            68 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            119 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            69 views
            0 likes
            Last Post PaulMohn  
            Working...
            X