Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
exits based on strategy price vs actual fill price
Collapse
X
-
exits based on strategy price vs actual fill price
Is there a way with the unmanaged approach to code and calculate the exits so that they're not based on the average filled price "Order.AverageFillPrice", but instead on the price the strategy would have wanted when the entry signal started?Tags: None
-
Hello giulyko00,
You could save the current Close[0] (or GetCurrentAsk()/GetCurrentBid()) to a variable in OnBarUpdate() and use this as the base for the calculation when submitting the exits.
private double marketPriceAtEntryCondition;
In OnBarUpdate():
if (/* condition to enter here */)
{
marketPriceAtEntryCondition = Close[0]; // you will want logic to ensure this condition only evaluates once until the trade is closed so this price is not continuously updated
SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "longEntry");
}
In OnExecutionUpdate():
if (exection.Name == "longEntry")
{
SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 1, 0, Math.Min(GetCurrentBid() - TickSize, marketPriceAtEntryCondition - 10 * TickSize), "longEntry", "longExit");
}Chelsea B.NinjaTrader Customer Service
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
81 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
42 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
64 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
66 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
54 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment