cBot to convert stop loss to trailing stop loss
Created at 09 Mar 2023, 16:48
JO
cBot to convert stop loss to trailing stop loss
09 Mar 2023, 16:48
I've only just downloaded cTrader today, so forgive my ignorance with this question.
I'm hoping to create a bot that will check each `PendingOrder`, and update the stop-loss to a trailing-stop-loss if it is not already set.
The difficulty I'm having is when using `ModifyPendingOrder`, I thought I'd be able to pass in the existing order details and updating `hasTrailingStop` to true.
Here's a code snippet:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class BOT1Convertlimitordertotrailingstop : Robot
{
protected override void OnStart()
{
// Handle cBot start here
foreach (var order in PendingOrders)
{
if (order.HasTrailingStop == false) {
Print("Updating order: ", order);
ModifyPendingOrder(order, order.TargetPrice, null, null, null, order.VolumeInUnits, true);
}
}
}
}
}
I'm receiving an `InvalidRequest` error code when running the bot, but unsure what it's referring to.
Any help would be much appreciated.
Thanks for taking a look!
joe.a.guest
10 Mar 2023, 13:45 ( Updated at: 10 Mar 2023, 13:52 )
I've managed to make some progress on this, here's the code I've managed to write:
Seems to work well from my testing so far, hope this helps if anyone else is looking for something similar.
@joe.a.guest