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

Repopulating iOrder object after disconnect

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

    Repopulating iOrder object after disconnect

    Hello,

    I am having an issue with figuring out synching positions after disconnect. Let’s say my strategy submitted a long order and then after some time it goes down. Once I bring the system up, I need to tell the strategy that I have a live working order.

    I am planning to send details of executed orders to a file. On restart, I will read the file, so the question is how can I repopulate iOrder object with the details from the file? So that when the strategy signals an exit, I will be able to close the position.

    I have read documentation about various ways to do it via Account and Strategy position synching, but I have a managed account which has sub accounts which would run strategies across multiple charts. The only way for me to know exactly what positions belong to which accounts and charts is to store this info in a file or DB, and then retrieve in restart, but I am not sure how to repopulate iOrder object.

    Thanks,
    redduke

    #2
    Hello RedDuke,

    The only supported way that I can think of to repopulate your IOrder objects is when your strategy is processing Historically you may place an order inside of your Strategy to match your position that you are writing to a file.

    The main issue here is that the Strategy is completely separate from your Account so there is not a way to create/retrieve that IOrder object but you can submit the order Historically so when your strategy is running in real-time that it matches up with your Account.

    Let me know if you have any further questions.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC,

      Thanks fort the info.

      1) Does it mean, that I can submit a fake historical order with the same parameters as previously submitted real order?
      2) If I do that, will the following logic still work: if (entryOrder.OrderState == OrderState.Filled)...?
      3) How do I do I trigger this order in historical?

      Thanks,
      redduke

      Comment


        #4
        Hello RedDuke,

        1. Its not a Fake order but an order to match your actual prices that your broker filled your order at.

        2. Yes, NinjaTrader will still follow the logic that the entryOrder is filled because it will use the Historical Fill Process to evaluate the order fills.

        3. This will mainly depend on how you are recording your Data to the file and your conditions. If you would like to make sure that it is only processed Historically you may use the object "Historical" which will return true if your Strategy is being processed on Historical Data.

        For example:
        if (Historical)
        {

        //read file to see if any orders present
        }



        Most strategy, will be able to be sync up with disconnected and reconnected if you change some of the Strategy Options. If you have not seen it before there is a video demonstration that goes over all of the synchronization options to get a better understanding of this at the following link.
        JCNinjaTrader Customer Service

        Comment


          #5
          JC,

          Thanks for the video. I will watch it, but I read the section in help that covers Strategy Position vs Account Position. Since in my case, I have multiple accounts with executions across multiple charts, syncing would need to be done manually.

          I figured that historical order would need to be triggered within
          if (Historical)
          {}

          I use the following code to enter the positions:
          entryOrder=EnterLongStopLimit(BarsInProgress, true, 1, LimitPrice, StopPrice, "LONG");

          Will the system automatically know that since I am in historical mode to not submit it live? Since, bars are painted, won't the system reject the order since there is no tick data to verify price level? Normally orders are rejected when market is beyond order levels.

          Thanks,
          redduke

          Comment


            #6
            Hello RedDuke,

            Correct, yes if it is Historical it will not submit orders live. It will basically be like a Backtest in this regards.

            It will use the Close snapshot price of the bar to determine if order is valid so you can check the values of the "Close[0]" to make sure that your order is able to be entered.

            Note that you can also submit a Market Order to get the order to virtually fill but the Realized and Unrealized PnL of the Strategy would be slightly off due the price but your position will be covered.
            JCNinjaTrader Customer Service

            Comment


              #7
              JC,

              Thanks for very useful info. I have another question. The following is is from help guide:

              ----------------------------------------------------------
              Immediately submit live working historical orders, Sync account position = false

              Any active orders on the account previously generated by the strategy that does not match* an active strategy order will be cancelled.
              -------------------------------------------------------------

              1) Does active order mean order in accepted status that has not been executed yet?
              2) Will any live order that was executed not be affected and still stay open?

              Thanks,
              redduke

              Comment


                #8
                Hello RedDuke,

                1. That is correct, Accepted or Working orders.

                2. Correct, any orders that were already filled will not be effected by this. Only orders that have not been filled yet.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Hi JC,

                  I added the logic to read from the file and submit historical orders. Few more questions.

                  1) How do I attach stop loss to this historical order? I added the following logic, but it does not seem to do anything: SetStopLoss(entryOrder.Name, CalculationMode.Price, entryOrder.AvgFillPrice-TickSize*40, false); I checked that this logic is being triggered and all variable are populated, yet I do not see any working orders.
                  2) When an exit is triggered, how would the system know that historical order is linked to a previously open order, and that open order needs to be closed?

                  Thanks,
                  redduke

                  Comment


                    #10
                    Hello RedDuke,

                    1. Where are you setting this SetStopLoss() order in? For example is this when your entry order is submitted in OnBarUpdate()?

                    Also, can you add TraceOrders = true inside of Initialize() and take a look in the Output Window (Control Center -> Tools) to see if there is any messages about your Stop Loss order.


                    2. Since the Strategy has its own virtual position it is only going to see the Historical Position, but since you are synchronizing this with the order on your account it will exit out of your open position in your account so they will be in the same Position.
                    JCNinjaTrader Customer Service

                    Comment


                      #11
                      Hi JC,

                      1) Yes, I trigger SetStopLoss within OnBarUpdate when live feed resumes and as long as my iOrder object is not null and order status is filled.
                      2) Does it mean that the virtual position automatically syncs with previously opened position? And when I close virtual position it will close real open position. Just trying to figure out what links them.

                      Thanks,
                      redduke

                      Comment


                        #12
                        Hello RedDuke,

                        1. It should be setting your Stop Loss or submitting an active Stop Loss order. Do you see any messages inside of your Output Windows when you set TraceOrders to True?

                        2. Basically, there is nothing that links them together that is why it is important to make sure that your Strategy Position matches your Account Position. Any Live orders that your strategy gets it will submit it to your account.

                        Happy to be of further assistance.
                        JCNinjaTrader Customer Service

                        Comment


                          #13
                          JC,

                          This is what I got from output window:
                          3/27/2014 10:33:07 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Long' Mode=Price Value=1834.25 Currency=0 Simulated=False

                          However, I do not see any Accepted orders under Control Center order tab.

                          Thanks,
                          redduke

                          Comment


                            #14
                            Hello RedDuke,

                            That should be placing the order. The only thing that I see is that it is placing the order a few months back. Which means that the order could have been filled.

                            Can you check on your chart to see if your Stop Loss order is filled by chance?

                            Also, if you do not want your orders to be closed out at the end of they day you may want to set ExitOnClose to false.
                            JCNinjaTrader Customer Service

                            Comment


                              #15
                              JC,

                              Yes, I have it set to false.

                              Any other ideas why I do not see the stop in control center order tab? Kinda at a loss of what to do next.

                              Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              11 responses
                              39 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by FrazMann, Today, 11:21 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post FrazMann  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              8 responses
                              52 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              4 responses
                              26 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by George21, Today, 10:07 AM
                              1 response
                              22 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Working...
                              X