I am trying to send stoplimit order on open tick of a new bar. It works 90% of the time. But sometimes NT tells me stoplimit buy orders cannot be created below last traded price.
So it seems though the code condition is Close[0]<entryPrice, when the order gets to the broker, the new most recent close moved above entryPrice, so the order fails. Is there a way to check for this error without it giving a pop up and interrupt the script? Thanks
int previousBar=-1;
protected override void OnBarUpdate() //Calculate = Calculate.OnEachTick;
{
if (CurrentBar>previousBar)
{
if (Close[0]<entryPrice)
{
Order entryOrder = xAccount.CreateOrder(
Instrument,
OrderAction.Buy,
OrderType.StopLimit,
OrderEntry.Manual,
TimeInForce.Day,
1,
entryPrice,
entryPrice,
"",
"xEntryBuy" + CurrentBar,
DateTime.MaxValue,
null);
}
}
previoiusBar=CurrentBar;
}
Also similiarly,
I want to cancel existing not-filled entry orders on first tick of new bar, and send in new orders
It works most of the time.
But once a whlie NT will pop up message: cannot cancel filled order. So I guess that order got filled between the OrderStatus check and the Account.Cancel line. Would be great if there is a way to handle this without having a pop up window.
protected override void OnBarUpdate() //Calculate = Calculate.OnEachTick;
{
for (int i=entries.count-1;i>=0;i--)
{
if (entries[i].OrderStatus==OrderStatus.Accepted)
{
xAccount.Cancel(new[] {entries[i]);
}
}
}
--edit:
I think maybe to make the question more clear,
is there a way to send in a buy order that is stoplimit by default, but if the exchange rejects it because price already moved above the desired entry price then automatically fall back to a limit buy order at the same entry price, all without having NT give a pop up error window and potentially stopping the script? - Thank you!
Comment