Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
OnBarClose and OnPriceChange in the same indicator
Collapse
X
-
Hello cay7man,
Thank you for your post.
Yes, this would be possible by setting Calculate to Calculate.OnPriceChange in OnStateChange() when State == State.SetDefaults. Then, inside of OnBarUpdate(), you could separate out logic that you would like to be calculated on bar close within a check for when IsFirstTickOfBar is true. Here is the help guide page for IsFirstTickOfBar:
We have a strategy reference sample that demonstrates separating logic to calculate either on bar close or on every tick that uses IsFirstTickOfBar:
Please let us know if we may be of further assistance.
- Likes 1
-
Hello cay7man,
Thank you for your reply.
On Price Change will call OnBarUpdate() for every price change during real-time data. In historical processing, OnBarUpdate() is only processed on bar close unless Tick Replay is enabled:
Please feel free to reach out with any additional questions or concerns.
- Likes 1
Comment
-
Ok. I'm not sure what I'm doing wrong. I've the following in the code
Calculate = Calculate.OnEachTick;
protected override void OnBarUpdate()
{
Draw.TextFixed(this, "NinjaScriptInfo",string.Format("{0}",Close[0]), TextPosition.BottomRight);
}
I don't see price changing during intra bar. Its printing previous bar close. Close[0] is incorrect? What should I use to get the current price?
Comment
-
Hello cay7man,
Thank you for your reply.
Do you get any errors on the Log tab of the Control Center? I was able to get both of the following TextFixed objects to update the Close[0] price on each tick:
Be sure to double-check in the indicator settings when you are configuring it that Calculate is set to OnEachTick:Code:protected override void OnBarUpdate() { Draw.TextFixed(this, "tag", Close[0].ToString(), TextPosition.BottomRight); Draw.TextFixed(this, "tag1", string.Format("{0}", Close[0]), TextPosition.BottomLeft); }
World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.
You could also consider adding prints in OnBarUpdate() to verify the value of calculate and see how frequently it is printing. For example:
Print(string.Format("{0} state: {1} calculate: {2}", Time[0], State, Calculate));
This is also a good way to see that when the state is Historical, OnBarUpdate() is only processed once per bar regardless of what Calculate is set to. Once the state is Realtime, you should see prints in OnBarUpdate() that correspond with what Calculate is set to.
Please let me know if I may be of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
553 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
100 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
543 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
546 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment