Modified Pending Order gets cancelled
Modified Pending Order gets cancelled
21 Sep 2022, 12:22
Hello, I have isolated the behaviour that is causing me some trouble in my own bot. When I place a pending order then modify it the pending order gets cancelled without me having called CanclePendingOrder.
I ran this on EURUSD and the 2 minute candle chart on the 5th of January 2018 with ICMarkets data, but it should cause the issue even on different markets and times.
[Robot(AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = "Hello world!")]
public string Message { get; set; }
DateTime tradeTime = new DateTime(2018, 1, 5, 7, 6, 0);
Ticks ticks;
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
// https://help.ctrader.com/ctrader-automate
ticks = MarketData.GetTicks(SymbolName);
}
protected override void OnTick()
{
var t = ticks.Last().Time;
if(t.Year == tradeTime.Year && t.Month == tradeTime.Month && t.Day == tradeTime.Day && t.Hour == tradeTime.Hour && t.Minute == tradeTime.Minute) {
if(PendingOrders.Count < 1) {
PlaceStopLimitOrder(TradeType.Buy, SymbolName, 167000, 1.2061, 0.0, "long", 6.0, 7.0);
}
}
}
protected override void OnBar()
{
var bar = Bars.Last(1);
if(bar.OpenTime.Hour == 7 && bar.OpenTime.Minute == 6)
{
foreach(var porder in PendingOrders)
{
ModifyPendingOrder(porder, 1.20595, 4.5, 7.0);
}
}
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
Replies
emileschneider7
21 Sep 2022, 16:39
RE:
PanagiotisCharalampous said:
Hi emileschneider7,
I could not reproduce this issue with the provided source code but such cancellations usually happen when the price is not valid e.g. lower that the ask price for buy orders and higher than the bid price for sell orders.
Best Regards,
Panagiotis
This is my issue though. The entry price is above Bid or Ask (for EURUSD data from ICMarkets) and the order gets successfully placed. I observed it in the debugger tick by tick and at some point it just gets cancelled for no apparent reason.
@emileschneider7
PanagiotisCharalampous
21 Sep 2022, 16:46
Hi emileschneider7,
I could only observe this when the prices were invalid. If you can print the prices in the log and provide it, it might be helpful.
Best Regards,
Panagiotis
Join us onTelegram andFacebook
@PanagiotisCharalampous
PanagiotisCharalampous
21 Sep 2022, 16:16
Hi emileschneider7,
I could not reproduce this issue with the provided source code but such cancellations usually happen when the price is not valid e.g. lower that the ask price for buy orders and higher than the bid price for sell orders.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous