Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Same order is getting fired twice. order state and handling problem

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

    Same order is getting fired twice. order state and handling problem

    Hello,

    After condition 1 becomes true E-signal is supposed to send 1 order to NT, but instead it is firing 2 orders one after another within the same second. I dont think NTmarketPosition is updating fast enough to reflect the success or failure of the first trade after it has sent.

    Baically my code performs the following steps:

    if previous order sent was either rejected, filled or partfilled in NT then
    {
    if Condition1 is true and marketposition in NT is zero, then, BUY 1 contract at Market price.
    };

    the reason why i put in the first line is to check to see if the previous order was either filled or rejected. which "should" mean that "NTmarketPosition" should have updated in real-time if we got a fill ie changed from 0 to 1. maybe this is where im wrong, as it still fires 2 orders within the same second. only 1 order should be fired by e-signal.

    can someone please tell me what is wrong with my logic or steps im performing. the problem that i think im seeing is that while e-signal is sending the first order to NT and waiting for NTmarketposition to change from zero to 1, e-signal fires off another order to NT, as it still thinks NTmarketposition =0

    i tried running my e-signal program only once every 2 seconds and this solves the problem as this means when the first order is sent there is 2 seconds available for NTmarketPosition to update from 0 to 1, and this is enough time to get the position status back from our broker, which means the same order does not get executed twice. But im not 100% happy with this solution, as its not perfect, as sometimes it might take longer than 2 seconds to get order confirmation and position status from our futures broker after an order has been submitted by my local computer.

    Is there a better way to stop this problem of order duplication, using the OrderState() command in NT. if so how do i structure the code? just a list of some simple steps would help me immensely.

    Upon thinking about it some more, maybe in simulation mode, im getting a "Filled" order state *before* NTmarketPosition is able to update from a 0 to +1, or a 0 to -1. If i get 10 ticks in a second, before NTMaketPosition value is updated in real-time, what is stopping e-signal from sending 10 buy orders to NT, when in fact i only want to send 1 order? How can I solve this problem?

    Thanks in advance.

    Regards

    Rod
    Last edited by Rocket130713; 09-05-2008, 08:45 AM.

    #2
    Hello,

    Are you using IOrders or tracking orders via signal name?

    If you are using IOrders to track your trades try this link for a sample on how to do this:


    Using the IOrders method with OrderState you can receive the order state (Pending, Working, etc.) before NT receives any executions for it.
    DenNinjaTrader Customer Service

    Comment


      #3
      Rod,

      Try this (pseudocode):
      Create a bool that tracks if you've placed an order already or not

      Code:
      if (!traded)
      {
         // logic for trade
         traded = true;
      }
      Then you can reset the bool after your order's fill is recognized.

      Code:
      if (NTFilled > 0)
         traded = false;
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        hello,

        thanks for your replies. problem is that im doing the programming and order handling in e-signal EFS javascript.

        i think the problem is that im using simulation mode in NT, and, that the OrderState() string changes very quickly from "pendingSubmit" to "filled" before the "NTmarketPosition()" updates from flat to long, or, flat to short. this means if there are many ticks within the same second, you can see say 5 orders getting placed all at once within the same second, when in fact, we only want to send 1 order.

        Maybe this problem would not happen with a "live" NT account, as in this situation i could check to see if the order was in fact filled, partfilled or rejected, before any more orders are placed by the EFS e-signal program. this should mean that while e-signal program is waiting for order confirmation, it cant send any more orders while waiting.

        Do you see what im getting at? is my understanding correct when trading in simulation mode compared with live mode in NT?

        How do i program code in e-signal EFS to stop orders firing off more than once, using the OrderState() function ?

        Any comments or suggestions would be much appreciated.

        Thanks in advance.

        Regards

        Rod

        Comment


          #5
          Rod,

          You can't rely on any timing in sim or live, your logic needs to be independant of this. I am have not read the entire thread below but you would need to self track how many orders you submit from an external source. As you probably know, an order is submitted for each call you make to any of the order submission functions in the Automated Trading Interface.
          RayNinjaTrader Customer Service

          Comment


            #6
            i got to to bottom of this problem finally. in simulation mode, when i reload my e-signal strategy this causes NTmarketposition to go from null to zero and then to long 10 lots and it takes 4 seconds to do this. NTmarketposition should never go to zero when in fact we are long 10 lots in the sim101 account, it should instead go from null to +10 when i re-load the e-signal EFS strategy. problem is that when the NTmarket position goes to zero for a couple of seconds this fires off an extra order as e-signal thinks the position in the sim101 account is flat as NTmarketposition=zero. firstly will this problem happen in a live account when i go live soon? and how can i fix this problem?

            thanks in advance.

            regards

            Rod

            Comment


              #7
              Are you sure that NTMarketPosition() when it reports zero is the same symbol and account as the subsequent call when it reports 10? Since NTMarketPosition() is a wrapper function, hard code the account value and instrument name in the underlyign DLL function to verify that it is in fact the same.
              RayNinjaTrader Customer Service

              Comment


                #8
                Hi Ray,

                Thank you for your reply (and thanks to the others that also replied) I really appreciate it.

                I tried hardcoding the account and symbol strings in the DLL NTmarketPosition function, but this did not work.

                there is also more info that you need to know. the problem only happens when e-signal is open with EFS strategies running, and then i shut down NT and re-open NT straight away. and then after doing these steps i then re-load the EFS strategy and this causes the NTmarketPosition to go from a correct value which is say long 10 (ie +10) to zero and then in 7 seconds back to +10. for a split second, when the NTmarketPosition value goes to zero (which is incorrect value) it fires off an extra order, which is really bugging me. also, NTmarketPosition changes from +10 to zero and then back to +10 when we are on the last bar on the e-signal chart with live ticks are flowing through (i.e. in e-signal we only place trades when getBarStatus()==BARSTATE_CURRENTBAR which means live ticks are flowing through).

                if i dont close down and re-open NT plaftform (While e-signal is open) and just try to reload E-signal EFS strategy the problem does not show up.

                This is really strange behaviour, i dont see why reloading EFS strategy on chart shoudl cause NTmarketPosition to go from a correct value, to zero, and then back to correct value, and all this happens in about 7 seconds.

                If anyone has any ideas on how to fix this, that would be very much appreciated.

                Thanks in advance.

                Regards

                Rod

                Comment


                  #9
                  Can you try and reproduce with our sample script provided? If you can't find it on your PC, its located here as well.

                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Ray,

                    Thanks for taking the time to have a look at the problem i am seeing.

                    I have used your "NTsample" code (with some very minor additions which include reference to the function NTmarketPosition) in e-signal so that you can try and replicate the problem i am seeing. (see E-signal EFS file attached to this message, note that the EFS file is presented within a notepad text file).

                    These are the steps you need to carry out in exact order as specified to see the problem.

                    1. Open up NT and connect to e-signal data feed, and then place a manual order to buy 1 "ES Z8" contract at market. Note: make sure you can see that the order has been filled and is showing "long 1" under the NT "positions" tab.

                    2. Open the e-signal platform and then appy the EFS code (called "NT sample") to a 1 minute chart (say for symbol "ES Z8").

                    3. In e-signal, open the "Formula output Window" and you should be able to see the details of the current open position i.e NTmarketPosition which is long 1, order status, average entry price, etc.

                    4. Then close down NT completely, and re-open the NT platform straight away, and then connect to e-signal feed. wait around 10 seconds until the details of the current order in NT are shown again in "formula output window" in e-signal and live ticks are coming through on the e-signal ES Z8 chart. Every time a tick flows through the details of the current position in NT should show in Esignal "formula output window".

                    5. then "re-load" the E-signal EFS code by clicking on "chart options" tab in e-signal, and then clicking on "re-load" and then move mouse out to the right and select the EFS strategy called "NT sample".

                    after doing step 5 you should see that marketposition in NT is now 2 contracts (ie long 2), and it should be only long 1. that is re-loading the strategy should not place an extra buy order. this can be further confirmed by checking "Position size" in the "formula output window" when you reload strategy, position size goes from +1, to zero, and then to +2

                    a reload should do nothing to the position size, it should in fact stay at +1 in this example at all times.

                    thank you for looking at this problem. please let me know if you can replicate it at your end. this problem has been causing my e-signal strategies to fire off an extra order, apart from this NT is brilliant software.

                    If you would like i can also be contacted by telephone, and i can go over the above steps, so you can see the problem also. im always here to help as many people as possible.

                    Thanks in advance.

                    Regards

                    Rod
                    Attached Files

                    Comment


                      #11
                      Rod,

                      We recommend you to not use the Reload in eSignal. Instead please Remove and readd the NTSample.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        I seen this probllem

                        Rocket130713,

                        I been working with the DLL for almost a year first in simulation and now live. From experience I can tell you that you can not thrust MarketPosition by itself. When I send an entry order I wait for the Status to turn to field then and only then my exit orders start kicking (monitoring the MarketPosition). Here is some high level of what you might want to do.

                        MP = NTMarketPosition(account) ;//returns 1 or 0
                        Current_Shares NTCurrentShares(account);//returns current shares
                        OrderId = SendNTOrder(....);

                        //Stop and Profit orders

                        If OrderId = "" And MP <> 0 Then

                        //Send stop or profit orders now

                        End

                        OrderId = IsOrderFilled(OrderId)//This function returns an empty string when order is filled and that will signal to the stop/profit order to start working



                        You might also trigger the exit orders on a Partial Filled but I prefer to wait for the fill. I am using 400 shares max in symbols with more than a million shares daily volume so that is not a problem.

                        Moscu

                        Comment


                          #13
                          Hi Josh,

                          Thanks for your suggestion to solve my problem but this unfortunately did not work. Im still getting extra orders fired off.

                          to see the problem, instead of doing a "re-load" of the "NTsample" strategy in step 5, the same problem occurs when you "Remove and re-add the NTSample".

                          Please see the 5 steps I outlined in post below. if you follow these exact steps you will see the bug. NTsample EFS code is provided in a text file attached in post below.

                          if you can not duplicate the problem could you please telephone me and i would be happy to go over the steps to show you what im seeing.

                          the reason this is a very serious problem is that every day I have to shut down and re-open the NT platform due to our MF Global broker re-setting their servers each day. and after doign this if i have to make a change to my e-signal code or shut down and re-open the e-signal platform, this will cause the problem which is extra unwanted orders being fired off.

                          As mentioned above, the problem occurs also when i have to shut down and re-open the E-signal platform which may need to be done due to mains power going off and then back on, or due to E-signal platform crashing.

                          Please see 5 steps in my post below. If you perform these 5 steps in the order as listed, you should see the bug im referring to.

                          In step 5, you can either do (1) a "re-load" of NTsample strategy. (2) remove and re-add NTsample strategy. (3) close down and re-open E-signal platform. ~ Note that all 3 of these actions all "re-load the strategy" and this is what causes the problem.

                          thanks in advance. look forward to your reply.

                          if you can fix this problem im happy to sign up and pay the $50 per month, for many years to come.

                          regards

                          Rod
                          Last edited by Rocket130713; 09-17-2008, 01:39 AM.

                          Comment


                            #14
                            Rod,

                            I forgot to mention to try it on the next build.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              ok. which build number is that?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by timko, Today, 06:45 AM
                              1 response
                              7 views
                              0 likes
                              Last Post gaz0001
                              by gaz0001
                               
                              Started by Waxavi, 04-19-2024, 02:10 AM
                              3 responses
                              41 views
                              0 likes
                              Last Post gaz0001
                              by gaz0001
                               
                              Started by Max238, Today, 01:28 AM
                              2 responses
                              26 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by Shansen, 08-30-2019, 10:18 PM
                              25 responses
                              949 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by JonesJoker, 04-22-2024, 12:23 PM
                              8 responses
                              44 views
                              0 likes
                              Last Post JonesJoker  
                              Working...
                              X