I developed a custom strategy and have some errors in it.
Error on calling 'EventHandlerBarsUpdate' method: More than 100 subsequent user events
I think this error is displayed because of OnBarUpdate event, but I can't find the solution.
protected override void OnBarUpdate()
{
if (currentState == ButtonState.ON)
{
lastPrice = Close[0];
double newBuyStopPrice = 0;
double newSellStopPrice = 0;
newBuyStopPrice = Close[0] + Distance * TickSize;
newSellStopPrice = Close[0] - Distance * TickSize;
// Check if the order is still working and not filled
if (buyStopOrder != null && sellStopOrder != null && buyStopOrder.OrderState == OrderState.Accepted && buyStopOrder.OrderState == OrderState.Accepted)
{
ChangeOrder(buyStopOrder, buyStopOrder.Quantity, buyStopOrder.LimitPrice, newBuyStopPrice);
ChangeOrder(sellStopOrder, sellStopOrder.Quantity, sellStopOrder.LimitPrice, newSellStopPrice);
}
}
}
When price move, orders will also move keeping the input distance.
It works well in a short time, but the error message is displayed.
Calculation event is OnPriceChange.
Please help me in this problem.
Regards.

Comment