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!
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
NinjaTrader
Account Balance tracking code is printing executions that did not occur
Collapse
X
-
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.
-
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:
Code: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)); } } }
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.
AlecTags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by alifarahani, Today, 09:40 AM
|
6 responses
31 views
0 likes
|
Last Post
by alifarahani
Today, 03:18 PM
|
||
Started by Waxavi, Today, 02:10 AM
|
1 response
17 views
0 likes
|
Last Post Today, 03:03 PM | ||
Started by Kaledus, Today, 01:29 PM
|
5 responses
13 views
0 likes
|
Last Post Today, 02:56 PM | ||
Started by Waxavi, Today, 02:00 AM
|
1 response
12 views
0 likes
|
Last Post Today, 02:53 PM | ||
Is it possible to have a drawing, such as a line, cycle through different colors?
by gentlebenthebear
Started by gentlebenthebear, Today, 01:30 AM
|
3 responses
17 views
0 likes
|
Last Post Today, 02:41 PM |
Leave a comment: