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
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.Emily C.NinjaTrader Customer Service
- 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.Emily C.NinjaTrader Customer Service
- 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:
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); }
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.Emily C.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ZeroKuhl, Today, 04:31 PM
|
0 responses
7 views
0 likes
|
Last Post
by ZeroKuhl
Today, 04:31 PM
|
||
Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
|
54 responses
5,336 views
0 likes
|
Last Post
by Gaterz
Today, 04:29 PM
|
||
Started by ETFVoyageur, 05-07-2024, 07:05 PM
|
11 responses
73 views
0 likes
|
Last Post
by -=Edge=-
Today, 04:27 PM
|
||
Started by _Zero_, 04-10-2020, 03:21 PM
|
145 responses
7,899 views
6 likes
|
Last Post
by johng2
Today, 04:19 PM
|
||
Started by TheTradingMantis, 01-19-2023, 02:05 AM
|
43 responses
917 views
0 likes
|
Last Post
by jmagaia
Today, 04:13 PM
|
Comment