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 pechtri, 06-22-2023, 02:31 AM
                      10 responses
                      124 views
                      0 likes
                      Last Post Leeroy_Jenkins  
                      Started by judysamnt7, 03-13-2023, 09:11 AM
                      4 responses
                      59 views
                      0 likes
                      Last Post DynamicTest  
                      Started by ScottWalsh, Yesterday, 06:52 PM
                      4 responses
                      36 views
                      0 likes
                      Last Post ScottWalsh  
                      Started by olisav57, Yesterday, 07:39 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post olisav57  
                      Started by trilliantrader, Yesterday, 03:01 PM
                      2 responses
                      22 views
                      0 likes
                      Last Post helpwanted  
                      Working...
                      X