protected override void OnBarUpdate()
{
if(currentTime <= tradeStartTime || currentTime >= tradeStopTime){
return;
}
else{
// Do all the logic for trading strategy
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to tell Backtest and Optimization to go to next trading day
Collapse
X
-
How to tell Backtest and Optimization to go to next trading day
I want to increase the speed of Optimization for my strategy. I have already done IsInstantiatedOnEachOptimizationIteration=false and coded my strategy to properly reset the variables. My strategy only trades during specific time of the day (e.g. between 9:30am to 12pm). Below is excerpt pseudo code of my strategy.
Based on this pseudo code, during Backtest/Optimization, it is my understanding NT will go through every single bar available and if the bars fall within the given time range, then my trading strategy's logic will execute. How can I properly terminate my strategy if the time range is outside the desired trading time range and inform Backtest/Optimization to go to the next day. This way, we don't waste processor computation and memory on checking bars that are outside of the given time range?Code:Tags: None
-
Hello wzgy0920,
Thank you for your post.
OnBarUpdate() will be called whenever a bar is updated. There is no way to tell OnBarUpdate() not to update at all on a certain condition. Your return statement however will ensure that it will skip any further calculation.
Please let us know if you have any further questions.
-
Is it possible to request a feature to signal the Backtest/Optimization to terminate/skip the processing the strategy for the remaining bars of the trading session? As I mentioned I would like to Backtest/Optimize my strategy for specific time range of the trading session. During Bactest/Optimization NT is spending a lot of processing going through bars that doesn't actually result in strategy usage. This feature would help improve performance.Originally posted by NinjaTrader_Gaby View PostHello wzgy0920,
Thank you for your post.
OnBarUpdate() will be called whenever a bar is updated. There is no way to tell OnBarUpdate() not to update at all on a certain condition. Your return statement however will ensure that it will skip any further calculation.
Please let us know if you have any further questions.
Comment
-
I would also very much like this feature to be implemented.
I have a couple of specific time frames I want to create strategies for, that are between 10 minutes and half an hour.
You would of course need to have the minimum bars needed before the start to have all indicator values used in the strategy correctly reflected etc.
So I'm sure it's not trivial to implement.
It seems that a big improvement can be made for strategies like these if you could specify a start and stop time for the optimization per day (where the strategy can take trades).
- Likes 1
Comment
-
I want to bring your attention to two other related topics (see listed below). If you also are on the same boat as me, please provide your vote to NT dev team so they can increase the priority to improving the performance of Strategy Analyzer.Originally posted by bmggchevalier View PostI would also very much like this feature to be implemented.
I have a couple of specific time frames I want to create strategies for, that are between 10 minutes and half an hour.
You would of course need to have the minimum bars needed before the start to have all indicator values used in the strategy correctly reflected etc.
So I'm sure it's not trivial to implement.
It seems that a big improvement can be made for strategies like these if you could specify a start and stop time for the optimization per day (where the strategy can take trades).
I have questions and suggestions related Strategy Analyzer. 1) Currently the analysis of Optimization results is very very slow and painful. Please improve this. I run Optimization on multiple variables that span multiple weeks. The Optimization itself takes few hours, after which I am presented with top results. When I am
I have few questions about using the Strategy Analyzer and some feedback for improvement. 1) How do I change the default strategy that appears when I go to New >> Strategy Analyzer >> General >> Strategy? Right it seems the list of strategies in the drop down box are alphabetically orders. Essentially I want
Comment
-
Hello wzgy0920,
IsInstantiatedOnEachOptimizationIteration only determines if the strategy should be re-instantiated (re-created) after each optimization run when using the Optimizer.
https://ninjatrader.com/support/help...niteration.htm
The optimal approach to "terminate" a strategy from OnBarUpdate() is to use a return statement. You can also call CloseStrategy().
https://ninjatrader.com/support/help...sestrategy.htm
Please let me know if you have any other questions.
Comment
-
When I call CloseStrategy(), it does not stop the strategy. I checked that after I called CloseStrategy(), the OnBarUpdate() is still being called.Originally posted by NinjaTrader_Gaby View Post
The optimal approach to "terminate" a strategy from OnBarUpdate() is to use a return statement. You can also call CloseStrategy().
Comment
-
Hello,
My apologies, I neglected to mention that CloseStrategy only works in real time. From the Help Guide page:
Warning: This method can only be call before the State has reached State.Terminated and after the State reaches State.Realtime
https://ninjatrader.com/support/help...sestrategy.htm
Instead of CloseStrategy(), you can use SetState(State.Terminated) to abort the strategy as it is running. Doing this in a Strategy Analyzer backtest will abort the backtest entirely, and no partial backtest results will be shown.
SetState() - https://ninjatrader.com/support/help...8/setstate.htm
Please let me know if you have any other questions.
Comment
-
Originally posted by wzgy0920 View Post
Is it possible to request a feature to signal the Backtest/Optimization to terminate/skip the processing the strategy for the remaining bars of the trading session? As I mentioned I would like to Backtest/Optimize my strategy for specific time range of the trading session. During Bactest/Optimization NT is spending a lot of processing going through bars that doesn't actually result in strategy usage. This feature would help improve performance.
This request is being tracked under the number SFT-6312.
As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted on the Release Notes page of the Help Guide.
Release Notes —https://ninjatrader.com/support/help...ease_notes.htm
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
119 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
63 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
45 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
82 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|
Comment