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

Modification of Swing Indicator

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

    Modification of Swing Indicator

    Hi,

    Is it possible to modify the swing indicator, such that it will keep plotting all the swings until the market moves above / below?

    In other words, when a new swing high or low is detected, that just will become a new plot, rather than becoming the new value of the current swing high/low plot.

    And the plots will be removed once they are broken.

    Thanks

    #2
    Hi zaza5000,

    It may be possible. Unfortunately we do not provide custom coding services but hopefully another community member can offer to modify for you.

    If you are interested in tackling this on your own, can edit the existing swing code by clicking Tools > Edit NinjaScript > indicator > Open Swing. From the NinjaScript editor: Right Click > Save As to make a copy.

    If you are interested in having this professionally developed, you may consider a NinjaScript consultant for this:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I am interested in tackling this myself, but I was just seeking advice here, not asking for some1 to do it for me.

      I am just lost on how to start.

      Comment


        #4
        You can start by looking at the code for the default Swing indicator provided in the platform, and then checking into what the programmatic methods provide.

        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          You can start by looking at the code for the default Swing indicator provided in the platform, and then checking into what the programmatic methods provide.

          http://www.ninjatrader.com/support/h.../nt7/swing.htm
          I've done that. There are only 2 plots in this code, swing high and swing low.

          In the indicator that I want to develop, there will be more plots. And the problem is, the number of plots will not be constant as it is in the default swing indicator. This is the part I cannot figure out; how to have multiple plots added/removed withing the onbarupdate function.

          Is there a way to do that?

          Regards

          Comment


            #6
            You will have to look into using DrawLine() instead.

            Dan
            eDanny
            NinjaTrader Ecosystem Vendor - Integrity Traders

            Comment


              #7
              Originally posted by eDanny View Post
              You will have to look into using DrawLine() instead.

              Dan
              Thanks, is there a function to remove the lines drawn by the DrawLine() method when necessary?

              I thought that i would name the lines say 101.50 - the actual level, so it would be easy to remove them when I want in the code by using its name.

              Comment


                #8
                Originally posted by zaza5000 View Post
                Thanks, is there a function to remove the lines drawn by the DrawLine() method when necessary?

                I thought that i would name the lines say 101.50 - the actual level, so it would be easy to remove them when I want in the code by using its name.
                Actually, is there a website with a list of ninjascript functions?

                I somehow cannot find it...

                Thanks

                Comment


                  #9
                  Yes, there is a list of NinjaScript items here:
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks a lot

                    DrawHorizontalLine and RemoveDrawObject functions were what I needed (and toString).

                    Sorry for the inconvenience

                    Comment


                      #11
                      Coding adding part of the lines is easy, but I am having a little trouble with coding the removal of the lines.

                      Each line is tagged with value.toString() function so their names are their actual value.

                      To remove the lines, my idea is to store all high and low values 2 lists of a certain structure that will allow a for loop of the logic below:

                      for every double in [high-list] {
                      if high[0]>value {
                      RemoveDrawObject(value.toString());
                      --and remove this value from the list --
                      }}

                      Could anyone help me how to go about this?

                      Thanks a lot.

                      Comment


                        #12
                        I coded the indicator but its not working properly.

                        I added code into the onbarupdate function such that everytime a new swing high/low of appropriate strenght is found, a horizontal line would be drawn at that level.

                        (lines 146-151 and lines 194-198)

                        Also to the beginning of the onbarupdate function, I added a certain code that will remove the horizontal lines that should be removed.

                        (lines 87-109)

                        But, in any chart that I loaded my indicator (SwingMap), only the first horizontal line is drawn, but the swing plots / rest of the horizontal lines are not drawn (I did not edit any of the rest, I just added my parts).

                        Why could this be happening? Is the code just breaking right after the first horizontal line is drawn (line 146)?

                        I attached my code.

                        I would appreciate any help, thanks a lot.
                        Attached Files
                        Last edited by zaza5000; 03-18-2011, 09:59 AM.

                        Comment


                          #13
                          zaza5000, unfortunately we could not debug the custom code for you - I suggest you cut it down to the bare essentials working for you and then start to add more complexity to it to see exactly where your logic breaks - http://www.ninjatrader.com/support/f...ead.php?t=3418
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_Bertrand View Post
                            zaza5000, unfortunately we could not debug the custom code for you - I suggest you cut it down to the bare essentials working for you and then start to add more complexity to it to see exactly where your logic breaks - http://www.ninjatrader.com/support/f...ead.php?t=3418
                            OK, I figured the problem in the code, it is where I try to remove the lines:

                            int k=counth-1;
                            while (k>=0) {
                            x=(
                            double)(highs[k]);
                            if (x<High[0]) {
                            RemoveDrawObject(x.ToString());
                            highs.RemoveAt(counth);
                            k--;
                            counth--;
                            }
                            else k=-1;
                            }

                            With this while loop, I am trying to remove swing highs that are smaller than High[0].

                            highs is an ArrayList, and when a line is drawn, the double value is put into the ArrayList, and then the ArrayList is sorted (no trouble in the code there).

                            When I comment out this part of the code, I just have all of the lines (since non are removed), and when I have this code, it draws the first line, and then the code obviously breaks when it tries to go through this loop for the first time.

                            So I think the problem may be with the casting line:

                            x=(double)(highs[k]);

                            All the values stored in highs are doubles, but from it's nature ArrayList has objects in it.

                            Is there a way to have a list that is double?
                            Last edited by zaza5000; 03-18-2011, 11:03 AM.

                            Comment


                              #15
                              Unfortunately Arrays and Lists are outside of the scope we can support here - I don't think you would need the cast here.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by geddyisodin, Today, 05:20 AM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Max238, Today, 01:28 AM
                              3 responses
                              31 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by timko, Today, 06:45 AM
                              2 responses
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by habeebft, Today, 07:27 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post habeebft  
                              Started by Tim-c, Today, 03:54 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X