What I am trying to solve is Why is there a 10 minute delay from code calling enterlongposition, to the actual order submission/fill?
Below is the log for yesterday.
4/11/2025 9:27:00 AM: SHORT ENTRY - Entry Price: 18330
4/11/2025 9:37:00 AM: Order update - Name: Short1, Type: Market, State: Submitted, LimitPrice: 0, StopPrice: 0
4/11/2025 9:37:00 AM: Order update - Name: Short2, Type: Market, State: Submitted, LimitPrice: 0, StopPrice: 0
4/11/2025 9:37:00 AM: Order update - Name: Short3, Type: Market, State: Submitted, LimitPrice: 0, StopPrice: 0
4/11/2025 9:37:00 AM: Order update - Name: Short1, Type: Market, State: Accepted, LimitPrice: 0, StopPrice: 0
4/11/2025 9:37:00 AM: Order update - Name: Short1, Type: Market, State: Working, LimitPrice: 0, StopPrice: 0
4/11/2025 9:37:00 AM: Order update - Name: Short1, Type: Market, State: Filled, LimitPrice: 0, StopPrice: 0
4/11/2025 9:37:00 AM: Trade executed - Short1 at price 18326.5
As you can see, the code detects a short entry at 09:27AM, but the order is only submitted/executed at 09:37AM. Although the print at 09:37 says it filled at 18,326.5, the actual fill was 18,446 as the price has moved past my entry during the 10 minute delay.
Below is the part of the code that calls the initial print 4/11/2025 9:27:00 AM: SHORT ENTRY - Entry Price: 18330
if (!hasPositionInCurrentTrend &&
Position.MarketPosition == MarketPosition.Flat &&
hasCrossedThisSession)
{
waitCounter++;
if (waitCounter >= WaitBars)
{
if (currentTrend == "LONG")
{
// Store entry price BEFORE entering position
entryPrice = Close[0];
Print(string.Format("{0}: LONG ENTRY - Entry Price: {1}", Time[0], entryPrice));
EnterLongPosition();
}
else
{
// Store entry price BEFORE entering position
entryPrice = Close[0];
Print(string.Format("{0}: SHORT ENTRY - Entry Price: {1}", Time[0], entryPrice));
EnterShortPosition();
}
hasPositionInCurrentTrend = true;
waitCounter = 0;
}
}
For context:
Calculate = Calculate.OnBarClose;
protected override void OnBarUpdate()
DateTime currentTime = Time[0];
DateTime currentDate = currentTime.Date;
// Check if we're within regular trading hours or exactly at the StartTime (06:30)
bool isRth = IsWithinTradingHours();
bool isOpeningTime = currentTime.TimeOfDay == StartTime.TimeOfDay;
Thanks in advance to anyone that could offer some help.
MK

Comment