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

Number of opened trades in different Algorithms

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

    Number of opened trades in different Algorithms

    Hi, I a, working on simultaneous algorithms running, the problem I have is the number of contracts I can trade. For that reason I am looking for information to check the number of open trades, is there any variable available to get that? I understand that Position.MarketPosition is only local within the algo.

    Thanks, Marcelo

    #2
    Hello lordvader34,

    You can use the Account Position however this will not work in historical or back testing modes. If you are working with a realtime only strategy which does not need to resume orders or use a Start Behavior you could reference the account position directly in logic by using PositionAccount: https://ninjatrader.com/support/help...ionaccount.htm
    This works in the same way as Position and has the same properties/methods but references the account directly.

    If you needed to know more about the open orders you would need to combine your logic into a single strategy so it can track the information its self. Generally using two strategies toward a common goal is difficult as they are virtualized and not expecting to work with another script. Most frequently it is best to combine both sets of logic into a single strategy that manages multiple positions.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks a lot Jesse, PositionAccount is what I needed. I have 10 algos running simultaneously in different tickers in the same account but cannot trade more than 5 contracts for all those 10 algos.

      Comment


        #4
        This only works for only one ticker, I am using two tickers, NQ 3-20 and YS 3-20, How should I do to support several tickers? Thanks!!!

        Comment


          #5
          Also keep in mind that I have to pull this information to different algorithms in order to check the total simultaneous orders. Thanks!!

          Comment


            #6
            This is the code that I am adding to all the algos. but I noticed if an order it opened manually, the OpenedTrades does not increments.

            protected override void OnBarUpdate()
            {
            .......
            /// Show position size
            Draw.TextFixed(this, "OpTrades","\n\n\n\n\n\t\t" + OpenedTrades , TextPosition.TopLeft, Brushes.Blue, new SimpleFont ("Arial",14), Brushes.Transparent, Brushes.Blue, 0);
            ........


            // Set 1
            if (XXXXXX)
            ......
            && (OpenedTrades<MaxTrades) // If opened trader are LT MaxTrades
            {
            EnterLong(Convert.ToInt32(DefaultQuantity), "");
            }

            }

            protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
            {
            OpenedTrades=quantity;
            }

            The purpose is to count the opened order for all the algos and manually. Thanks!

            Comment


              #7
              Hello lordvader34 ,

              For multiple series you can use PositionsAccount, plural:

              https://ninjatrader.com/support/help...sitionsaccount

              The OnPositionUpdate override will only be called for positions which that current strategy has entered/exited. All other positions held manually or outside of this strategy would be ignored.

              Generally it is not suggested to try and interweave multiple scripts together like this, if the purpose is to trade multiple instruments/timeframes it is much easier to do this in one strategy that targets those instruments/timeframes. If you also want to include manual trades an addon would be better suited for that type of task. A strategy is intended to be virtual and work alone without manual trading. An addon is similar to one of the existing tools like a superdom where it observes an account and the manual/automated orders that are placed to the account.

              I look forward to being of further assistance.
              Last edited by NinjaTrader_Jesse; 01-23-2020, 10:52 AM.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Jesse, thanks for the answer, I have 5 algos working with 2 instruments y 2 timeframes. The suggestion is to combine all this into only one algo? My intention is not controlling any manual trade, all auto trades.Do you have any guideline to merge all the algos?

                Thanks, Marcelo

                Comment


                  #9
                  Hello lordvader34,

                  Correct, if the different scripts need to know something about what the other is doing splitting them up will make that more difficult. A single script can trade multiple instruments or multiple timeframes which also gives it the ability to have information for all of those instruments/timeframes in one place.

                  The platform comes with two sample strategies called SampleMultiInstrument and SampleMultiTimeframe to explore the very basics of this concept. The following page explains this concept in much more detail.

                  https://ninjatrader.com/support/help...lightsub=multi

                  It is more complex to program initially but will give you the ability to control each individual algo based on what the other instruments/timeframes are doing because it is all contained in a single script. If you needed to know that instrument A has an order open or has a position, you could do that because you can store instrument A's order as a variable in the script or use the Positions object to gather multi instrument positions.
                  https://ninjatrader.com/support/help...tsub=positions



                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Philippe56140, Today, 02:35 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Philippe56140  
                  Started by 00nevest, Today, 02:27 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post 00nevest  
                  Started by Jonafare, 12-06-2012, 03:48 PM
                  5 responses
                  3,986 views
                  0 likes
                  Last Post rene69851  
                  Started by Fitspressorest, Today, 01:38 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Fitspressorest  
                  Started by Jonker, Today, 01:19 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Jonker
                  by Jonker
                   
                  Working...
                  X