Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position Sizing During Backtest

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

  • trend747
    replied
    Ok, just sent. Thanks so much for your prompt attention. Your support is top notch!

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    Too bad, sure please send it over to support at ninjatrader dot com to my Attn.

    Thanks,

    Leave a comment:


  • trend747
    replied
    It's not working Bertrand. I forgot to remove the hardcoded number that we put in there... LOL. Can you take a look at this code?

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    Since the hardcoded entry is working out fine, the issue is to be found in your code - are you using a public property for positionsize as well here? If you send your script to support we could give it a run here as well.

    Leave a comment:


  • trend747
    replied
    Here's the output from the Print() statements of what I just ran. As you can see, the positionSize variable is being populated correctly:

    My account size is: 9814.79010000007
    My risk amount is: 1.06682501086957
    My first position size is: 10668.2501086957
    My final position size is: 10668

    Leave a comment:


  • trend747
    replied
    Originally posted by NinjaTrader_Bertrand View Post
    If you directly enter your position size needed hard-coded in the EnterLong() for a test - would it then use the qty specified?
    Yes. I used a random number (123485) and it used it.

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    If you directly enter your position size needed hard-coded in the EnterLong() for a test - would it then use the qty specified?

    Leave a comment:


  • trend747
    replied
    Originally posted by NinjaTrader_Bertrand View Post
    trend747, if you startup the strategy by what are you then defining position size, ByDefaultQuantity or ByStrategy?
    ByStrategy

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    trend747, if you startup the strategy by what are you then defining position size, ByDefaultQuantity or ByStrategy?

    Leave a comment:


  • trend747
    started a topic Position Sizing During Backtest

    Position Sizing During Backtest

    I know it's not officially supported, but I was told that you could use the Performance class to do position sizing for backtests.

    Check out this code:

    Code:
    if (Demo == true && Realtime == false)
                {            
                    //Print("My account size is: " + (Performance.AllTrades.TradesPerformance.Currency.CumProfit + AccountSize));
                    double myRiskAmount = ((Performance.AllTrades.TradesPerformance.Currency.CumProfit + AccountSize) * (RiskPercentage * .01) / SL);
                    //Print("My risk amount is: " + myRiskAmount);
                    double myPositionSize = (myRiskAmount * 10000);
                    //Print("My test position size is: " + myPositionSize);
                    int PositionSize = (int)myPositionSize;
                    //Print("My final position size is: " + PositionSize);
                }
    All of those print statements was me testing my code. Basically, the final position size shows the correct position size -- let's say, for example, 11980 units.

    Then this is my entry code:

    Code:
    if (Close[0] > Close[1])
    {
       EnterLong(PositionSize);
    }
    But it still enters whatever is specified in the parameters... I don't understand that... I mean, it's in the code... it should work.
    Last edited by trend747; 07-13-2011, 09:29 PM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by CaptainJack, 05-29-2026, 05:09 AM
0 responses
310 views
0 likes
Last Post CaptainJack  
Started by CaptainJack, 05-29-2026, 12:02 AM
0 responses
200 views
0 likes
Last Post CaptainJack  
Started by charlesugo_1, 05-26-2026, 05:03 PM
0 responses
186 views
1 like
Last Post charlesugo_1  
Started by DannyP96, 05-18-2026, 02:38 PM
1 response
278 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by CarlTrading, 05-11-2026, 05:56 AM
0 responses
229 views
0 likes
Last Post CarlTrading  
Working...
X