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

Identifying Swings

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

    Identifying Swings

    I am new to NinjaScript.

    I wish to identify a higher low in a falling market. For example:

    if(SwingLow(5)[1] > SwingLow(5)[2]));

    Is there some way to identify the last instance quicker than by it’s strength (number of bars before and after)? Even risking a false turn.?

    I have seen reference to using ticks etc but I can’t find any example.

    #2
    Hello,

    Since SwingLow() should return a data series, you should be able to use HighestBar() and LowestBar() to find the highest and lowest bar in the data series. You can then save the bar number in a variable, and update the bar number if HighestBar() or LowestBar() returns a new number on future calls to OnBarUpdate().

    For more information on HighestBar() and LowestBar(), please see the links below:
    http://www.ninjatrader.com/support/h...highestbar.htm
    http://www.ninjatrader.com/support/h...?lowestbar.htm

    Please let me know if I can assist further.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Thanks Dave, I will give that a try!

      Comment


        #4
        Dave, I understand your suggestion and am trying to learn enough to carry it out.
        I found example in the help file how to assign a variable to dataseries and initialize same but I have no idea and can find no example for getting SwingLow to return a dataseries. Can you give me nudge here? Thanks.

        Comment


          #5
          Hello,

          I may have been mistaken about SwingLow() returning a dataseries. Is this a custom indicator that you are using, or are you using Swing().SwingLow[]?
          Dave I.NinjaTrader Product Management

          Comment


            #6
            Your question gave me an idea to explore. I will get back to you.

            Comment


              #7
              Am back after trying to learn some more from various sources.

              My project is to identify a swing higher low in a falling market (and vice versa).
              Sounds easy but I am having trouble just getting started.

              I have set up a custom indicator with the indicator wizard.

              When I say identify I mean an audio alert and drawn signal at time of the turn up of the higher low but the signal drawn back at the actual low point. (So I can see the picture better). A line drawn from the higher low point to the previous swing low would be even better but I would settle for an arrow or such at the actual higher low. So my first step is to try to identify this point

              Perhaps there is a better way but I assume I will need both price value and index of this low to draw a signal at the actual low point.

              So to get the index:

              The Swing() in the following code line I assume is taking dataseries from the indicator Swing and SwingLowBar returns the index of the low point of the swing.

              Swing(5) . SwingLowBar(0,1,20);

              My question (which shows my novice state) is how to make this index number into a variable such a “lowSwing1index”

              Could you help with this first step?

              Comment


                #8
                Hello,

                In the Swing indicator, SwingLowBar and SwingHighBar will return an int, and SwingHigh and SwingLow will return a double. Thus, you can assign the return value of each of these to a variable of that type, like so:

                Code:
                int swingHighBar;
                
                double swingHighVal;
                
                   protected override void OnBarUpdate()
                        {
                			swingHighBar = Swing(x).SwingHighBar[y];
                			
                			swingHighVal = Swing(x).SwingHigh[y];	
                        }
                We have some good resources to use as a starting point when learning C# fundamentals, which you can find at the link below:

                http://www.ninjatrader.com/support/h..._resources.htm

                Please let me know if I can assist further.
                Dave I.NinjaTrader Product Management

                Comment


                  #9
                  Originally posted by Pete77 View Post
                  Am back after trying to learn some more from various sources.

                  My project is to identify a swing higher low in a falling market (and vice versa).
                  Sounds easy but I am having trouble just getting started.

                  I have set up a custom indicator with the indicator wizard.

                  When I say identify I mean an audio alert and drawn signal at time of the turn up of the higher low but the signal drawn back at the actual low point. (So I can see the picture better). A line drawn from the higher low point to the previous swing low would be even better but I would settle for an arrow or such at the actual higher low. So my first step is to try to identify this point

                  Perhaps there is a better way but I assume I will need both price value and index of this low to draw a signal at the actual low point.

                  So to get the index:

                  The Swing() in the following code line I assume is taking dataseries from the indicator Swing and SwingLowBar returns the index of the low point of the swing.

                  Swing(5) . SwingLowBar(0,1,20);

                  My question (which shows my novice state) is how to make this index number into a variable such a “lowSwing1index”

                  Could you help with this first step?
                  Pete - this thread may interest you:



                  esp. post #10.

                  Comment


                    #10
                    Dave, your post on the 2oth got me started and I have gone fairly far with my project but it needs lots of work. I have a question now … How do I designate a variable for use as user input?

                    I have attempted to attach my file.
                    Attached Files

                    Comment


                      #11
                      Hello,

                      I'm glad to hear the project is coming along. To expose a variable, you can create a public property for it. The code in your Properties region for the public ints Length and Strength will accomplish this. If you uncomment that code, or create similar properties for other variables, you should see them exposed in the Indicators or Strategies window for user input.

                      One quick tip -- it is standard practice to create a public property with same name as the variable, but starting with a capital letter. For example, for a private int named var1, you would create a public int named Var1.
                      Dave I.NinjaTrader Product Management

                      Comment


                        #12
                        Thanks Dave, that works!


                        I have another novice question. I would like to add "Low[0] - 10 * TickSize" to my:

                        "DrawTriangleUp("Tag3", true ,swingLow1Index ,swingLow1Val, Color.Black)" statement,

                        to make the triangle more visible but it won't compile. Is there a fix for this? And how would I increase the size of the triangle?

                        Thanks

                        Comment


                          #13
                          I have another novice question. I would like to add "Low[0] - 10 * TickSize" to my:

                          "DrawTriangleUp("Tag3", true ,swingLow1Index ,swingLow1Val, Color.Black)" statement,

                          to make the triangle more visible but it won't compile. Is there a fix for this? And how would I increase the size of the triangle?
                          I think the problem arises with overload #4.

                          I'm assuming that swingLow1Val is a double representing the y-value of a method of yours. But you would need to choose between either this value or Low[0] - 10 * TickSize.

                          Low[0] - 10 * TickSize will give the exact y-value of the triangle so that's all you need and it should compile.

                          Comment


                            #14
                            Thank you arbuthnot. I have trouble understanding how Low[0] establishes the low swing y value, but it works.

                            Meanwhile can you tell me how to increase the size of the triangle?

                            Comment


                              #15
                              Originally posted by Pete77 View Post
                              Thank you arbuthnot. I have trouble understanding how Low[0] establishes the low swing y value, but it works.

                              Meanwhile can you tell me how to increase the size of the triangle?
                              Hi Pete

                              Low[0] - 10 * TickSize is simply 10 pips/points below the low of the latest completed bar (with CoBC = true) - this is independent of any swing value.

                              Of course, instead of Low[0] - 10 * TickSize, you could substitute the y-value of your own method: swingLow1Val.

                              The triangle size unfortunately can't be increased. Please see this thread which has some other useful tips:



                              Cheers,

                              Ed
                              Last edited by arbuthnot; 05-03-2015, 10:36 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Tim-c, Today, 03:54 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Tim-c
                              by Tim-c
                               
                              Started by FrancisMorro, Today, 03:24 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post FrancisMorro  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              10 responses
                              1,771 views
                              0 likes
                              Last Post Leafcutter  
                              Started by Rapine Heihei, 04-23-2024, 07:51 PM
                              2 responses
                              31 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              945 views
                              0 likes
                              Last Post spwizard  
                              Working...
                              X