Ajouter une étiquette 11 juil.
2025 à 07:25
//+------------------------------------------------------------------+
//| Fonction de vérification de position ouverte
|
//+------------------------------------------------------------------+
bool IsPositionOpen(string symbol, int type) {
int total = OrdersTotal();
for (int i = total - 1; i >= 0; i--) {
if (OrderSelect(i, SELECT_BY_POS)) {
if (OrderSymbol() == symbol &&
OrderType() == type) {
return true;
}
}
}
return false;
}
//+------------------------------------------------------------------+
//| Fonction d'ouverture de position
|
//+------------------------------------------------------------------+
void OpenPosition(string symbol, double lots, int
type) {
if (!IsPositionOpen(symbol, type)) {
int ticket;
if (type == OP_BUY) {
ticket = OrderSend(symbol, OP_BUY, lots,
Ask, 3, 0, 0, "", 0, 0, Green);
} else if (type == OP_SELL) {
ticket = OrderSend(symbol, OP_SELL, lots,
Bid, 3, 0, 0, "", 0, 0, Red);
}
if (ticket > 0) {
// Position ouverte avec succès
} else {
// Erreur lors de l'ouverture de la position
}
} else {
// Une position est déjà ouverte pour ce type
de trade
}
}