public static void fixOrdersPosition(bool force = true) { int oOrders = getOpenOrderQty(); if (operation != "surf" && roeAutomatic && (Math.Abs(oOrders) < Math.Abs(positionContracts))) { positionContracts = getPosition(); // FIX CARLOS MORATO log("Get Position " + positionContracts); int qntContacts = (Math.Abs(positionContracts) - Math.Abs(getOpenOrderQty())); if (positionContracts > 0) { string side = "Sell"; double priceContacts = Math.Abs(getPositionPrice()); double actualPrice = Math.Abs(getPriceActual(side)); double priceContactsProfit = Math.Abs(Math.Floor(priceContacts + (priceContacts * (profit + fee) / 100))); double price = priceContacts + stepValue; if (Math.Abs(oOrders) > 0 && Math.Abs(oOrders) < Math.Abs(positionContracts)) { string orderid = getOpenOrderId(); if (orderid == "") { return; } String json = bitMEXApi.EditOrder(orderid, price, Math.Abs(positionContracts)); log(json); } else { String json = bitMEXApi.PostOrderPostOnly(pair, side, price, Math.Abs(qntContacts), force, marketTaker, "Normal/Scalp Sell Exit Order", true); JContainer config2 = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); log(json); } } if (positionContracts < 0) { string side = "Buy"; double priceContacts = Math.Abs(getPositionPrice()); double actualPrice = Math.Abs(getPriceActual(side)); double priceContactsProfit = Math.Abs(Math.Floor(priceContacts - (priceContacts * (profit + fee) / 100))); double price = priceContacts - stepValue; if (Math.Abs(oOrders) > 0 && Math.Abs(oOrders) < Math.Abs(positionContracts)) { string orderid = getOpenOrderId(); if (orderid == "") { return; } String json = bitMEXApi.EditOrder(orderid, price, Math.Abs(positionContracts)); log(json); } else { String json = bitMEXApi.PostOrderPostOnly(pair, side, price, Math.Abs(qntContacts), force, marketTaker, "Normal/Scalp Buy Exit Order", true); JContainer config2 = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); log(json); } } } }