Is this a bug of StopLoss setting when using PlaceStopOrderAsync()
23 Jun 2016, 10:46
I use the following statement to place stop order with stoploss:
PlaceStopOrderAsync(TradeType.Buy, Symbol, volume, openPrice, Lable, 5.5, takeProfitPips, Server.Time.AddHours(OrderExpireHour), Comment);
You can see I hardcoded 5.5 pips stoploss in the code. But when I run backtest, the stoploss is never 5.5pips, sometime is 5.0, sometimes is 6.0. Like the snapshot below.

Is this a bug? Or I did something wrong when I call PlaceStopOrderAsync()?
Thanks!

whis.gg
23 Jun 2016, 12:47
It's not a bug, stop loss and take profit haven't supported decimal places, so it always rounds to whole number. However, there is a workaround - see the sample code below.
using System; using cAlgo.API; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Sample : Robot { [Parameter(DefaultValue = 5.5)] public double StopLossPips { get; set; } [Parameter(DefaultValue = 8.1)] public double TakeProfitPips { get; set; } protected override void OnStart() { ExecuteMarketOrderAsync(TradeType.Sell, Symbol, Symbol.VolumeMin, "label"); Positions.Opened += OnPositionsOpened; } private void OnPositionsOpened(PositionOpenedEventArgs obj) { var position = obj.Position; if (position.Label == "label") { int direction = position.TradeType == TradeType.Buy ? 1 : -1; double stopLoss = position.EntryPrice - StopLossPips * Symbol.PipSize * direction; double takeProfit = position.EntryPrice + TakeProfitPips * Symbol.PipSize * direction; ModifyPosition(position, stopLoss, takeProfit); } } } }@whis.gg