Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

¿how can i get nt to establish position size according to cumulative profits/losses?

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

    ¿how can i get nt to establish position size according to cumulative profits/losses?




    people with nt,



    regards.



    i consider that nt support is consistently very good but it has badly let me down with the latest several requests i have made. in this case, i think the nt platform is perfectly capable of doing what i have in mind.




    right now when i backtest or optimize strategies on historical data i use a fixed position size of one single contract (1). however, in real life it is completely reasonable to assume that if one is significantly increasing one's capital one would also increase the position size that one would trade at some point in time.



    ¿how could i do so that my strategy used a variable position size according to cumulative profits - losses?


    i would like nt to assume an initial capital of 2 times the initial margin for the contract i'm evaluating.

    - the initial position size to trade would be 1.

    - if losses bring the available capital down below 1 time the initial margin for the contract then the position size should be 0.

    - however, the position size for any trade should be determined by dividing the available capital (assuming profits have been accumulated) between 2 times the initial margin at that moment.


    ¿how can nt check the level of cumulative profits - losses when performing backtest - optimization processes? ¿can nt know the amount required as initial margin for a particular contract? ¿can nt determine what the amount required as initial margin was at different points in the past? i'm sure the platform can easily establish how much capital is available in an account but if it also was able to determine the amount required as initial capital per instrument and its historical values that would be really impressive.


    very well, regards.

    #2
    Hello rtwave,

    This would be something you need to track yourself and calculate prior to placing your orders. The platform has no mechanism to do these type of calculations for you as there is no account being referenced in the backtest. The Backtest account is being used but would not have any specific starting balance or margin to hit so those type of values would be something you need to program into your strategy directly if you wanted to test that.

    You could look into using the trade performance information to collect the profits and then use that for controlling other calculations. For position sizing and knowing how much account value you have these are items you would need to make yourself by using variables and logic/math.

    https://ninjatrader.com/support/help...nce_statis.htm

    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 02-11-2020, 08:18 AM.

    Comment


      #3



      people with nt,



      thanks.


      i will take a look at the link and samples that have been shared.


      i just want to understand and make sure that the terminology we are using is similar enough; you state that there is no account referenced in a backtest, but ¿is it not that the profits and losses in the image below are accumulated in some sort of account somewhere? ¿what do the line and the shaded areas represent then? it is precisely the information reflected by those line and shaded areas that i was thinking that could be used to establish the performance of the strategies at any point and to determine the appropriate position size that it should use.



      Click image for larger version

Name:	nt strategy and account 001.JPG
Views:	217
Size:	266.8 KB
ID:	1086888



      i find it surprising that nt does not have any problem knowing the ticker, exchange, instrument settings, tick value, point value and many other attributes for any particular instrument it can operate but it would not know anything about initial margin or cumulative profit or loss for a strategy at any given moment.

      Comment


        #4
        Hello rtwave,

        I had mentioned what account is being used in my last post:

        The Backtest account is being used but would not have any specific starting balance or margin to hit so those type of values would be something you need to program into your strategy directly if you wanted to test that.
        You are looking at a backtest so your actual accounts are not being figured in here, this tool is using the internal account "Backtest" which does not have any type of configuration options. The account just exists to collect data and make the strategy perform as it would during historical/normal trading. In general there is not a way to have the platform calculate position size automatically in the way that you want so this would still be something that you would have to calculate yourself even if a normal account was being used in the backtest.


        i find it surprising that nt does not have any problem knowing the ticker, exchange, instrument settings, tick value, point value and many other attributes for any particular instrument it can operate but it would not know anything about initial margin or cumulative profit or loss for a strategy at any given moment.
        Profit and loss are known, only margin would be something you need to define in your logic if you wanted to use that.. You can see the following strategy reference sample for working with trade performance and PNL: https://ninjatrader.com/support/help...nce_statis.htm

        I look forward to being of further assistance.

        Comment


          #5



          regards to everyone,



          i have continued to work on this particular objective and i think i have now been able to create code that will determine the position size to be traded according to the strategy's performance. i share the code in case it could be helpful to other users:


          one needs to create dependent variables both for the approximate cumulative performance of the strategy and the number of contracts to be traded:

          private double account balance = 0;
          private int number of contracts = 0;


          one also needs to create two inputs for the initial capital and the capital required for every single contract:

          [NinjaScriptProperty]
          [Range(1, double.MaxValue)]
          [Display(Name="initial capital", Description="initial capital", Order=1, GroupName="Parameters")]
          public double initial capital
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, double.MaxValue)]
          [Display(Name="contract margin", Description="contract margin.", Order=2, GroupName="Parameters")]
          public double contract margin
          { get; set; }


          and then with a little basic algebra and basic arithmetic it is possible to have the platform use a number of contracts to trade that depends on the performance of the strategy. i thought i needed to use a switch - case - break structure but it is never covered in the help guides and it seems to me like mutually exclusive conditional statements work just as well. i added this code inside the on bar update section and substituted the number of contracts variable in all the entry and exit commands:


          account balance = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit + initial capital ;


          if ( account balance < contract margin )
          {

          number of contracts = 0;

          }

          else if ( ( contract margin <= account balance )
          && ( account balance <= ( contract margin * 2 ) ) )
          {

          number of contracts = 1;

          }

          else if ( ( contract margin * 2 ) < account balance )
          {

          number of contracts = ( (int) ( account balance / ( contract margin * 2 ) ) ) ;

          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          68 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X