Any idea as to why this might be happening?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy in Market Replay mode slows to real time only when position opened
Collapse
X
-
Strategy in Market Replay mode slows to real time only when position opened
I am having an issue with a custom strategy that I am testing that when tested in market replay model slows down to real time as soon as a position is opened. I can set it a 500x speed and it will play back at this speed properly but as soon as the strategy opens a position, the playback speed slows down to near real time.
Any idea as to why this might be happening?
Tags: None
-
Hello Jdmtrader,
Thank you for your post.
So I may accurately assist you, please answer all of the following questions:- What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
- What instrument symbol (and expiry if applicable) have you selected? For example, ES 03-22, AAPL, EURUSD, etc.
- What interval is selected? For example, 5 minute, 1 day, 2000 volume, 4 Renko, etc.
- Do you receive an error on the screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
- Does this only happen when testing a NinjaScript strategy or are you able to reproduce when opening a position manually during playback?
- Does the playback controller still show 500x speed or does it show a slower speed multiplier?
Emily C.NinjaTrader Customer Service
-
I am using NinjaTrader 8 version 8.0.28.0
ES 09-23, 5 MIN. I dont receive any error. The trade is opened properly, its just that market replay slows down to near real time. No errors in log.
It only happens when a strategy opens a position. If I open a position manually, it does not cause this to happen. It still shows 500x, even though the playback speed is showing seconds moving at real time or near real time.
Comment
-
Hello Jdmtrader,
Thank you for your reply.
It sounds like this may be related to a performance impact. Please try the following to test this in a blank workspace and only open a chart for the instrument you are running the strategy on:- Shut down NinjaTrader
- Navigate to the Documents\NinjaTrader 8\db\replay folder
- Temporarily move all files/folders except for the instrument and date(s) you are testing in playback to a new folder on the desktop
- Launch NinjaTrader
- Go to Control Center > Workspaces > New
- Name the new workspace
- Go to Control Center > Workspaces and close any workspaces that are still open other than the new workspace you just created
- Connect to the playback connection
- Select Control Center > New > Chart and set up a chart for the instrument you are testing on
- Run the strategy and take note of the replay speed when a position is opened
If you are still able to reproduce the apparent slowdown in playback, please provide the strategy being used as well as the steps to reproduce the behavior so I may test on my end.
I appreciate your patience and look forward to hearing the results.Emily C.NinjaTrader Customer Service
Comment
-
I have resolved the issue related to the performance impact.
However, I am having an issue related to an indicator that must run on onbarclose that is added into a strategy. I need the logic in OnBarUpdate in the strategy to run oneachtick, but the indicator added in the strategy using AddChartIndicator(IndicatorX) within State == State.DataLoaded to only update onbarclose.
Correct me if I am wrong, but if the Calculate setting is OnBarClose (Calculate.OnBarClose), I won't be able to get tick-level granularity inside the OnBarUpdate() method. This is because with Calculate.OnBarClose, OnBarUpdate() is only called once per bar - at the close of the bar. Is it possible to have the strategy default to onbarclose but allow logic within the onbarupdate to calculate oneachtick?
The intent of this is because the indicator being added in the strategy can't have anything updated that it draws until each bar closes, otherwise, the drawn object may be presented prematurely and incorrectly because its calculating oneachtick vs onbarupdate.
My solution is to update my indicator so within the onbarupdate, I force it by adding after onBarUpdate
if (!IsFirstTickOfBar) return;
This would ensure the indicator's calculations are effectively performed once per bar (i.e., on bar close), even though the strategy's calculation mode is set to Calculate.OnEachTick. While the calculation mode of the indicator set in its defaults can't stop the strategy from calling the indicator's OnBarUpdate() method on each tick, checking IsFirstTickOfBar can stop the indicator from doing any meaningful calculations until the bar closes.
My workaround would make the indicator behave as if it's operating on bar close, even though it technically gets called on each tick when it's added to a strategy that calculates on each tick.
Is this the correct way to do it?
Last edited by Jdmtrader; 07-05-2023, 07:20 PM.
Comment
-
Hello Jdmtrader,
Thank you for your reply.
Glad to hear you got the performance impact resolved. When it comes to a host script calculating on each tick and a hosted script, such as your indicator in this case, calculating on bar close, you are correct. You could use IsFirstTickOfBar in your logic to ensure that the indicator calculations are only processed once per bar. You could do it either as if (!IsFirstTickOfBar) return; followed by your indicator logic, or you could create a block of code within the condition if (IsFirstTickOfBar) and include your indicator logic within the actions of that condition. We have a reference sample that demonstrates how to separate logic to calculate on bar close or on each tick that may be found in the help guide here:
Please feel free to reach out with any additional questions or concerns.Emily C.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by gustavobp, Today, 03:15 AM
|
0 responses
5 views
0 likes
|
Last Post
![]()
by gustavobp
Today, 03:15 AM
|
||
Started by gustavobp, Today, 03:00 AM
|
0 responses
5 views
0 likes
|
Last Post
![]()
by gustavobp
Today, 03:00 AM
|
||
Started by nicbizz, Today, 02:14 AM
|
0 responses
5 views
0 likes
|
Last Post
![]()
by nicbizz
Today, 02:14 AM
|
||
Started by Ringer13, Today, 01:59 AM
|
0 responses
7 views
0 likes
|
Last Post
![]()
by Ringer13
Today, 01:59 AM
|
||
Started by NINZAMANA, 02-06-2025, 09:03 AM
|
2 responses
25 views
0 likes
|
Last Post
![]()
by Fertryd2
Today, 01:51 AM
|
Comment