SL-M buy order—to buy abv a certain price
SL-M sell order —to sell below a certain price
Since you had a buy position and you used a SL-M sell order at 1240 the system took the current price which was below 1240 and executed your trade.
You should have used a limit sell order for target 1240.
You seem new to the market, please take some time to learn at least the basics about trading before diving into futures trading using margin.