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

Problem backtesting with strategy managed position size

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

    Problem backtesting with strategy managed position size

    Hello,

    I am having an issue when backtesting where if I have my strategy manage the position size then it will stop executing trades on a particular instrument at a seemingly random point of the back test. If I back test the same instrument with a default position size selected then it continues to execute trades throughout the backtest period as expected.

    I'm using this code to determine my position size, and according to the number of shares traded throughout the back test, it appears to work fine until a certain point, after which all trades stop.

    if (((AccountSize/100) / price) >= 1)
    {

    EnterShortLimit(0, true, Convert.ToInt32(((AccountSize/100) / price)), (Close[0] * (1 + ((NATR1[0] * EntryFx) / 100))), @"shortOrder");

    }


    If I backtest on a basket of stocks, there will be a large number of stocks that stop trading at a seemingly random point in the backtest, and many other stocks that never stop trading throughout the backtest. The results are the same if I re-run the test, or if I then run backtests on each stock of the basket test individually. But like I said, if I then change the backtest parameters to manage position size my default and set it to any number, then all stocks trade throughout the entire backtest period without any issues...

    Thoughts??

    Thank you.

    #2
    Hello RobotSyndicate,

    From the given details its hard to say what may cause that. Are you getting any errors or output in the log or output window?

    If we can focus on the test that involves 1 instrument that will help, likely the basket shares the same issue.

    I could suggest to make a very simple test strategy that has the logic you have shown and maybe use BarsSinceEntryExecution to control exiting a few bars later to complete the loop and keep it simple. If that type of test shows the problem that would be helpful for finding the answer.



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

    Comment


      #3
      Hi RobotSyndicate,
      Couple of questions:
      1) How do you determine "AccountSize", is that the (fix) StartCapital or the (floating) CurrentTotalEquity?
      2) What's the price range of the instruments you are trading?
      3) Does the strategy stop to trade the more "expensive" instruments or also the "cheap" stuff?
      I suggest to add a print of (AccountSize/100) / Price to the Output Window to check the result of your calculation.
      Stocks have a long bias. Thus, an appreciation in price could perhaps explain why the strategy "has" to stop trading the stocks (which have become more expensive) at.some point in time ...
      NT-Roland

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by gravdigaz6, Today, 11:40 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by MarianApalaghiei, Today, 10:49 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by XXtrader, Today, 11:30 PM
      0 responses
      4 views
      0 likes
      Last Post XXtrader  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      9 views
      0 likes
      Last Post funk10101  
      Working...
      X