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
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.Emily C.NinjaTrader Customer Service
-
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
-
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.Emily C.NinjaTrader Customer Service
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 aligator, 01-06-2022, 12:14 PM
|
4 responses
233 views
0 likes
|
Last Post
by john_44573
Today, 06:11 PM
|
||
Started by reynoldsn, Today, 05:56 PM
|
0 responses
4 views
0 likes
|
Last Post
by reynoldsn
Today, 05:56 PM
|
||
Started by bortz, 11-06-2023, 08:04 AM
|
51 responses
1,989 views
0 likes
|
Last Post
by aligator
Today, 05:50 PM
|
||
Started by dmking, 11-12-2019, 12:31 PM
|
4 responses
4,150 views
0 likes
|
Last Post
by jasonw
Today, 04:32 PM
|
||
Started by roblogic, Today, 04:31 PM
|
0 responses
10 views
0 likes
|
Last Post
by roblogic
Today, 04:31 PM
|
Comment