Trailing stoploss
Trailing stoploss
29 Jul 2020, 22:26
Hi All,
Can someone see whats wrong in my code please?
if (TrailingSL)
{
if (pos.NetProfit / pos.VolumeInUnits / Symbol.PipSize <= Stoploss)
{
return;
}
double newstoploss = pos.TradeType == TradeType.Buy ? Bars.ClosePrices.LastValue - Stoploss * Symbol.PipSize : Bars.ClosePrices.LastValue + Stoploss * Symbol.PipSize;
newstoploss = Math.Round(newstoploss, Symbol.Digits);
TradeResult result = ModifyPosition(pos, newstoploss, pos.TakeProfit.Value);
if (result.IsSuccessful)
{
Print(string.Format("Position {0}: stoploss updated to {1}.", pos.Id, pos.StopLoss.Value));
else
{
Print(string.Format("Position {0}: stoploss could not be updated to {1}.", pos.Id, newstoploss));
}
}
}
It always give a fault in ctrader that the "pos" isn't accepted.
Thank you,
Replies
... Deleted by UFO ...
PanagiotisCharalampous
31 Jul 2020, 08:34
Hi Samm193,
You need to explain first what is the problem.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous