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

To "swing" or not to "swing..." Need advice...

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

    To "swing" or not to "swing..." Need advice...

    Hello all...

    So far smooth sailing on the new strategy (thanks to your great help and timely answers to my questions)... Now I've had a new idea and I have no idea how to implement it using the wizard.

    I would like for the strategy to place a dot on the chart when there is a swing high in one of the indicator plots.

    So... for example... when the RSI makes a peak... I'd like for the strategy to place a dot on the chart above the corresponding bar.

    I'm guessing I need a user variable.... but I thought I'd come back to the gurus for some more mental go juice and another nudge in the right direction.

    I've tried umpteen times to get the swing indicator to do this... but there must be something missing in my understanding of how to use its data in the wizard.

    So... my mental picture goes something like this: "track the plot of the RSI, and indicate each time it makes a high, indicate it by a dot on the chart."

    Is this done using the swing indicator in the condition builder?

    Thanks in advance!

    -VJ

    #2
    Hi Aurum,

    To clarify, each time the RSI makes a new high you would like to place a dot on that bar, is this correct?

    Would you want this reset at each new session?

    This may not be possible with the Strategy Wizard. The issue is you will need to calculate how many bars to look back for the highest bar and this isn't possible with the wizard.

    The code would be something like:

    Code:
    if (RSI(14, 3)[0] == MAX(RSI(14, 3), Bars.BarsSinceSession)[0])
    DrawDot("myDot", true, 0, High[0]+3*TickSize, Color.Blue);
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB! Thanks for the reply.

      And thank you for the code example. It is very instructive.

      To explain further... what I'd like to do... is during a trading session, have the strategy monitor the movement of an indicator plot (in our example the RSI), and everytime that indicator peaks, leave a dot.

      It's basically what the "swing" indicator does using a line of dots, but in my case, I'd like to use just a dot above the bar where the highest point was reached on the indicator. That's why I've been toying with the "swing" indicator, because I thought I could work something out with that. I was trying to find a way to feed the output of the RSI's line, into the swing indicator. So I would load the swing indicator... and then I'd use the RSI as the input for the swing indicator, trying to get the swing indicator to somehow report the high and low swings in the RSI indicator line. No luck!

      Since I may have to actually code this from scratch... I do have a related question. Would it be possible to program an indicator, and then call that indicator using procedures available to me in the wizard?

      For example... if I borrow your code example and build an indicator which does what I need it to do, can I then use that indicator as the trigger for actions inside the "wizard built" strategy? Let's say I need for some action to take place when that dot appears. Is there a way to then tell the strategy, using the wizard: "hey... if that indicator leaves a dot... do this command.." Is this possible?

      As you can see.... regarding the strategy, I'm trying to stay in the wizard as much as possible, because as soon as I unlock that code... I'm in over my head. :-)

      I suppose I could make a copy of it and tinker with the copy... now there's an idea!

      Thank you again!

      -V
      Last edited by Aurum; 07-02-2014, 05:30 PM.

      Comment


        #4
        Hi Aurum,

        It would be possible to use the RSI as the input series for the Swing indicator.

        To do this, add the Swing indicator, then in the parameters click the value for Input series -> click the ellipses button that appears -> in the Input Series window click the plus to expand Indicators -> select the RSI indicator -> click OK -> click OK.

        That said, the Swing indicator does not do quite what you are describing. The swing indicator looks for swings not for the highest high or lowest low of the session..
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi ChelseaB! Thanks again for the reply.

          Actually... the swing indicator may be just what I'm looking for... however, I'm not sure how to implement it to get the results I seek.

          Just to further clarify, I'm actually wanting to mark on the chart (above the corresponding bar) whenever the RSI's oscillating line makes a high or a low. it doesn't have to be the high of the day, or the low of the day. The swing indicator seems like it should work for this, since all I'm looking for are the swings (any swings). So, let's say I want to use the swing indicator... if I use the swing indicator, and feed it the input of the RSI, how do I then get the strategy to put a dot over the corresponding bar in the main panel of the chart?

          In the wizard, where I get stuck, is not knowing where to go after I select the indicator in the left column and add the RSI as its input. I have no idea what to do with the right column.

          I'm looking for a way to say: "If the RSI's line makes a new swing... put a dot above the corresponding bar on the chart's main panel." The swing indicator already does this over its input (in this case, it puts a line of dots over the RSI's line, if overlayed on the RSI's panel). I'm basically looking for the strategy to see this connection, and when it happens, paint a dot above the corresponding bar in the main window.

          So... my "if" statement is: "Swing(RSI()) == true." My "then" statement is: "put a dot above the corresponding bar on the main panel of the chart."

          Is the direction of my logic correct here? If so... would I need a bool or variable to accomplish what I'm after?

          Thanks for your suggestions and recommendations. They're really helping me hone in on better ways to use NinjaScript. Much appreciated.

          -VJ

          Comment


            #6
            Hi Aurum,

            I have a modified swing indicator that can assist with this.

            This allows you to call the values that are plotted with the SwingHighPlot plot and SwingLowPlot plot.

            To use this, use RSI as the input, and check to see if the SwingHighPlot of the current bar is not equal to the SwingHighPlot of the previous bar. If they are not equal we have a new high swing.
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello again ChelseaB!

              Thanks for the reply, and for the modified swing indicator. I can see from looking at the code I'm going to learn a lot from this one.

              I got an error screen pop-up when I tried to direct the output of the RSI into the input of the modified swing. I tried it twice (thus the two screenshots). After I clicked on the "abort" button at the bottom of the pop-up screen, NinjaTrader shut down automatically. There are no error messages in the log. Not sure what's going on here. It's a bit freaky.

              I've attached the graphics.

              Can't wait to get this working! You're a superstar (or an NSA mole... nyuk, nyuk)!

              -V

              Click image for larger version

Name:	SwingModifiedBug.PNG
Views:	1
Size:	101.6 KB
ID:	870746

              Click image for larger version

Name:	SwingModifiedBug2.PNG
Views:	1
Size:	116.4 KB
ID:	870747
              Last edited by Aurum; 07-03-2014, 07:02 PM.

              Comment


                #8
                Hi Aurum,

                Are you connected to a data provider?

                Who is your data provider?

                If you restart NinjaTrader and run the strategy again (while connected to a data provider) is the crashing consistent?

                Does the regular Swing indicator with the RSI as the input work ok within a strategy?

                May I have a screenshot of the condition you have made in the strategy?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello again ChelseaB!

                  If you're in the US, Happy Independence Day! Thank you for taking the time today to reply to my post!

                  The error I mentioned only occurs when I try to load the indicator into a chart and attempt to use it as a regular indicator (just like I would with the normal swing indicator).

                  It's not giving me that error from within the strategy, just when I try and load it on a chart with the RSI as its input.

                  When I load it into the strategy, I don't get any output whatsoever. Here's my procedure in the wizard. Maybe I'm missing something in the procedure itself, and that's the reason I'm not getting any output to the chart as expected.

                  1. I open the wizard and in the conditions panel, I select "add."
                  2. In the left column, I select SwingModified.
                  3. As the InputSeries, I select RSI(21,3).Avg
                  4. The Plot is SwingHigh, so I leave it as is.
                  5. I set the "Bars ago" setting to "0".

                  On the middle divider bar, I select "!="

                  I then go to the right column, do the same thing I did in the left column... only in this instance, I set the "Bars ago" setting to "1".

                  In the actions section... I tell the strategy to draw a dot above the current bar where this condition is true.

                  When I reload the NinjaScript... there's no output on the chart. No dots have been drawn above the current bar. By the way... I also have an RSI indicator on the chart so I can see where those swings are occurring and know where to expect the dots.

                  Am I banging the nail with the wooden and of the hammer?

                  Thanks again!!!

                  -V

                  Comment


                    #10
                    Hi Aurum,

                    You are correct about the crash, I got that as well.

                    The strategy enables though which is odd...

                    I'm looking into it.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you, ChelseaB.

                      Okay... so you got the crash also... good to know. I was hoping it wasn't some sort of misconfiguration on my end.

                      I look forward to the updated version of the code. Thank you again, very much!

                      -V

                      Comment


                        #12
                        Hi Aurum,

                        I've fixed the script so that it doesn't cause a crash...

                        Use the LowSwing and HighSwing plots instead of SwingHighPlot and SwingLowPlot plots.

                        However, while doing so I noticed that the values returned are not what I was expecting.

                        The Swing indicator does resets and also sets some values historically after the bar is already past.

                        When new swing is detected, it doesn't plot the price of the swing until a few bars later, and then it goes back and resets the price for those past bars.

                        This means on a new swing, the close price is returned on the bar instead of the new swing level. A few bars later this is corrected to the new swing level.

                        This would make using this a bit harder. I am still looking in to this but in the meantime you can use this to try and set this up.
                        Attached Files
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hey ChelseaB!

                          This is excellent. I will give it a whirl. What you're describing as the way the indicator calculates may actually work perfectly fine for what I'm trying to do. I'll give it a go and see what works out.

                          If you come up with further thoughts, please share them. I'd be highly interested in hearing more about the inner-workings of this indicator and what its possibilities may be with regard to strategy creation.

                          Thank you again!

                          -V

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Carolscogginsi, Today, 10:45 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post Carolscogginsi  
                          Started by RaddiFX, Today, 10:15 AM
                          2 responses
                          14 views
                          0 likes
                          Last Post RaddiFX
                          by RaddiFX
                           
                          Started by patrickmlee007, Today, 09:33 AM
                          2 responses
                          18 views
                          0 likes
                          Last Post patrickmlee007  
                          Started by magnatauren, 08-15-2020, 02:12 PM
                          5 responses
                          206 views
                          0 likes
                          Last Post RaddiFX
                          by RaddiFX
                           
                          Started by rene69851, 05-02-2024, 03:25 PM
                          1 response
                          23 views
                          0 likes
                          Last Post rene69851  
                          Working...
                          X