• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Account Balance tracking code is printing executions that did not occur

  • Filter
  • Time
  • Show
Clear All
new posts

  • NinjaTrader_Jim
    Hello GreenspanAlec,

    Welcome to the forums!

    When a baskest test is run or an optimization backtest is preformed, NinjaTrader performs a "Details run" which is used to populate the Results grid. If you are comparing output from a basket test, the ID's that get printed out in the Output Window may not necessarily correspond to the same ID's listed when reviewing the strategies results.

    Demo - https://drive.google.com/file/d/1a-C...w?usp=drivesdk

    As we can see, when we switch instruments, we see a "Details run" performed and not the complete backtest. These values are then consistent when we compare ID's because the ID's were generated with that last "Details run."

    You are really running into separate functionality NinjaTrader utilizes to populate Results grids and other grids which shouldn't be confused with your actual backtests. You wouldn't see this unless you were comparing the results to the prints in your output window. I recommend moving forward by comparing the output window to individual backtests and to avoid comparing the output window of basket and optimization backtests to the results grids.

    Please also note the Strategy Analyzer was not designed to utilize a full account for portfolio management when backtesting. You can add a variable for account funds to implement this functionality, but this variable will be separate for each strategy instance. In other words, the strategy will have a different amount of "funds" when backtesting multiple instruments, because we are testing separate instances of that strategy against separate instruments.

    You could consider creating a multi time frame script which trades all of the symbols the strategy will operate with, and the funds from your strategy will be shared since you will then have one strategy that trades multiple symbols.

    Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

    We look forward to assisting.

    Leave a comment:

  • Account Balance tracking code is printing executions that did not occur

    Hi all,

    To track account balance and use it in my backtest model I have put the following code at the end of my script:

            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
        if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
            if(execution.Order.Name == "BrunsBuy")
            AcctValue = (AcctValue - ((execution.Price)* execution.Quantity));
            Print(AcctValue.ToString()+" - "+(execution.OrderId)+" "+(execution.Time));    
    When this runs on one instrument I get the expected results that match exactly what the strategy did:

    MTCH Output:
    4919.42 - NT-00000-1418 12/24/2019 12:00:00 PM

    AMD Output:
    4953.23 - NT-00000-1435 12/26/2019 3:00:00 PM
    4898.43 - NT-00002-1435 2/14/2020 3:00:00 PM

    When it runs on the instrument list of the above items I get the following:
    4953.23 - NT-00000-1452 12/26/2019 3:00:00 PM Order ID did not happen
    4898.43 - NT-00002-1452 2/14/2020 3:00:00 PM Order ID did not happen
    4919.42 - NT-00000-1453 12/24/2019 12:00:00 PM Order ID did not happen
    4851.66 - NT-00000-1459 12/26/2019 3:00:00 PM This Order ID occurred
    4796.86 - NT-00002-1459 2/14/2020 3:00:00 PM This Order ID occurred
    4838.84 - NT-00000-1467 12/24/2019 12:00:00 PM This Order ID occurred

    I'm just running this on the buy executions right now. Where are these random buy IDs coming from when I run this on two instruments at once? These are no where to be found in the strategy analyzer. Note how the output did not print them in chronological order either... which is weird to me.


Latest Posts


Topics Statistics Last Post
Started by soulfx, Today, 03:57 AM
0 responses
1 view
Last Post soulfx
by soulfx
Started by digibob, Today, 03:45 AM
0 responses
1 view
Last Post digibob
by digibob
Started by Matts7, Today, 12:56 AM
1 response
Last Post NinjaTrader_Marco  
Started by barrybrice, Yesterday, 08:51 PM
1 response
Last Post NinjaTrader_Marco  
Started by hayleeabb, Today, 12:30 AM
1 response
Last Post NinjaTrader_ChrisSch