Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Lowest Swing value in last 20 bars

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

    Lowest Swing value in last 20 bars

    I'm trying to create a strategy which calculates if the current swing high value is the lowest swing high value in the last 20 bars. Strength is at 1

    I tried adding
    Code:
    (Swing1.SwingHigh[1] == LowestBar(Swing1.SwingHigh, 20)
    but that does not work.

    Any suggestions? Thanks
    Last edited by Ousher; 05-26-2021, 02:09 AM.

    #2
    Hello Ousher,

    Thanks for your post.

    Are you working with Ninjascript or with the Strategy Builder?

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello Ousher,

      Thanks for your post.

      Are you working with Ninjascript or with the Strategy Builder?
      Hi Paul,

      I started off with Strategy Builder but will have to go with Ninjascript after as my code involves Order Flow. So either one works for me

      Comment


        #4
        Hello Ousher,

        Thanks for your reply.

        I would suggest using Ninjascript in this case as you need to iterate through the swing "instances" in the last 20 bars. Ninjascript Swing gives you the ability to look for both the value and the bar.

        With Swing you are able to specify the bars look back as well as an "instance" of a swing within that lookback period. An instance of 1 will find the latest swing, 2 will find the one before that, 3 would be before that and so on. If an instance does not exist, the method will return a -1 value.

        Here is an example of searching through the last 20 bars for upto 20 instances which you likely will never hit 20. when it hits a -1 it will "break" out of the loop.

        for (int j = 1; j < 20; j++)
        {
        if (mySwing.SwingHighBar(0, j, 20) != -1)
        {
        Print (Time[0] +" j = "+j+" "+mySwing.SwingHighBar(0, j, 20));
        }
        else
        {
        Print ("Break at: "+j);
        break;
        }
        }

        The SwingHighBar method returns the "Bars ago" that the instance occurred.

        You can test the code as is and observe the New>Ninjascript output window and compare the results with what is on the chart (make sure to add the swing(1) to help visualize. From this you should get some ideas to move forward with.

        You may want to review the Swing method here: https://ninjatrader.com/support/help...lightsub=swing

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        65 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        139 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X