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 and strategy builder

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

    Swing indicator and strategy builder

    Hi,

    I would like to know why the strategy builder is not plotting anything:

    The idea is to plot an up arrow when the price crossabove (or is higher) the swinghigh. I have changed the bars ago in the swinghigh to 2 but nothing happens??

    Click image for larger version

Name:	graph.png
Views:	1751
Size:	16.1 KB
ID:	1077616


    Can you help me and tell me what I'm doing wrong?

    Thanks a lot,
    Miguel
    Click image for larger version

Name:	plot condition.png
Views:	1415
Size:	112.3 KB
ID:	1077615




    #2
    Hello aprendiz,

    Thanks for your post.

    Regarding the arrows (and draw objects in general), by default you would only see the latest occurrence of the arrow. As an arrow is drawn, the previous one is automatically erased from the chart (to conserve resources). If you want to see all occurances of the arrows, you would need to change the "tag" name to make it unique for each new arrow. Also, you have not provided a price level (Y) to plot the arrow at so the arrow if drawn would be at the price level of zero. Here is a short video on how to overcome both of these: https://paul-ninjatrader.tinytake.co...MF8xMTMwNTc0MA

    I would suggest reducing the conditions to just one, looking to see if the High of the price crosses above the swing High of the current bar[0]. Please note that the Swing Indicator's swing high (or swing low) are not changed to the current values until the "strength" number of bars have passed. This can be confusing because it draws the dots back to the swing points but only draws them after in this case 4 bars have passed.

    I've attached an example screenshot that may help.

    Click image for larger version

Name:	aprendiz-1.PNG
Views:	1416
Size:	54.3 KB
ID:	1077633
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks a lot Paul.

      I’ll try everything later.

      The short vídeo is great. Would be posible to see more similar vídeos?

      Comment


        #4
        Hello aprendiz,

        Thanks for your reply.

        Here are others I have created relative to the strategy builder:

        Adding and accessing other time frames in the strategy builder https://Paul-ninjaTrader.tinytake.co...MF8xMTY0NTQyMw

        Debugging a strategy builder created strategy with print statements: https://paul-ninjatrader.tinytake.co...NV8xMDk5MDc5Nw

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thank you again.

          Where can I find videos of entry and exit orders in the strategy builder? Or a good and extend guide with examples?

          Comment


            #6
            Hello aprendiz,

            Thanks for your reply.

            The only other references I can provide are:

            Help Guide: https://ninjatrader.com/support/help...gy_builder.htm

            Free on-line training on the strategy builder: https://ninjatrader.com/PlatformTraining (Strategy builder is every other Thursday, alternating weeks with the Ninjascript webinar)

            Previous recording of the Strategy Builder webinar: https://www.youtube.com/watch?v=HCyt...We0Nf&index=11

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi again,

              I'm working on entry orders in the strategy builder, but I think that I can not do what I want or at least I can't figure out how to do it.

              I'll try to explain what I want to do:

              As the swing inidicator stablishes swing high and low when strengh number of bars passed, I would like to send the entry orders at that moment. As I know the swinghigh and swing low values, I can set an stop limit entrey order at that moment .They will have to be and OCO orders as I only want to enter a position in just one direction, so If markets goes up, my long entry stop limit order will be filled and my short stop limit order should be cancelled at the same time.

              Then I also want to have for my just opened position another OCO with profit and trailstop orders.

              I hope you will undestand what I mean, as english is not my matern language and is hard to explain it for me.

              Thanks a lot for your help.

              Regards

              Comment


                #8
                Hello aprendiz,

                Thanks for your reply.

                You would not be able to place two entry orders in the opposite direction as this would create a conflict with the Managed Approach "Internal Order Handling Rules that Reduce Unwanted Positions" that the strategy builder and most strategies work under. For clarity, "The Managed approach in NinjaScript is designed to offer the greatest ease of use for beginner to intermediate programmers. The order methods are wrapped in a convenience layer that allows you to focus on your system's trading rules, leaving the underlying mechanics of order management and the relationships between entry orders, exit orders, and positions to NinjaTrader. This approach is best suited for simple to moderate order complexity, and can be further broken down into a Basic/Common Managed approach and a more Advanced Managed approach. " Please see the help guide link for further information as well as the list of internal order handling rules: https://ninjatrader.com/support/help...d_approach.htm

                What you could do is monitor price as it moves relative to the swing high or low and place a market order (or stopLimit)long or a short market (or stop limit) to enter into a position, depending on the price direction. This means you are only placing one order at a time which would not be in conflict. In the Strategy builder's Stops and targets window you can select fixed profit and fixed stop loss and these would be OCO tied to the entry and will automatically set themselves to the correct direction. I recommend using the Ticks values. As you are just learning the strategy builder, I would suggest staying with market orders for now for ease of use and as you develop your strategy you can switch to stop limit or limit orders once you have your entries conditions well confirmed.

                Here is a continuation of the previous example where a buy market order is placed when the High crosses the swing high, it draws a dot on the bar where the condition is true and the order is filled on the next bar (this is using Calculate.OnBarClose and market orders can only be filled on the next bar in that mode). The stops and targets are 5 ticks (not shown) in the screenshot.


                Click image for larger version

Name:	aprendiz-2.PNG
Views:	1425
Size:	66.9 KB
ID:	1077790
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you again.

                  Now I have anothers problems:

                  I figured out how to send the order that is nearest to the Swinghigh or Swinglow value (probably not the best way, but it works), but now the problem is that it keeps sending new orders every candle, sometimes cancels one and then send another identical order, so I think I have to check before sending a new order, if the same order has been sent before and stills alive and also if I have entered the market so no new order will be sent until market gets closer to the other swingside or in the same side gets another price.

                  I also would like to know if I can have more than one profit targets to exit my position. Let's say I entered with 2 contracts and I want to exit one by one in diferents prices.

                  And is posible to reverse one position with the strategy builder?

                  Comment


                    #10
                    Hello aprendiz,

                    Thanks for your reply.

                    You could add as part of the entry conditions, a check to see if you are in a flat market position which would prevent further orders once an entry has been filled.

                    For the multiple stops/targets, yes you can and the way that works is you have to submit individual entry orders and use the "signal names" field to tie the entry to the specific exits. The signal name must match exactly. So this means your would for example have two EnterLongs() each with a different name and two profit targets with the matching names but the different values. You could use a single stop loss without any signal names and it will support both or you could also use two individual stops with the matching names.

                    You would not be able to reverse one of two positions. You can reverse a position by placing an entry order in the opposite direction, the entry method will see that there is a position in the opposite direction and will automatically issue an order(s) to close the position and then place an order to leave you in the intended direction.

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks.

                      I hope you understand which is my problem....

                      I'm trying to detect when each swinghigh and swinglow values change so I can cancel the waiting order in market and send another one with new price.

                      The problem is that I'm detecting it changes after one candle later plus the numer of candles the strengh value from the swing indicator.

                      For example if strengh value for swing indicator is 4, I compare current swinghigh with 5 bars ago swinghigh so I know the value changes. I don't know if I can do it in another way.
                      So if I change the strengh value of the indicator to 6, and I can't make bars ago equal to any variable I won't know if it changes, because it repaints last 6 bars when changes and I'm compairing only 5 bars ago.

                      Any idea how can I solve this?

                      Thanks again.



                      Comment


                        #12
                        Hello aprendiz,

                        Thanks for your reply.

                        If you change the strength setting, you would have to change your code because as you noted it will not accept a variable for Bars Ago. You may want to create copies (save as) of your strategy where you can then configured them for different strength settings and the related bars ago values. I would suggest making sure that the strategy uses the 'Plot on Chart" selection for the particular swing used in the strategy, that way the chart will show the correct strength settings used by the strategy (instead of adding Swing to the chart separately).

                        Alternately, you may want to unlock your code and work directly in Ninjascript where you would have more access to all of the coding which would allow you to use variables for Bars Ago as well as other method overloads for swing. Please note that once you unlock your strategy, you would not be able to work with that strategy in the strategy builder going forward.
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Thank you for your help.

                          I think I'm not ready to unlock code as I'm really new to programing and will be harder to finish my automated strategy, but may be when I have it nearly finished would be a good idea to change a few things.

                          Another question: is posible to know when a boolean variable changes from true to false or to false to true? I think I can't compare the value from one bar ago with current bar.
                          This is because as I only can have one order in one direction waiting in the market, if markets changes direction I will have to change my order direction too. Right now I have a boolean variable that is true when market is closer to the swinghigh value and false when it is closer to the swinglow value. It's ok to send the first order, but I have to know when changes it value to cancel previous order and send new one in the other direction. Is it posible to do it with the strategy builder?

                          And also, is posible to change the price in a sent order instead of cancelling one and sending another when both are in the same direction?

                          Thanks

                          Comment


                            #14
                            Hello aprendiz,

                            Thanks for your reply.

                            " is posible to change the price in a sent order instead of cancelling one and sending another when both are in the same direction?" Yes, just submit using the same order name and the new price and the exiting order would be updated.

                            "Another question: is posible to know when a boolean variable changes from true to false or to false to true?" A bool is either true or false and will only change when your strategy executes and the conditions for it (the bool) to change are true. How often your strategy runs the code depends on strategies Calculate setting. I'm not sure I can answer your question to "when" as your logic, if based on that bool, will either go one way when true or another when false. Perhaps you need additional bools to be true when you have submitted an order so a set could check to see that you have submitted an order (via the bool) and if the original bool is false you could cancel the one order and submit the other way.
                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi again,

                              is posible to set the following value to a variable?

                              Variable = (Swinghigh-Swinglow) * 3 / 7

                              And where can I find info about drawing lines with trhe strategy builder? I don't know how it works

                              Thanks
                              Last edited by aprendiz; 11-19-2019, 08:26 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Segwin, 05-07-2018, 02:15 PM
                              14 responses
                              1,788 views
                              0 likes
                              Last Post aligator  
                              Started by Jimmyk, 01-26-2018, 05:19 AM
                              6 responses
                              837 views
                              0 likes
                              Last Post emuns
                              by emuns
                               
                              Started by jxs_xrj, 01-12-2020, 09:49 AM
                              6 responses
                              3,293 views
                              1 like
                              Last Post jgualdronc  
                              Started by Touch-Ups, Today, 10:36 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post Touch-Ups  
                              Started by geddyisodin, 04-25-2024, 05:20 AM
                              11 responses
                              62 views
                              0 likes
                              Last Post halgo_boulder  
                              Working...
                              X