if(ToTime(Time[0]) >= timeOpen && ToTime(Time[0])< timeClose &&
Position.MarketPosition == MarketPosition.Long /*&& Close[0]<=s1*/)
{
if(stopLossLong==null )
{
Print("Stop entered in onbarupdate");
stopLossLong = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, Position.AvgPrice - 6, "protectLong", "stop loss long");
}
if(stopLossLong.StopPrice==0)
{
//ChangeOrder(stopLossLong, 1, 0, Position.AvgPrice-6);
CancelOrder(stopLossLong);
stopLossLong = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, Position.AvgPrice - 6, "protectLong", "stop loss long");
}
if (longEntry != null)
{
CancelOrder(longEntry);
Print ("Long entry cancelled");
longEntry=null;
}
if (shortEntry != null)
{
//ChangeOrder(shortEntry, 1, r2, 0);
CancelOrder(shortEntry);
Print ("Short entry cancelled");
//shortEntry=null;
shortEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Limit , 1, ShortLimitPrice, 0, "s", "Short");
}
else
shortEntry = SubmitOrder(0, OrderAction.SellShort, OrderType.Limit , 1, ShortLimitPrice, 0, "s", "Short");
if(targetLong!=null)
{
//ChangeOrder(targetLong, 1, r2, 0);
CancelOrder(targetLong);
//targetLong=null;
targetLong = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, r2, 0, "TgtLong", "profit target long");
}
else
targetLong = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, r2, 0, "TgtLong", "profit target long");
I am running this on TopStepTrader using the Sim101 account as I want to see that the program acts right in real time before running it on Top StepTrader's Combine. The issue I am having is that when the bar changes, the targetLong and shortEntry get cancelled but does not get submitted until the next bar. I want the old order cancelled and the new order submitted on same bar in the OnBarUpdate(). Instead what I am seeing is the orders cancelled on one bar and then submitted on the nextbar. Should I be resubmitting the orders on the OnOrderUpdate event or another event and only cancel for OnBarUpdate?
In the backtest, everything works fine.
Thanks,
Cowpux
Comment