Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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?

    Paul H.NinjaTrader Customer Service

    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
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        27 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 04-23-2024, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        193 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,235 views
        0 likes
        Last Post xiinteractive  
        Working...
        X