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

It is possible to place duplicate orders for different accounts

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

    #16
    Originally posted by NinjaTrader_BrandonH View Post

    In regard to the behavior of clicking the Close button when multiple orders are placed, this is because the order quantity being submitted is set to 1. Instead, the order fill quantity would need to be used for the order quantity. I have attached a modified version of the strategy which demonstrates this fix. I have also replaced the script attached in post #4 with this modified version.

    Let us know if we may assist further.

    Thank you for the update, now I see the script replicates what is done in the Close and Rev buttons in the main account

    I have one last scenario where I need to "replicate" orders but in a lightly different way that is the next:
    I’m testing 1 algorithmic strategy and it gives signals based in the ES, but happens that I need to replicate the orders the strategy places (Entry, Trailing Stop Loss…) in a Sim account that will work with Micros like the MES. So in this case the second account has a different instrument to work with different order quantities.

    The idea is that if the strategy generates 1 ES long contract trade, then the script replicates this trade but “in fractions of the ES”, so in Micro-ES where maybe you could specify the target contract instrument and order quantity. In this example let’s say the script replicates the order in a 2nd account but instead to replicate 1 ES long contract trade, it replicates 5 MES long contract trade to fit the risk according to the size in the 2nd account.

    I think the more intuitive way to do this would be additionally specifying in the script:
    • The account #2 Target Order Quantity to replicate.
    • The account #2 Input series where replicate the order.

    I will attach 1 picture to give a visual idea (I don't know if it could be the most useful way to specify this in the script but it is more or less the idea I have), because I have since this Thrursday looking for a way to do this and I can’t find anything similar to what I explain. During these days I’ve tried different things trying to get the result I explain and the most I got was to replicate from the ES to the MES, but unable to change the target quantity. And I don’t know if the way I could replicate from the ES to the MES is the most efficient way because I first loaded the MES in the main chart window as a second data series in order to then be able to specify in the script the MES as Input Series.

    Thank you very much for your time and for the support

    Click image for larger version

Name:	Visual idea.png
Views:	418
Size:	208.6 KB
ID:	1176097

    Comment


      #17
      Hello futurenow,

      Thanks for your note.

      AddDataSeries() would be used to add an additional data series to your script. You could then specify which data series you would like to submit orders to by checking the BarsInProgress number of the data series and calling your order methods. If you would like orders submitted to the primary series, you would check if BarsInProgress == 0. To submit orders to the first added data series, you would check if BarsInProgress == 1. To submit orders to a second added series, you would check if BarsInProgress == 2, and so on.

      Note from the AddDataSeries() help guide: Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided.

      If you are submitting 1 order to the ES instrument and would like 5 orders replicated on the MES instrument. you could add 4 to the order quantity being placed by your order methods. For example,

      if(BarsInProgress == 1)
      {
      buyOrder = account2.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Manual, TimeInForce.Day, e.Order.Quantity + 4, e.AverageFillPrice, 0, "", "buyOrder"+DateTime.Now.ToString(), DateTime.MaxValue, null);

      account2.Submit(new[] {buyOrder});
      }

      See the help guide pages below for more information.
      AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
      BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm

      Let us know if we may assist further.
      Brandon H.NinjaTrader Customer Service

      Comment


        #18
        Thank you for your reply and guidance

        About the last version of the script you uploaded I'm noticing the script has a very important bug that it is when you enable in NT8 the option for Auto-close-position (Options \ Trading) to close everything at certain specific hour, and at the same time you are using this script (SubmitOrderToTwoAccounts.zip), what happens at that pre-defined time is NT8 closes everything as should (as normal), but it seems this script takes that kind of close-all-at-market-order and 1 second later, it replicates that close-all order to the secondary account causing instead that everything be closed at the desired time, then almost everything be closed except the orders what were inmediately opened by this script right after NT8 send the “close/dissable-all” order to everthing in the platform.

        The result of having the Auto-close-position option and this script, both enabled at the same time, is if you need to have everything closed let’s say at 1:00:00 PM, then NT8 will close everything EXCEPT that 1-2 seconds later you will have opened the opositive orders you previously had in the Secondary account where is being copied the orders, something totally out of the plan.

        Comment


          #19
          Hello futurenow,

          This is Jim responding on behalf of Brandon who is out of the office at this time.

          Like our other forum examples, Brandon's script is meant to be an example to get started rather than a drop in tool. The script shows how to listen to orders on one account and send them to the other account.

          In this case, Auto Close Position is closing on all accounts, and the Close on the first account is duplicated on the second account.

          Normally, we could look at the name of the order to identify it and determine if we should take a different action. However, since Auto Close position just uses "Close" as the order name, we could not distinguish it from a press of a Close button which would use the same name.

          We would recommend disabling Auto Close Position behavior with a script like this. If you need the Auto Close Position functionality, it could implemented in a custom AddOn that adds a timer, checks the PC clock time in the timer, checks open positions, and submits market orders to close positions at a specified time. The only difference being, you would then give a unique order name for the Auto Close Position orders, that the duplicator script can recognize, and ignore.
          JimNinjaTrader Customer Service

          Comment


            #20
            Hello i would like to know how to copy and install this add-on.


            Hello jorgeaug,

            Welcome to the forums and thank you for your post.

            I understand that you would like to submit an order to one account and have the same order submitted on a second account.

            Account-level OrderUpdate events could be used to pick up orders from one account and submit orders to another account. To accomplish this, you would need to create a script that subscribes to account-level OrderUpdate events to monitor orders sent to the first account. Then, in OnOrderUpdate you could check if an order is filled and if the order is long or short. If the order IsLong, then you can use Account.CreateOrder() to create a buy order followed by calling Account.Submit to submit that order to the second account. If the order IsShort, you could use Account.CreateOrder() to create a sell order followed by calling Account.Submit to submit that order to the second account.

            Please see the attached example script that demonstrates how this is accomplished.

            Also, please see the following help guides linked below for more information.

            OrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

            CreateOrder - https://ninjatrader.com/support/help...tegycreate.htm

            Let us know if we may further assist.
            Attached Files

            Comment


              #21
              Hello helbertolmr,

              Thanks for your note.

              You would download the reference sample zip file located here: https://ninjatrader.com/support/foru...01#post1175601

              After downloading the reference sample, you would follow this basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

              To Import:
              1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
              2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
              3. Select the downloaded .zip file
              4. NinjaTrader will then confirm if the import has been successful.

              Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

              Once installed, you may add the indicator to a chart by:
              • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK

              Here is a short video demonstration of the import process:
              After importing the reference sample, you could view the script's code in a New > NinjaScript Editor window. The file is located under the Indicators folder in the NinjaScript Editor window.

              Please let me know if I can be of further assistance.
              Brandon H.NinjaTrader Customer Service

              Comment


                #22
                Originally posted by NinjaTrader_BrandonH View Post
                AddDataSeries() would be used to add an additional data series to your script. You could then specify which data series you would like to submit orders to by checking the BarsInProgress number of the data series and calling your order methods. If you would like orders submitted to the primary series, you would check if BarsInProgress == 0. To submit orders to the first added data series, you would check if BarsInProgress == 1. To submit orders to a second added series, you would check if BarsInProgress == 2, and so on.
                (...)

                if(BarsInProgress == 1)
                {
                buyOrder = account2.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Manual, TimeInForce.Day, e.Order.Quantity + 4, e.AverageFillPrice, 0, "", "buyOrder"+DateTime.Now.ToString(), DateTime.MaxValue, null);

                account2.Submit(new[] {buyOrder});
                }
                I'm testing this and the OnOrderUpdate BarsInProgress randomly returns 0 or 1, so sometimes it runs on the second ticker and sometimes it doesn't. Should a variable be recorded in "OnOrderUpdate" like BuyOrderTrigerred = true , and "onMarketUpdate" send the order if BuyOrderTriggered = true?
                Last edited by rocker84; 09-08-2022, 12:25 PM.

                Comment


                  #23
                  Hello rocker84,

                  Thanks for your note.

                  It is expected that if you are using two different instrument data series and you're either using non-time-based charts or you're using Calculate.OnEachTick or Calculate.OnPriceChange and print out the BarsInProgress, you would see random prints for which BarsInProgress is currently processing because the ticks wouldn't come in at the same time.

                  You would need to ensure that you are using time-based charts and Calculate.OnBarClose for orders to take place properly.

                  Let me know if I may assist further.
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by NinjaTrader_BrandonH View Post
                    Hello rocker84,

                    Thanks for your note.

                    It is expected that if you are using two different instrument data series and you're either using non-time-based charts or you're using Calculate.OnEachTick or Calculate.OnPriceChange and print out the BarsInProgress, you would see random prints for which BarsInProgress is currently processing because the ticks wouldn't come in at the same time.

                    You would need to ensure that you are using time-based charts and Calculate.OnBarClose for orders to take place properly.

                    Let me know if I may assist further.
                    ok thanks. Also the original code (for same ticker, no with second series added) is replicating other tickers on the same account, but running on another screen. And it has the same behavior of running random on one ticker or another, but this time with different chart windows. For example, I uploaded it to a UPS chart, and in another window I was running AAPL and got the replicated AAPL entry as well. However the exit it ran it with the ticker UPS. (timeframe: 5m on AAPL, 3m on UPS)

                    On the other hand, "OrderState.Filled" is used in the code. What happens if a "partial fill" of a market order is obtained in the log? I think this happens when there are several lots and the execution price is different in each one.
                    Last edited by rocker84; 09-15-2022, 12:17 PM.

                    Comment


                      #25
                      Hello rocker84,

                      Thanks for your note.

                      I am not able to reproduce the behavior you are reporting when testing the example script shared in post # 4. Note that this is only intended to be an example script, not a fully functioning drop-in AddOn. The script shows how to listen to orders on one account and send them to the other account.

                      In regard to your inquiry about partial fills, you could check if the OrderState is OrderState.PartFilled in OnOrderUpdate().

                      See this help guide page for more information about OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm

                      And, see this reference sample demonstrating the use of OnOrderUpdate(): https://ninjatrader.com/support/help...and_onexec.htm

                      Let me know if I may assist further.

                      Brandon H.NinjaTrader Customer Service

                      Comment


                        #26
                        Originally posted by NinjaTrader_BrandonH View Post
                        Hello rocker84,

                        Thanks for your note.

                        I am not able to reproduce the behavior you are reporting when testing the example script shared in post # 4. Note that this is only intended to be an example script, not a fully functioning drop-in AddOn. The script shows how to listen to orders on one account and send them to the other account.

                        In regard to your inquiry about partial fills, you could check if the OrderState is OrderState.PartFilled in OnOrderUpdate().

                        See this help guide page for more information about OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm

                        And, see this reference sample demonstrating the use of OnOrderUpdate(): https://ninjatrader.com/support/help...and_onexec.htm

                        Let me know if I may assist further.
                        yes, its file on post 4. Adding it to a chart duplicates orders on all strategies running on that account. I think I solved it using "e.Order.Instrument" instead of "Instrument"

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by DJ888, Today, 10:57 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by MacDad, 02-25-2024, 11:48 PM
                        7 responses
                        158 views
                        0 likes
                        Last Post loganjarosz123  
                        Started by Belfortbucks, Today, 09:29 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post Belfortbucks  
                        Started by zstheorist, Today, 07:52 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post zstheorist  
                        Started by pmachiraju, 11-01-2023, 04:46 AM
                        8 responses
                        151 views
                        0 likes
                        Last Post rehmans
                        by rehmans
                         
                        Working...
                        X