Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
EMA cross
Collapse
X
-
Not if you are using Limit orders. The order will be submitted at the Limit price, and the backtest/optimize engine will only fill the order if the price bar on which the order is placed actually intersects the limit price. That is how I optimize my entry offsets.Originally posted by mateo321 View PostStrategy takes signals based on EMA crosses on 5 min chart. With offset set to zero the price I'm getting (in the backtest) is the close of the bar on which the cross has occured. With offset set to lets say to -3 pips I'll still be getting the close of that bar (or opening of the next one because it's the same thing) because alghoritm can give you only one of those four prices (open,high, low, close) and you're getting whichever is closer to the price where your signal fired off.
That's why you need to look inside the bar
Comment
-
Here's the code after applying limit orders. The backtest results I get with this shouldn't be any different from the previous version with market orders or maybe I'm wrong ?
if (CrossAbove(EMA(8), EMA(21), 1))
{
ExitLongLimit(Close[0] + Of_S * TickSize, "", "");
EnterShortLimit(DefaultQuantity, Close[0] + Of_S * TickSize, "");
}
// Condition set 2
if (CrossBelow(EMA(8), EMA(21), 1))
{
ExitShortLimit(Close[0] + Of_L * TickSize, "", "");
EnterLongLimit(DefaultQuantity, Close[0] + Of_L * TickSize, "");
}
Comment
-
mateo, depending on what you're trading, the open could be vastly different from the close, especially if the bars are 5 minutes or longer. Say a tick comes in for July crude at 11:59:58 at 100.00 on a 5 minute bar. The next tick occurs at 12:03:56 at 100.83. This tick will generate the close of the previous bar, which would then also generate your order at 100.00. The open of the next bar, however, would be at 100.83 and that is where a market order would be filled.
If you need your orders executed at specific prices, you must use limit orders.AustinNinjaTrader Customer Service
Comment
-
I don't understand how a trade at 12.03 can generate a prevoius 5 min bar close. Shouldn't it be the last trade before 11.59.59 ? What I'm trying to do here is to play around with entries/exits around prices I'm getting filled at with market orders. If close of the previous bar and open of the next one can differ can I just set my limit order at opening price of the next bar +/- offset ? This price is not known untill the first trade on the new bar so I'm not sure if it can be done
Comment
-
NinjaTrader is not time but event based, so for example in an illiquid or slow market you could definitely wait a bit for the tick to come in that would close the old bar and open the new one. You could run in realtime / Market Replay with CalculateOnBarClose to false and then submit your order in FirstTickOfBar context, then you would have the open price value and could work an order at this exact limit price.
Comment
-
Yes this is the reality of bar data in NinjaTrader. NinjaTrader only knows the OHLC of each bar. Whether that bar started at 11:59:00 or 12:03 doesn't matter. What matters is when the pricing data came through in the market and your logic should be unaffected by this. Since it will still get the low price of the bar correct and therefor the limit order will still be submitted correctly based on market action and would be true to market conditions. The only time you'll get a delayed date like that is if there is little volume. Which would only occur either overnight or illiquid markets Is this you’re seeing or are you seeing this all the time on popular futures contracts like the ES? If that's the case I may want to look into your data to make sure it matches my own data and is correct.
There only a few cases where this would cause issue, and in those cases you would simply need to test the strategy live on realtime data for this not to happen as then you have access to tick by tick live feed data and not just the bar data. You can test on Market replay or simulated live to the sim101 account. Which is what Bert mentioned.
Let me know if I can be of further assistance.BrettNinjaTrader Product Management
Comment
-
Please test this code on AUD/CAD (last 2 years, 5 min chart). Then try the same thing just with market orders
if (CrossAbove(EMA(8), EMA(21), 1))
{
ExitLongLimit(Close[0] + Of_S * TickSize, "", "");
EnterShortLimit(DefaultQuantity, Close[0] + Of_S * TickSize, "");
}
// Condition set 2
if (CrossBelow(EMA(8), EMA(21), 1))
{
ExitShortLimit(Close[0] + Of_L * TickSize, "", "");
EnterLongLimit(DefaultQuantity, Close[0] + Of_L * TickSize, "");
Comment
-
You would almost necessarily have different results with different entry orders. For one thing. market orders will always be filled, albeit at an, ab initio, indeterminate price, whereas limit orders may not get filled, even if touched, and certainly not if the market runs away.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
668 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
377 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
110 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
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
580 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment