Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Accessing EMA value within OnMarketUpdate
Collapse
X
-
Accessing EMA value within OnMarketUpdate
I have been trying to access and ema value within the OnMarketData function but it doesn't seem to work. I tried to set a CrossAbove event to see if price crossed and EMA and nothing happens I have no compile error. It just never seems to get triggered.Tags: None
-
Hello Itachi,
CrossAbove() and CrossBelow() are for OnBarUpdate() as these are using bars series information, which updates in OnBarUpdate().
If you need to have this update for each tick or price change, use the Calculate.OnPriceChange or Calculate.OnEachTick.
In historical this will also mean TickReplay will need to be enabled, and if you placing orders, 1-tick intra-bar granularity.
https://ninjatrader.com/support/foru...377#post773377
That said, the EMA is accessible in OnMarketData(), it just won't be updated to a new value until OnBarUpdate() runs.
Try printing the value in OnMarketData().
Print(EMA(5)[0]);Chelsea B.NinjaTrader Customer Service
-
It sounds like you're trying to put a square peg into a round hole here. The purpose of OnBarUpdate is to perform calculations that need to be performed when the bar series related information has changed. That's why it's called "on bar update". OnMarketData is for when you need things like bid or ask updates but there has not been a new trade.
If you're trying to check for a cross over or under of an EMA, that is bar-related; ergo, it should be in OnBarUpdate unless you have a really compelling reason it should be in OnMarketData.
You need to decide, as NinjaTrader_ChelseaB has suggested, if you want intrabar updates or not. If you want only closed bar crossovers, set Calculate = Calculate.OnBarClose, and put your crossover logic in OnBarUpdate. If you want intrabar crosses, understanding that they may cross and cross back a hundred or a thousand times in one bar, set Calculate = Calculate.OnPriceChange, and put your crossover logic in OnBarUpdate.
Put OTHER logic in OnMarketData if it has to do with bid or ask updates, or if it has to do with price changes but your indicator/strategy itself is running in Calculate = Calculate.OnBarClose, yet, whatever you are doing in OnMarketData does not need up-to-date bar series information e.g. no indicators like EMA.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 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
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
574 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment