Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to call OnBarUpdate function 3 seconds before candle is rendered.
Collapse
X
-
Hello Mykhailo,
Thank you for your post and welcome to the NinjaTrader forum community.
OnBarUpdate() is an event-driven method, so there is no way to call it manually. It is called based on the Calculate property for the script, which can be set to call OnBarUpdate() either On Bar Close, On Price Change, or On Each Tick. More information may be found at the links below:- https://ninjatrader.com/support/help...nbarupdate.htm
- https://ninjatrader.com/support/help.../calculate.htm
I look forward to your reply.
-
Thank you for your quick replay. My problem is want to set strategy logics before bartime(in seconds) from rendering new candle. So I want to use dataseries like
if (State == State.Configure) {
AddDataSeries(BarsPeriodType.Second, 1);
}
And i displayed time on bottom right corner, but it was not accurate. Times sometimes skips two or three.
Is there any way to do so?
1 Photo
Comment
-
If you call AddDataSeries() to add a 1 second series, then you could access the timestamps of the 1-second bars via Times[1][barsAgo]Originally posted by Mykhailo View PostThank you for your quick replay. My problem is want to set strategy logics before bartime(in seconds) from rendering new candle. So I want to use dataseries like
if (State == State.Configure) {
AddDataSeries(BarsPeriodType.Second, 1);
}
And i displayed time on bottom right corner, but it was not accurate. Times sometimes skips two or three.
Is there any way to do so?
You could then potentially create a condition that checks if the 1-second timestamp is a certain value that would be 3 seconds prior to the close of the main series.
For more information on working with multi-series scripts:
Please let us know if we may be of further assistance.
Comment
-
protected override void OnStateChange()
{
if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Second, 1);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress == 0){
} else if (BarsInProgress == 1) { // 1s chart
Print( Times[1][0]);
}
//Add your custom strategy logic here.
}
When i run this code, i got such result.
2024-03-13 19:29:00
2024-03-13 19:29:04
2024-03-13 19:29:05
2024-03-13 19:29:07
2024-03-13 19:29:08
2024-03-13 19:29:09
2024-03-13 19:29:13
2024-03-13 19:29:14
2024-03-13 19:29:16
2024-03-13 19:29:17
2024-03-13 19:29:20
2024-03-13 19:29:21
2024-03-13 19:29:23
2024-03-13 19:29:25
2024-03-13 19:29:26
2024-03-13 19:29:28
2024-03-13 19:29:30
but i want to get every all seconds. current TF is 1min.
Comment
-
Hello Mykhailo,
It may be there was not any volume during that second and no bar was formed.
If you open a new chart with a 1 second data series, are you seeing the missing 1 second bars on the chart?
Are you able to reproduce this on an ES 06-24 chart?Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
54 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
131 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment