Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Questions about placing orders

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

    Questions about placing orders

    Hi,
    I have two questions:
    1. I am wondering if I place a long limit order for 3 contracts, and set EntriesPerDirection == 1, is that ok? EntriesPerDirection has nothing to do with position size, do it? It only means if I already have one long position (no matter how many contracts), then I can't open another long position later, right? This is kind of confusing to me.
    2. Supposed I can open 3 contracts at once, I want to set their stop loss to be like 10 ticks away, and profit target to be 10,15,20 ticks away for each contract. Do I need to call EnterLongLimit() once with the three contracts, and ExitLongStop() once with these three contracts, and then ExitLongLimit() 3 times for each of the different price target? What happens if right after I call EnterLongLimit, the computer crashes or internet goes down, then will my stop loss and profit target orders go through? It would be disastrous if these orders don't go through. Is there a way to submit all of these together?

    #2
    Originally posted by zehua View Post
    Hi,
    I have two questions:
    1. I am wondering if I place a long limit order for 3 contracts, and set EntriesPerDirection == 1, is that ok? EntriesPerDirection has nothing to do with position size, do it? It only means if I already have one long position (no matter how many contracts), then I can't open another long position later, right? This is kind of confusing to me.
    2. Supposed I can open 3 contracts at once, I want to set their stop loss to be like 10 ticks away, and profit target to be 10,15,20 ticks away for each contract. Do I need to call EnterLongLimit() once with the three contracts, and ExitLongStop() once with these three contracts, and then ExitLongLimit() 3 times for each of the different price target? What happens if right after I call EnterLongLimit, the computer crashes or internet goes down, then will my stop loss and profit target orders go through? It would be disastrous if these orders don't go through. Is there a way to submit all of these together?
    1. Please read the following post.



    2. You can use stop losses and take profits to do this.



    Also, please read the following thread to answer your order submission questions.

    Note: This information is relevant for NinjaTrader 7 only. For NinjaTrader 8, please click here (https://ninjatrader.com/support/helpGuides/nt8/where_do_your_orders_reside_.htm). CQG Orders in a state "Accepted" or "Working" are at the exchange. If the exchange does not support a specific order type, the


    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Adam.
      I just read those posts, and I still have the following questions:
      1. If I set EntriesPerDirection to 1, can I call EnterLong() with quantity of 2 for just once? Can I call EnterLong() with quantity of 1 immediately for twice?
      2. Does EntriesPerDirection restrict only one symbol? If I set it to 1, and set EntryHandling.AllEntries, and I applied my strategy to both ES and YM, what will happen? I want to apply my strategy to most of the futures market, but I want a max of 5 entries simultaneously. Can this variable achieve that goal?
      3. I don't want to call SetStopLoss() and SetProfitTarget(), because they are initialized in Initialize(), and cannot change. For each of my order, Once I want to enter long, I would like to place the stop loss order one tick below the lowest low of the most recent 3 bars. Therefore I do need to call ExitLongStop().
      I just wrote the following code, and I am not sure if it will work as I expected. Could you please take a look?

      entryOrder = EnterLongLimit(0, true /*liveUntilCancelled*/, quantity, entryPrice, "long");
      ExitLongStop(0, true /*liveUntilCancelled*/, quantity, stopLossPrice, "long stop", "long");
      ExitLongLimit(0, true /*liveUntilCancelled*/, quantity, targetPrice, "long target", "long");

      I see from your manual that doing this will link the stop and target exit orders to the entry order. So that means after the entry order is executed, and later suppose the limit order is hit, then the stop order will automatically be cancelled? Well, maybe I don't need to ask this. I just need to write some code in OnExecution to reset my entryOrder to null.
      4. Is GetAccountValue() thread safe? If I have apply my strategy to multiple instruments, I need to make sure GetAccountValue() is thead safe. Otherwise I might place too many orders and get margin calls.


      Sorry for asking so many questions. I tried to avoid asking so many questions, and I have spent two full weekends to read through your entire manual. These are the questions that I am really not able to figure out myself.

      Comment


        #4
        Aha, I read the manual about SetStopLoss(), and it is able to be set within OnBarUpdate(), so that is good.
        However, I am concerned with this statement:
        Stop loss orders are submitted in real-time on incoming executions from entry orders.
        This means if the entry order is submitted, and then my computer crashes, or internet is down, then there is no way that my stop loss order can be submitted? That is scary to me.
        Could you provide any EnterLongLimit method that I can submit entry price, stop loss price and target price all at once? In that case, this operation would be safe.
        Also if I choose to use SetStopLoss(), then I would have no way to get an IOrder object for this stop loss order, and in OnExecution, if I am stopped out, I can't really do anything inside that method, right?
        Last edited by zehua; 03-04-2012, 09:10 PM.

        Comment


          #5
          zehua, we would unfortunately not support so called atomic orders as placement - NT needs to be connected live to manage resulting stops / target orders based on incoming executions seen.

          Correct, the Set's do not have native IOrder access, however you could capture their returns in OnOrderUpdate() as shown here -

          BertrandNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            zehua, we would unfortunately not support so called atomic orders as placement - NT needs to be connected live to manage resulting stops / target orders based on incoming executions seen.

            Correct, the Set's do not have native IOrder access, however you could capture their returns in OnOrderUpdate() as shown here -

            http://www.ninjatrader.com/support/f...ead.php?t=5790
            Well, I just checked your manual regarding unmanaged orders, and SubmitOrder function allows me to submit the order with limit price and stop price together. If I do it that way, then will this issue be solved?

            Comment


              #7
              Hi zehua,

              What problem are you trying to solve with unmanaged SubmitOrder() here?

              The SubmitOrder() overload allows for both stop and limit price specification only as part of one order, like if you wanted to submit a stoplimit order. It's not used for two distinct stop and limit orders.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_RyanM View Post
                Hi zehua,

                What problem are you trying to solve with unmanaged SubmitOrder() here?

                The SubmitOrder() overload allows for both stop and limit price specification only as part of one order, like if you wanted to submit a stoplimit order. It's not used for two distinct stop and limit orders.

                Ryan, the problem that I want to solve is to submit a long limit order with stop loss and profit target as an atomic operation.
                Right now I don't see any way to achieve this through your Managed orders. That means I have to call EnterLongLimit, and then call ExitLongStop. The problem with that is if my computer crashes right after I call EnterLongLimit, my account will be in danger as there is no stop loss to protect me from being wiped out.
                Is there any solution to this problem? I would be surprised if Ninjatrader provides no solution to this obvious potentially disastrous operation.

                Comment


                  #9
                  Why don't you use ATM for this?

                  Comment


                    #10
                    zehua,

                    Orders reside for the most part on your brokers servers or at the exchange.

                    Note: This information is relevant for NinjaTrader 7 only. For NinjaTrader 8, please click here (https://ninjatrader.com/support/helpGuides/nt8/where_do_your_orders_reside_.htm). CQG Orders in a state "Accepted" or "Working" are at the exchange. If the exchange does not support a specific order type, the


                    Most likely your order would go through and reside there.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Our first recommendation here is that you do not leave your computer unattended while automated trading. That way if anything goes wrong you can see right away and call your broker to manage any open orders and positions.

                      Then, check out this sample for ways of submitting protective orders upon entry execution. The limit and stop order would come through as two separate commands but potentially the same operation (fill event on the entry order). The likelihood of your computer crashing in-between submission of these is very low.
                      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()
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_RyanM View Post
                        Our first recommendation here is that you do not leave your computer unattended while automated trading. That way if anything goes wrong you can see right away and call your broker to manage any open orders and positions.

                        Then, check out this sample for ways of submitting protective orders upon entry execution. The limit and stop order would come through as two separate commands but potentially the same operation (fill event on the entry order). The likelihood of your computer crashing in-between submission of these is very low.
                        http://www.ninjatrader.com/support/f...ead.php?t=7499
                        Ryan.... The reason I am intereted in buying your software is because I want to auto trading without watching it all day long.
                        I know the probability that this issue happens is very low, but when it happens, it could wipe out the entire account. Usually the internet condition is the worst when the market moves fastest, so the probability of this happening is actually not really low.
                        I understand that probably no one in your team has been concerned about this issue, and therefore you currently have no solution to it, but I do hope you can try to provide a solution to it in your next version. I would not buy your software and start trading with this problem existing.

                        Comment


                          #13
                          Thanks for the feedback.

                          What you might consider is that you contact your prospective broker to see if they will do a master stop on the account.

                          Meaning is the account was ever to go down 30% auto close the position from the broker side. You use your own value here however this might be another option for you if your broker would support that for you to protect you from the extreamly small chance of this happening.

                          Furthermore, on the more advanced side this would be more leading edge and advanced but no reason why it couldn't be done. Set up a second server with a second IP address. Connect them via a VPN or some sort of IP that both servers make sure they are still up. They both run the same strategy and connect to the same account, however if one goes down and you stop getting a heart beat from it you could then have the second client take over.

                          Again a lot more advanced however the basic issue at hand is that you need a server as a backup to park your orders on that give you better chance of the order flow not getting disrupted. Most broker technologies do NOT support this and only support the exchange order types as to support these order types they have to simulate it on their servers and take responsibility for it. There are a few that do support this however since most do not as such we do not support this in NinjaTrader.

                          As always we always recommend here at NinjaTrader that automated trading is watched by a trader as you ultimately are responsible for your account.

                          -Brett
                          Last edited by NinjaTrader_Brett; 03-05-2012, 03:02 PM.

                          Comment


                            #14
                            Originally posted by NinjaTrader_Brett View Post
                            Thanks for the feedback.

                            What you might consider is that you contact your prospective broker to see if they will do a master stop on the account.

                            Meaning is the account was ever to go down 30% auto close the position from the broker side. You use your own value here however this might be another option for you if your broker would support that for you to protect you from the extreamly small chance of this happening.

                            Furthermore, on the more advanced side this would be more leading edge and advanced but no reason why it couldn't be done. Set up a second server with a second IP address. Connect them via a VPN or some sort of IP that both servers make sure they are still up. They both run the same strategy and connect to the same account, however if one goes down and you stop getting a heart beat from it you could then have the second client take over.

                            Again a lot more advanced however the basic issue at hand is that you need a server as a backup to park your orders on that give you better chance of the order flow not getting disrupted. Most broker technologies do NOT support this and only support the exchange order types as to support these order types they have to simulate it on their servers and take responsibility for it. There are a few that do support this however since most do not as such we do not support this in NinjaTrader.

                            As always we always recommend here at NinjaTrader that automated trading is watched by a trader as you ultimately are responsible for your account.

                            -Brett
                            Thanks. I will ask AMP futures if they provide a master stop. This is a bit disappointing to me. Even if I am watching the trades, and after EnterLong() is called, the internet is down, then what can I do about it? I can certainly call my broker, but it could be too late.

                            Regarding the orders, I am currently using this approach. Do you see any problems?
                            private IOrder entryOrder = null;
                            private IOrder stoplossOrder = null;private IOrder profitTargetOrder = null;

                            OnBarUpdate()
                            {
                            // I set all three orders to be live until cancel
                            entryOrder = EnterLong();
                            stoplossOrder = ExitLongStop();
                            profitTargetOrder = ExitLongLimit();}

                            OnExecution()
                            {

                            if (execution.order == stoplossOrder )
                            {
                            CancelOrder(profitTargetOrder);
                            entryOrder = null;
                            stoplossOrder = null;
                            profitTargetOrder = null;
                            }
                            else if (execution.order == profitTargetOrder )
                            {
                            CancelOrder(stoplossOrder);
                            entryOrder = null;
                            stoplossOrder = null;
                            profitTargetOrder = null;
                            }
                            }


                            Finally, I see in your manual that you mentioned the setting to flat all positions before end of session might have problems, and you gave this example:
                            1. There is a stoploss order.
                            2. End of session is approaching, so you place a market sell order to close the long position.
                            3. Right after you place the market sell order, the stoploss order is triggered. Therefore, the account ends up with a short position.

                            I think this is a very bad problem. Can't you do this instead:
                            1. Detect if there is a stoploss order for this long position
                            2. If not, place a market sell order
                            3. If yes, then modify that stop loss order price to be a few ticks above the current market price. Then wait to see if it gets triggered. If not, keep raising the stop loss trigger price until it gets triggered.

                            This would guarantee there is no such a problem.

                            Comment


                              #15
                              Hello,

                              You would need to do this in your own code to correct the issue we discussed about earlier as there are limitations to how are exit on close works that unfortunately cannot be changed in our current NT release due to technical limitations however it is on developments list to look into for our next major release to make a change here.

                              This is why I recommend doing any exit on close orders manually yourself hardcoded into the strategy so you can make sure you are doing these checks.

                              -Brett

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bmartz, 03-12-2024, 06:12 AM
                              4 responses
                              31 views
                              0 likes
                              Last Post bmartz
                              by bmartz
                               
                              Started by Aviram Y, Today, 05:29 AM
                              4 responses
                              11 views
                              0 likes
                              Last Post Aviram Y  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              3 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by gentlebenthebear, Today, 01:30 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by cls71, Today, 04:45 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X