Cancel Pending Orders by pip distance from current price?
Cancel Pending Orders by pip distance from current price?
26 Jul 2017, 21:54
How to adjust this to cancel pending stop orders when they reach a certain pip distance from the current price on tick?
protected override void OnTick()
{
foreach (var order in PendingOrders)
{
if (order.Label == "myLabel")
{
CancelPendingOrder(order);
}
}
}
Replies
theonlinemick
27 Jul 2017, 11:24
Great, thank you, works perfectly.
added the parameter and label for anyone who wants to save time.
[Parameter("Cancel Pending Orders", DefaultValue = 30, MinValue = 0)]
public int MaxPipDistance { get; set; }
protected override void OnTick()
{
foreach (var order in PendingOrders)
{
var pipDistance = Math.Abs((order.TargetPrice - Symbol.Ask) / Symbol.PipValue);
if (pipDistance > MaxPipDistance)
{
CancelPendingOrder(order);
Print("Order Has Reached Max Distance, Order Cancelled");
}
}
}
@theonlinemick
kartheek99923
14 Jun 2024, 04:28
( Updated at: 14 Jun 2024, 05:11 )
RE: Cancel Pending Orders by pip distance from current price?
theonlinemick said:
Great, thank you, works perfectly.
added the parameter and label for anyone who wants to save time.
[Parameter("Cancel Pending Orders", DefaultValue = 30, MinValue = 0)]
public int MaxPipDistance { get; set; }
protected override void OnTick()
{
foreach (var order in PendingOrders)
{
var pipDistance = Math.Abs((order.TargetPrice - Symbol.Ask) / Symbol.PipValue);
if (pipDistance > MaxPipDistance)
{
CancelPendingOrder(order);
Print("Order Has Reached Max Distance, Order Cancelled");
}
}
}
This code is showing errors while building. Can you help me with the code?
@kartheek99923
Spotware
27 Jul 2017, 10:28
Dear theonlinemick,
Thanks for your post. You can try something like the following
You can ajdust the price you will consider (Symbol.Ask or Symbol.Bid) based on your order's direction.
Best Regards,
cTrader Team
@Spotware