Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest - Simple position sizing based on account size & trade performance

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

    Backtest - Simple position sizing based on account size & trade performance

    Hello,
    I have various strategies where I would like to set the position size based on how the strategy is doing. Sadly I never really found a thread where this was covered. A few years ago I just used "by account value" of Strategy Analyzer in NT7 but in NT 8 this is not available.

    So three things would need to be done.

    1. Setting up the account with an initial value.
    (Declaring a double variable?)

    2. Calculating position size based on last stock price
    (Divide part of account value by last available instrument price and round down)

    3. Update account value based on the latest total net profit discarding the initial setup value and adding or subtracting from that

    I tried a bit but nothing worked and just gave me various errors. However, I think this should be rather straightforward.
    I just need some sample code where this is somehow demonstrated.
    Last edited by FoersterX; 04-23-2020, 11:48 PM.

    #2
    Wanted to edit my post, put it says "Sorry, you are not authorized to view this page".


    In another software I have this is written in basic and the backtest code there looks something like this:

    Capital = 500000
    Risk = 0.05
    equity = Capital + StrategyProfit
    maxrisk= round(equity*Risk)
    PositionSize = abs(round((maxrisk/tradeprice)))
    Last edited by FoersterX; 04-24-2020, 12:02 AM.

    Comment


      #3
      Hello FoersterX ,

      Welcome to the NinjaTrader support forums.

      The items you listed are certainly possible however you will need to implement that yourself.

      1). the most simple way forward with this would be to make a user input so you can type in a value and have the script read from that. You can create inputs using the strategy builder or see the SMA indicator and copy its Period property into your script and edit it. An int input could be used for this.

      2). It looks like you updated to have a general sample, that is also essentially already NinjaScript with some slight modifications. You would need a few variables for what you have shown and the math functions can be accessed by using C#'s Math: https://docs.microsoft.com/en-us/dot...tframework-4.5

      3). You can see this sample for information on how to work with the realized pnl, this information could be used in a similar way to what is shown to calculate a new account balance or do other tasks. https://ninjatrader.com/support/help...nce_statis.htm

      If you have tried something already or after reviewing this try something new and it does not work please provide a sample of what you tried in NinjaScript and we can likely provide more help with that.

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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by mattbsea, Today, 05:44 PM
      0 responses
      2 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      31 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      2 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,281 views
      0 likes
      Last Post Leafcutter  
      Started by WHICKED, Today, 12:45 PM
      2 responses
      19 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Working...
      X