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 Indicator

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

    Swing Indicator

    Hello,

    I am using the Swing indicator and trying to programatically capture the bar at which a Swing begins.

    For instance, say I am looking at a chart and see that 9 minutes ago, a Swing High occurred and lasted for 7 bars (i.e. there are 7 green dots). How do I capture that the Swing commenced 9 bars ago? I just want to retrieve the bar at which the Swing began.

    Thank you.

    Isaac

    #2
    Hello,
    Thanks for posting today.

    This could be done by adapting the code from the Swing indicator, which is included in NinjaTrader, and tracking when the first item is plotted using a Boolean value such as isFirst = true;

    Once this first occurrence has occurred you can change that Boolean to false and no longer receive values that you do not need.

    Once you reset the swing plot you can then also reset your isFirst Boolean back to true so that it will be the first instance when it plots again.

    To adapt this code follow these steps.
    • From the Control Center>Tools>Edit NinjaScript>Indicators>Swing
    • Right mouse click and Save As... rename the indicator to create the custom indicator.
    • Adapt the code to meet your needs
    • Right mouse click and select Compile
    • This custom indicator will now appear in your list of default indicator and can be added to a chart

    Please let us know if we may be of further assistance for anything NinjaTrader.
    Alex G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by ivb73077 View Post
      Hello,

      I am using the Swing indicator and trying to programatically capture the bar at which a Swing begins.

      For instance, say I am looking at a chart and see that 9 minutes ago, a Swing High occurred and lasted for 7 bars (i.e. there are 7 green dots). How do I capture that the Swing commenced 9 bars ago? I just want to retrieve the bar at which the Swing began.

      Thank you.

      Isaac
      The MRO method will help you here.

      Please refer to this thread:



      Edit: Alex and I posted at the same time. Alex has given a very effective method. The one I've suggested is a different approach.
      Last edited by arbuthnot; 05-25-2015, 09:10 AM.

      Comment


        #4
        Thank you.

        Before moving ahead, I wondered if you could provide some more clarity on the arguments taken by the Swing indicator. Specifically,

        barsAgo
        instance
        lookBackPeriod

        I have already seen this link: http://www.ninjatrader.com/support/h...html?swing.htm

        but remain a bit unclear of what the arguments refer to and how to populate them. The strength parameter tells us the number of bars before and after that are required to identify a swing. I am quite unclear as to how the lookbackPeriod works with this.

        Please provide some more detail or refer me to another source.

        Thank you.

        Comment


          #5
          Originally posted by ivb73077 View Post
          Hello,

          I am using the Swing indicator and trying to programatically capture the bar at which a Swing begins.

          For instance, say I am looking at a chart and see that 9 minutes ago, a Swing High occurred and lasted for 7 bars (i.e. there are 7 green dots). How do I capture that the Swing commenced 9 bars ago? I just want to retrieve the bar at which the Swing began.

          Thank you.

          Isaac
          The shipping Swing indicator, more or less directly gives you that information.
          #region Functions
          /// <summary>
          /// Returns the number of bars ago a swing low occurred. Returns a value of -1 if a swing low is not found within the look back period.
          /// </summary>
          /// <param name="barsAgo"></param>
          /// <param name="instance"></param>
          /// <param name="lookBackPeriod"></param>
          /// <returns></returns>
          public int SwingLowBar(int barsAgo, int instance, int lookBackPeriod)
          {...}

          Comment


            #6
            I will play around with it and see if I can get what I need.

            I still am unclear as to what the lookbackPeriod parameter does? Can you please provide some added detail of how this works? Thank you.

            Comment


              #7
              Originally posted by ivb73077 View Post
              I will play around with it and see if I can get what I need.

              I still am unclear as to what the lookbackPeriod parameter does? Can you please provide some added detail of how this works? Thank you.
              This is what the NTHelp says. I am not sure how else it can be explained any more clearly. What is the problem with the statement?
              Attached Files

              Comment


                #8
                Hello ivb73077,
                Thanks for the reply.

                The lookBackPeriod parameter determines how far back you would like to run the test condition.

                In other words, the swing indicator condition is testing on the current bar and then it will test if the condition is true for x number of bars back as indicated by the lookBackPeriod parameter. So if you set it to 5 as your lookBackPeriod, it will test on the current bar and then test on 1 bar back, 2 bars back, 3 bars back... until the 5th bar back is tested to determine if the condition is met.

                Please let me know if that clarifies that parameter definition or if we can offer further clarification or assistance.
                Alex G.NinjaTrader Customer Service

                Comment


                  #9
                  That is a very helpful reply. Thank you.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post Javierw.ok  
                  Started by timmbbo, Today, 08:59 AM
                  2 responses
                  10 views
                  0 likes
                  Last Post bltdavid  
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  41 views
                  0 likes
                  Last Post alifarahani  
                  Working...
                  X