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

Swing High

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

    Swing High

    Im trying to enter a position only if the most recent swing high is higher than the swing high before that. I thought this would work, but I must be on the wrong track...

    Swing(5).SwingHigh[0]>Swing(5).SwingHigh[1]

    If I add this then it wont enter at all.

    #2
    That line is checking the current bar's swing value with the previous bar's swing value. This is probably not what you want since the current bar's swing high will most likely be the same as the previous bar's unless it just happened to be the place where the swing changed.

    Instead you want to use this syntax:
    Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod)

    An instance of 1 = most recent high. 2 = previous high. Please refer to the Help Guide article on Swing for further examples.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Swing High

      Thanks Josh, the wizard only has Input Series, Strength, Bars Ago and Offset, so I would have to unlock the code to add that then?

      Comment


        #4
        Features beyond the scope of the wizard can be used as you unlock the code.

        Comment


          #5
          Unlock the Strategy

          Ive unlocked it and tried to change the code.
          I was able to add the swing high bar
          Swing(5).SwingLowbar(0,1,20) > Swing(5).SwingLowbar(0,2,100)

          but then got an error saying it isnt defined.

          Currently it looks like this.
          Add(Swing(5));

          Ive tried changing it andwas only able to come up with the following.
          Add(Swing(5).SwingHighBar(0,1,100));

          This gives me a different error though.

          Comment


            #6
            - not sure what you are trying to achieve by adding Swing: Add(Swing..)).
            - it always helps as you post exact and complete error messages on your reports
            - note the capitalization of your NS code
            Swing(5).SwingLowBar(0,1,20) > Swing(5).SwingLowBar(0,2,100)
            - I suggest using the editor intellesense to verify the correct spelling of NS methods

            Comment


              #7
              Capitilization

              Dierk, Thanks, I went back and checked it. Seems the capitalization was where I had gone wrong.

              Comment


                #8
                Ive managed to get the code right (well at least it verifies)

                && Swing(5).SwingLowBar(0,1,20) > Swing(5).SwingLowBar(0,2,100))

                The above filter is for a Long entry, the theory behind it a new HL is required before taking a long position.

                && Swing(5).SwingHighBar(0,1,100) < Swing(5).SwingHighBar(0,2,100)
                for a short entry

                However after applying it, it doesnt seem to be having the desired effect.
                (I would post a chart to show what I mean except Im not sure how.)
                It still enters short even after a HH has been made and most of the long entries have dissappeared completely.

                Comment


                  #9
                  For your lookback parameter try just using CurrentBar. That way it will just look all the way back to the beginning of the chart.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    I would like to enter a position if the close is below the most current Swing Low. Would the following code be correct?

                    if (Close[0] < Swing(5).SwingLow[0])
                    {
                    EnterShort(DefaultQuantity, "");
                    }

                    Comment


                      #11
                      I believe that woudl be correct but to confirm, I suggest print out values to the Output window and correlate to the chart to ensure it is what you expect...

                      Print(Swing(5).SwingLow[0]);
                      RayNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by fx.practic, 10-15-2013, 12:53 AM
                      5 responses
                      5,404 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Started by Shai Samuel, 07-02-2022, 02:46 PM
                      4 responses
                      95 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Started by DJ888, Yesterday, 10:57 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by MacDad, 02-25-2024, 11:48 PM
                      7 responses
                      159 views
                      0 likes
                      Last Post loganjarosz123  
                      Started by Belfortbucks, Yesterday, 09:29 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post Belfortbucks  
                      Working...
                      X