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

SetStopLoss and ExitLongLimit

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

    SetStopLoss and ExitLongLimit

    I have read through the documentation on internal order handling and am still a little confused. I am trying to use the managed approach, with a setstoploss and I'm calling an exitlonglimit inside OnExecution (of an entry). With my criteria for setstoploss and exitlonglimit, they could never happen simultaneously.

    Question 1: Based on the documentation I believe I cannot have a static setstoploss order and an exitlonglimit order occurring simultaneous, correct?

    Question 2: Is there a way to accomplish this within the managed approach, somehow setting when one is executed, the other is automatically cancelled? Or calling the setstoploss within the OnExecution of the entry?

    Question 3: If not possible, what would be the best way of accomplishing having a stoploss and exitlong limit?

    #2
    Hello wallabee13,
    Thanks for your post and I am happy to assist you.

    1 - Yes correct. If SetStopLoss is in place you cannot place ExitLongLimitorders.

    2 & 3 – Simply reassign the SetStopLoss again. Please refer to this sample code for further reference http://ninjatrader.com/support/forum...ead.php?t=3222

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thanks for that, but I am still having problems with it. It works before any position are entered (when stoploss has not been called yet in OnBarUpdate). Then when a second position attempts to enter I get an object reference not set to instance of object for my exitlonglimit.

      I have a print command to determine if myLongExitOrder1 is null for debugging purposes, which does print.

      protected override void OnExecution(IExecution execution)
      {
      if (myLongEntryOrder1 != null && myLongEntryOrder1 == execution.Order)
      {
      Print(execution.ToString());
      Print("Entry 1 Filled");
      myLongEntryOrder1 = null;
      Print("Entry 1 null");

      if(myLongExitOrder1 == null)
      {
      Print("Exitisnullandentereing");
      myLongExitOrder1 = ExitLongLimit(0,true,DefaultQuantity,(Low[0] + (tickRange+1)*TickSize),"MyLongExitOrder1","My Long Entry Order 1!!!");
      Print("placingLongExitOrder at " + myLongExitOrder1.LimitPrice + ToTime(Time[0]));
      Print(myLongExitOrder1.ToString());
      }
      }


      Here is the output window:

      "Execution='f17e61d3fde245d19ea86b50de62c9e5' Instrument='ES 03-12' Account='Replay101' Name='My Long Entry Order 1!!!' Exchange=Default Price=1218 Quantity=1 Market position=Long Commission=1.1 Order='781ae9b50ad14257a23dc323c5ae20ab' Time='12/14/2011 8:50:44 AM'
      Entry 1 Filled
      Entry 1 null
      Exitisnullandentereing
      **NT** Error on calling 'OnExecution' method for strategy 'BlackBarManagedLongs2/8c512878c6fa4f769d490f5045516597': Object reference not set to an instance of an object."

      Comment


        #4
        Hello wallabee13,
        Please check for null orders in your code. For example.
        Code:
        protected override void OnExecution(IExecution execution)
        {
          If (execution.Order == null)
          {
        	//do stuffs or return
          }
           //do rest of the stuffs
        }
        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          That's exactly what
          "if(myLongExitOrder1 ==null)
          { //stuff"
          is there for. Is that syntax wrong?

          It enters the logic, prints "exitisnullandentereing" and then comes up with an error that myLongExitOrder1 is not null.

          Everything worked perfectly before I tried to add the setstoploss order. It's something with the stoploss. Is there a way to declare "SetStopLoss==null;"?
          Last edited by wallabee13; 02-03-2012, 01:06 PM.

          Comment


            #6
            Ok, Sorry. There's nothing wrong with the stop loss. It's something about calling the print statements after the exitlong entry. Thanks for the help. Will continue to work on it.
            Last edited by wallabee13; 02-03-2012, 01:45 PM.

            Comment


              #7
              Well, after a second run on it, it is still coming up with the same problem. After the first time a setstoploss and a exitlonglimit are set, the exitlonglimit does not get triggered again in the code posted previously.

              There is no error, it just never gets set again.

              Comment


                #8
                Hello Wallabee13,
                Once a SetStopLoss is set it cannot be undone, i.e. for the subsequent entries, you cannot use ExitLongLimit() orders. You have to use the Set orders only.

                As such, if you wish to use exit limit orders, then don’t use Set orders, replace Set orders with ExitLongStop for the first case.

                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Thanks very much, Joydeep. I’ve had to a look at the ‘SampleMACrossover’ strategy and at the Managed Approach page. I’ve taken some time studying both of these in some detail.

                  But I wonder if you could answer this question: could you kindly explain how the Managed Approach to strategies differs from those which are worked out using the Strategy Wizard alone?

                  Looking at the code for ‘SampleMACrossover’, it must very similar to one for the same strategy worked out with the Wizard alone. If there is a difference, could you kindly point it out?

                  Again, much obliged in advance for your reply.

                  Comment


                    #10
                    Hello arbuthnot,
                    Thanks for writing in and I am happy to assist you.

                    The strategy wizard uses the Managed approach only to submit the orders.

                    Strategy Wizard is mainly for users who not have coding experience and want a simple interface to construct their strategies.

                    Code wise there is no difference whether you code your strategy via the Strategy wizard or code it via the NinjaScript editor using Managed approach.

                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks again, Joydeep. It was obvious that I posted my last reply in the wrong thread! This won't be the first time this has happened, I'm sure.

                      Anyway, I'm only a novice at coding but I'll try to get to grips with the Managed Approach.

                      Comment


                        #12
                        Hello Arbuthnot,
                        The main difference between managed approach and unmanaged approach is that with the former (i.e. managed approach) NinjaTrader takes care of the bells and whistle that might affect an order. With Unmanaged approach you have to take care of everything.

                        Please go through our help guide to get more idea on managed approach http://www.ninjatrader.com/support/h...d_approach.htm

                        Please let me know if I can assist you any further.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Joydeep View Post
                          Hello Arbuthnot,
                          ....The main difference between managed approach and unmanaged approach is that with the former (i.e. managed approach) NinjaTrader takes care of the bells and whistle that might affect an order. With Unmanaged approach you have to take care of everything...
                          What are the "bells and whistles" that managed approach takes care of?
                          - overfill?
                          - order errors?
                          - entries per direction?
                          - competing orders?
                          - position management -> only submit exit if there is a position?

                          Is there a detailed list anywhere? And some detail about required considerations for dealing with these issues in unmanaged approach? So that I can build up a checklist of stuff to look at when using unmanaged approach...
                          Last edited by AnotherTrader; 07-03-2012, 02:12 AM.

                          Comment


                            #14
                            Hello AnotherTrader,
                            Unfortunately there is no comprehensive list but basically the Managed approach reduces unwanted position. It can be competing orders or position management etc.

                            Please refer to our help guide to know more about the Managed approach.
                            JoydeepNinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by wallabee13 View Post
                              Well, after a second run on it, it is still coming up with the same problem. After the first time a setstoploss and a exitlonglimit are set, the exitlonglimit does not get triggered again in the code posted previously.

                              There is no error, it just never gets set again.
                              Instead of setstoploss maybe use exitlongmarket. Example here. Link

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by BarzTrading, Today, 07:25 AM
                              2 responses
                              23 views
                              1 like
                              Last Post BarzTrading  
                              Started by devatechnologies, 04-14-2024, 02:58 PM
                              3 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by tkaboris, Today, 08:01 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post tkaboris  
                              Started by EB Worx, 04-04-2023, 02:34 AM
                              7 responses
                              163 views
                              0 likes
                              Last Post VFI26
                              by VFI26
                               
                              Started by Mizzouman1, Today, 07:35 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X