I'm having an issue with using the SetStopLoss code.
This is part of my code that sets the StopLoss.
- The line of code for setting up long positions. This line of code works very well.
private void postavi_limit_order(double cijenaaa, string pozicija)
{
if (pozicija == "Long")
{
EnterLongLimit(cijenaaa, "test1");
}
if (pozicija == "Short")
{
EnterShortLimit(cijenaaa, "test1");
}
}
- This line of code checks when the Limit order is filled and sets the StopLoss
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
if (order.OrderState.ToString() == "Filled")
{
Print("Start SL");
nalazim_se_u_tredu = true;
if (pozicija == "Long")
SetStopLoss(CalculationMode.Price, SL_cijena - 0.25);
if (pozicija == "Short")
SetStopLoss(CalculationMode.Price, SL_cijena + 0.25);
}
}
But when in a Short position, the SetStopLoss function doesn't set the StopLoss correctly. It sets it as "Action: Buy to cover - Type: Stop Market" instead of "Buy - Stop Market". When the current candle closes, the following problem occurs. Image attached for reference.
Please assist me in identifying where I am making a mistake and why?
Thanks

Comment