Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Submit entry and stop at limit in managed orders?

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

    Submit entry and stop at limit in managed orders?

    I have read the documentation and tried a search on the forum, but I can't see how to achieve what I think is a very simple task. I want to submit a limit order, and together with the limit order submit a stop limit order. So being that I calculate both the limit entry and stop loss price for every situation, I don't want to use "StopLoss". At least I don't think that would do what I want. I looked at "ExitLongStopLimit" and "ExitShortStopLimit" but these appear to apply after an order has been entered. I want to say, "Enter long or short at this price", "if I enter at that price, then stop out if I exceed this stop price".

    If that case is not possible without unmanaged orders, then how about this? Use EnterLongLimit, EnterShortLimit and set StopLoss to some worst case stop loss. Then on the next bar after a confirmed entry, call "ExitLongStopLimit" or "ExitShortStopLimit" as the case may be? I just don't understand the documentation enough to know what these calls do.

    #2
    I think you'd want to use ExitLongLimit() in this case.

    Comment


      #3
      Your scenario is in violation of the order handling rules we built to help prevent unwanted positions.

      I would encourage you to use the manage approach and code your own order handling rules to achieve your goal.
      MatthewNinjaTrader Product Management

      Comment


        #4
        Originally posted by NinjaTrader_Matthew View Post
        Your scenario is in violation of the order handling rules we built to help prevent unwanted positions.

        I would encourage you to use the manage approach and code your own order handling rules to achieve your goal.
        Mathew,
        This is unclear. I never said I didn't want to use the managed approach, so what do you mean? And what is in violation? I don't want unwanted positions either, and I'm not doing anything that would create unwanted positions. I am asking you for the proper code so this is done right.
        So lets go back to basics. A bar comes into OnBarUpdate and closes at 1390. I want to put a buy limit order in for 1380. I also want as soon as possible to protect my entry with a sell stop order 2 points lower at 1378. I am asking how to place the order and the stop loss? That is my question.
        Next, I speculated as to what calls may accomplish this, thinking I was helping, but lets put that aside and just take this first step. What sequence of calls would do this. I don't see a clear answer in the documentation.

        Comment


          #5
          Hello,

          Thanks for the clarification - submitted two entry orders would end up in one of the orders being ignored due to the order handling rules

          In your last example, you would use EnterLongLimit for your entry order, and then ExitLongStop for the stop order.

          If you want to submit a protective stop order as soon as possible, you would want to work in OnExecution() rather than OnBarUpdate()

          Please see our Reference Sample on Using OnOrderUpdate() and OnExecution() methods to submit protective orders

          The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


          Our example will use SetStopLoss and SetProfitTarget, but you can also use ExitLongStop and ExitLongLimit for your stops/targets.
          MatthewNinjaTrader Product Management

          Comment


            #6
            I used the approach given in that example. How can I debug this? I went into the debugger and it calls EnterShortLimit just as I intended with a valid price, but it never hits even though I know in just a few bars the price is hit? I put a breakpoint in OnExecution and it simply does not hit. I also put a print every time I call any entry API call and it just calls it once, so it is not overriding it. I used the simplest EnterShortLimit with just a limit price, do I need to use one of the other calls?

            I have extensively used EnterLong, EnterShort without any problems executing before, but this is my first limit order.

            Comment


              #7
              For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

              It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.
              MatthewNinjaTrader Product Management

              Comment


                #8
                Here is my entry printout and then the output of TraceOrders=true. I don't see anything wrong, but I now have this vague memory of some orders having to be reentered every bar? I was thinking I was entering an order and it would sit there until filled or cancelled. If not so, then how are you supposed to work this? It means you have to track your orders yourself and resubmit them every bar?
                EnterShortLimit: 1305.825
                5/23/2012 10:12:00 AM Entered internal PlaceOrder() method at 5/23/2012 10:12:00 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1305.75 StopPrice=0 SignalName='' FromEntrySignal=''
                5/23/2012 10:13:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00000/Sim101' Name='Sell short' State=Working Instrument='ES 06-12' Action=SellShort Limit price=1305.825 Stop price=0 Quantity=1 Strategy='ThreefoldFib' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='f3a3b978df3e48088d2df7951549ca00' Gtd='12/1/2099 12:00:00 AM'

                Comment


                  #9
                  Hello,

                  You're on the right track - the default behavior is to cancel the orders once the condition is no longer true.

                  However you can change this behavior to keep the order alive until you cancel it programmatically.

                  Please see our reference sample on this topic for more information:



                  I'm also providing a sample on Canceling orders:

                  When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-until


                  Please let me know if you have any questions.
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    Ok, so now I have entries and target exits working. I am not sure I have stop exits. Below is a sequence where I do EnterShortLimit which is filled, then ExitShortStop which is also hit, and then I have ExitShortLimit which is entered but not hit because I first exit with the Stop. The question is if this is ok, or should I not give the target order (ExitShortLimit)? I check for Positon.MarketPosition and it thinks it has a position at the time when I give the target order. I just wanted to make sure this is the proper sequence. When I think about it there is no way of knowing if a stop out or target will get hit first, so one of the two will always get cancelled?

                    EnterShortLimit: 1297.785
                    5/23/2012 10:49:00 AM Entered internal PlaceOrder() method at 5/23/2012 10:49:00 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1297.75 StopPrice=0 SignalName='Enter Short' FromEntrySignal=''

                    ExitShortStop: 1298.71
                    5/23/2012 10:50:00 AM Entered internal PlaceOrder() method at 5/23/2012 10:50:00 AM: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1298.75 SignalName='Stop Short' FromEntrySignal='Enter Short'

                    ExitShortLimit: 1294.688
                    5/23/2012 10:51:00 AM Entered internal PlaceOrder() method at 5/23/2012 10:51:00 AM: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1294.75 StopPrice=0 SignalName='Target Short' FromEntrySignal='Enter Short'

                    5/23/2012 10:54:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00014/Sim101' Name='Target Short' State=Working Instrument='ES 06-12' Action=BuyToCover Limit price=1294.688 Stop price=0 Quantity=1 Strategy='ThreefoldFib' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='580b91f98bc34acda297667f77b1a9bc' Gtd='12/1/2099 12:00:00 AM'

                    Comment


                      #11
                      Yes, it will cancel the stop/target associated with the position once the position has been closed.

                      Where are you checking for Position? Is this in OnBarUpdate or OnExecution/OnOrderUpdate?

                      If you're using OnBarUpdate, you may not see the position reported as flat until the next OnBarUpdate event. Using OnExecution/OnOrderUpdate should give you a more accurate Position update.

                      You can also use OnPositionUpdate() to check for market position which should be called as soon as the position changes:

                      MatthewNinjaTrader Product Management

                      Comment


                        #12
                        OnBarUpdate has EnterLongLimit for entry, ExitLongLimit for target.
                        OnExecution has ExitLongStop for stop loss. So upon an entry trigger, first the stop gets set. Then the target can get entered right while the stop is getting stopped out. I suppose the ExitLongLimit could be moved to OnExecution, but my signals are setup based on bar updates, so I'll have to consider that.

                        Comment


                          #13
                          You could also set the initial target for example right from OnExecution when the entry fills and then adjust from OnBarUpdate() as the trade progresses. Just cancel order the target then when your stop reports filled.
                          BertrandNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by philmg, Today, 12:55 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post philmg
                          by philmg
                           
                          Started by Russ Moreland, Today, 12:54 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post Russ Moreland  
                          Started by f.saeidi, Today, 12:14 PM
                          2 responses
                          5 views
                          0 likes
                          Last Post f.saeidi  
                          Started by TradeForge, 04-19-2024, 02:09 AM
                          2 responses
                          28 views
                          0 likes
                          Last Post TradeForge  
                          Started by aprilfool, 12-03-2022, 03:01 PM
                          3 responses
                          327 views
                          0 likes
                          Last Post NinjaTrader_Adrian  
                          Working...
                          X