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

Will this work?

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

    Will this work?

    I want to have one stoploss and multiple targets when I place an order. So will this logic work and manage the stop and targets for me (with OCO):

    SetStopLoss(CalculationMode.Ticks, 10);
    SetProfitTarget("Entry 1",CalculationMode.Ticks, 5)
    SetProfitTarget("Entry 2",CalculationMode.Ticks, 10)
    SetProfitTarget("Entry 3",CalculationMode.Ticks, 15)
    SetProfitTarget("Entry 4",CalculationMode.Ticks, 20)
    EnterLongStop(0, true, 1, 100.05, "Entry 1");
    EnterLongStop(0, true, 1, 100.05, "Entry 2");
    EnterLongStop(0, true, 1, 100.05, "Entry 3");
    EnterLongStop(0, true, 1, 100.05, "Entry 4");

    So when this long order triggers at 100.05, I expect there to be one stoploss for 4 contracts at 99.95, and 4 targets at 100.10 for 1, 100.15 for 1, 100.20 for 1 and 100.25 for 1. As each target is hit, I expect the number of stoploss contracts to decrease for each target hit. If all targets are hit, the stoploss order is cancelled. If the stoploss is hit, all remaining target orders are cancelled.

    Thanks!
    Bryan
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Hello cassb,

    Thanks for your post.

    Yes, it will work. I've created a short video on how you can test this for yourself: http://screencast.com/t/BPIBBRLLPiF
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      That's awesome, thank you Paul! It seemed so simple but I have run into problems with multiple stops/targets before, so I just wanted to ask first this time.

      Take care,
      Bryan
      cassb
      NinjaTrader Ecosystem Vendor - Logical Forex

      Comment


        #4
        Originally posted by NinjaTrader_Paul View Post
        Hello cassb,

        Thanks for your post.

        Yes, it will work. I've created a short video on how you can test this for yourself: http://screencast.com/t/BPIBBRLLPiF
        Paul, do you still have your strategy set up? If so, can you enter these orders and test it?

        EnterLongStop(0, true, 34, 100.05, "Entry 1");
        EnterLongStop(0, true, 33, 100.05, "Entry 2");
        EnterLongStop(0, true, 33, 100.05, "Entry 3");

        When I do this in my strategy with the above targets set, I get

        18 contracts at 100.10, 16 at 100.09
        18 at 100.15, 15 at 100.14
        18 at 100.20, 15 at 100.19.

        I would expect 34, 33 and 33 at each target. Is there some reason internally to NT that it won't put more than 18 contracts at one price?

        Thanks!
        Bryan
        cassb
        NinjaTrader Ecosystem Vendor - Logical Forex

        Comment


          #5
          Hi Bryan,

          Thanks for your post.

          Do you have the entries per direction set to allow for that many contracts?
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Paul View Post
            Hi Bryan,

            Thanks for your post.

            Do you have the entries per direction set to allow for that many contracts?
            Entries Per Direction is set to 4, because I want to allow a total of 4 profit targets.

            Bryan
            cassb
            NinjaTrader Ecosystem Vendor - Logical Forex

            Comment


              #7
              Hi Bryan,

              Thanks for your reply.

              Yes, entries per direction would need to be 4.

              Is "set order Quantity" set to "by strategy"?

              Do you see any error messages in the "log" tab of the control center that relate to the strategy?
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Yes, it's set to by strategy. I attached a screen shot of the settings.

                Thanks!
                Bryan
                Attached Files
                cassb
                NinjaTrader Ecosystem Vendor - Logical Forex

                Comment


                  #9
                  Hi Bryan,

                  Thanks for your reply.

                  I can see I misread your post. I didn't see that you were getting partial fills and thought you were only getting 18 contracts filled. The partial fills would be because of the simulation engine trying to simulate a live environment where that many contracts might not get filled at once. You can change the behavior in Tools>Options> and in the simulator tab select "Enforce immediate fills".
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    I don't think it's that setting, because it's not filling anything -- it's just placing BuyToCoverLMT orders. But I did check that box and tried again -- it still is placing 6 limit orders for the profit targets and not 3 like I expect.

                    Bryan
                    Attached Files
                    cassb
                    NinjaTrader Ecosystem Vendor - Logical Forex

                    Comment


                      #11
                      Hi Bryan,

                      For me to assist further I will need more detail. Please post the strategy you are using and advise what instrument and time frame you are testing your strategy on.

                      Alternatively, please feel free to send in the strategy to PlatformSupport[at]NinjaTrader[dot]com in the subject line put Atten: Paul and a link to this thread.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        I am not allowed to share the source code. But if you were able to test in your strategy and it works OK with 100 contracts, then I will assume it's a bug in my code and see if I can figure it out.

                        Thanks!
                        Bryan
                        cassb
                        NinjaTrader Ecosystem Vendor - Logical Forex

                        Comment


                          #13
                          Paul, I am still at a loss as to why the magic number 18 is happening. No matter how many profit targets I set, if there are more than 18 contracts per entry, then the profit target limit orders will always create one order for 18 contracts, and another order 1 tick less for the rest of the contracts.

                          SetProfitTarget("Entry 1",CalculationMode.Ticks, 20)
                          EnterLongStop(0, true, 19, 100.05, "Entry 1");

                          This is creating 18 contracts at 100.25 and 1 contract at 100.24. This appears to be code that's running internally in NT, so I'm not sure why it's happening. Can you try an order with your strategy for more than 18 contracts per position and see if it does the same thing? I am using the latest copy of NT v7.

                          Thanks!
                          Bryan
                          cassb
                          NinjaTrader Ecosystem Vendor - Logical Forex

                          Comment


                            #14
                            Hello Bryan,

                            Thanks for your reply.

                            Here is a video of what you asked for: http://screencast.com/t/FjgYxqqC
                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Paul View Post
                              Hello Bryan,

                              Thanks for your reply.

                              Here is a video of what you asked for: http://screencast.com/t/FjgYxqqC

                              OK, so it works for you. I am baffled then about why 18 is some magic number that the SetProfitTarget code decides to use. I will look at my trace and log files and see if I can find something there.

                              Bryan
                              cassb
                              NinjaTrader Ecosystem Vendor - Logical Forex

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NRITV, Today, 01:15 PM
                              2 responses
                              6 views
                              0 likes
                              Last Post NRITV
                              by NRITV
                               
                              Started by frankthearm, Today, 09:08 AM
                              7 responses
                              31 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              5 responses
                              26 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by quantismo, Yesterday, 05:13 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post quantismo  
                              Started by adeelshahzad, Today, 03:54 AM
                              5 responses
                              33 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X