Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automated strategies -- limit total position size?

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

    Automated strategies -- limit total position size?

    Hello,

    I am looking for a way to code my strategies so that I can control the number of entries per instrument in a single direction. For example I have algos that trade both CL and NG, and I don't want to be in more than let's say 3 lots for either instrument, in the same direction. So if I'm running 20 CL algos, I want to code them so that they can judge how many contracts are already in play, and then not enter any new trades if the max limit is reached. So let's say I am already long 3 CL, and another long CL algo gets a signal to enter, it will not do so because the maximum limit of 3 positions are already in the market. Ideally however, if it was a SHORT algo that wanted to execute, it would still be able to do so.

    Is there a way that this can be coded?

    Regards,

    Andrew

    #2
    Hello Andrew,

    Thank you for your post.

    This can be coded, but requires some unsupported code. This is due to the fact that the strategies will maintain and pull from their own position and instrument with no real communication between the other strategies running and no real sync to the account aside form the initial sync when starting the strategy with Sync Account = True;.

    You would need to pull from the account it's positions and then instruments for those positions. The following is unsupported code that will pull the account positions and instruments for those positions:
    Code:
    			foreach (Account acct in Cbi.Globals.Accounts)
    			{
    			if (acct.Positions != null)
    			{
    			PositionCollection positions = acct.Positions;
    			foreach (Position pos in positions)
    			{
    			Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
    			}
    			}
    			}

    Comment


      #3
      I'm doing something like this, trying to get account balance, using GetAccountValue, but it always returns zero (0).
      1) Does anyone have this working?
      2) Any way to get required margin on a futures contract?
      Thanks.

      Comment


        #4
        Hello kenz987,

        Thank you for your post.

        GetAccountValue() will return 0 on historical bars, this includes backtests in the Strategy Analyzer.
        For information on GetAccountValue() please visit the following link: http://ninjatrader.com/support/helpG...countvalue.htm

        Comment


          #5
          Thank you Patrick,
          I did that, still get 0 on new bars in onbarupdate.
          edit: wait, even new bars coming in in the backtester?
          if so, makes it hard to test.
          I want to get balance at start up and calculate the max contracts per futures contract and I would like to get margin somewhere in the script also.
          Will ver 8 have better account access functions?
          Last edited by kenz987; 08-18-2015, 06:42 AM.

          Comment


            #6
            Hello kenz987,

            The GetAccountValue() will return 0 on historical bars, this includes the entire backtest period.

            This would need to manually created and tracked on historical bars in both NinjaTrader 7 and 8.

            Comment


              #7
              Not a real problem for me since I only trade a few contracts on a small account, but for guys doing real online automated trading I can see it would be a big problem, You guys have an opportunity now with ver 8 to supply much needed functions for account information. Why not make it available in OnStartUp? Doesn't matter if it is historical or not!

              Comment


                #8
                Hello kenz987,

                Thank you for your response.

                I will forward your suggestion to our development team.

                Comment


                  #9
                  This is an issue which has been resolved with the new architecture of NinjaScript in NinjaTrader 8. We have leaned towards exposing objects along with their public properties, rather than using interfaces and Get methods to wrap around the objects.

                  In NinjaTrader 8, you can use the Account class to obtain this information, even on historical bars or in the early initialization States of the script. The following code would return a reliable value on historical data:

                  Code:
                  Account.GetAccountItem(AccountItem.CashValue.Currency.USDollar).Value
                  Keep in mind that this does not store snapshots of account values at the times represented by historical bars, but it can pull your current account value at any time in the script, allowing you to set up the kind of parameters you mentioned.
                  Last edited by NinjaTrader_DaveI; 08-18-2015, 12:45 PM.
                  Dave I.NinjaTrader Product Management

                  Comment


                    #10
                    The request to track account value on historical tests is being tracked under SFT-620.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Mestor, 03-10-2023, 01:50 AM
                    16 responses
                    387 views
                    0 likes
                    Last Post z.franck  
                    Started by rtwave, 04-12-2024, 09:30 AM
                    4 responses
                    31 views
                    0 likes
                    Last Post rtwave
                    by rtwave
                     
                    Started by yertle, Yesterday, 08:38 AM
                    7 responses
                    29 views
                    0 likes
                    Last Post yertle
                    by yertle
                     
                    Started by bmartz, 03-12-2024, 06:12 AM
                    2 responses
                    22 views
                    0 likes
                    Last Post bmartz
                    by bmartz
                     
                    Started by funk10101, Today, 12:02 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post funk10101  
                    Working...
                    X