Ajouter une étiquette 9 juil.
2025 à 07:38
//+------------------------------------------------------------------+
//| Expert Advisor |
//+------------------------------------------------------------------+
#property strict
//+------------------------------------------------------------------+
//| Inputs |
//+------------------------------------------------------------------+
input double LotSize = 0.1; // Taille de la position
input int StopLoss = 20; // Stop loss en points
input int TakeProfit = 20; // Take profit en points
//+------------------------------------------------------------------+
//| OnInit function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Détermination de la couleur de
l'avant-dernière bougie
color lastCandleColor = GetCandleColor(1);
color currentCandleColor = GetCandleColor(0);
// Vérification des conditions pour acheter
if((lastCandleColor == Red || lastCandleColor ==
Maroon) && (currentCandleColor == Green ||
currentCandleColor == Lime))
{
// Acheter
int ticket = OrderSend(Symbol(), OP_BUY,
LotSize, Ask, 3, Bid-StopLoss*Point,
Bid+TakeProfit*Point, "Achat", 0, 0, Green);
if(ticket > 0)
{
Print("Position d'achat ouverte avec succès");
}
}
}
//+------------------------------------------------------------------+
//| Fonction pour déterminer la couleur d'une
bougie |
//+------------------------------------------------------------------+
color GetCandleColor(int shift)
{
double l_icci_0 = iCCI(NULL, 0, 14,
PRICE_TYPICAL, shift);
double l_icci_8 = iCCI(NULL, 0, 50,
PRICE_TYPICAL, shift);
if(l_icci_0 >= 0.0 && l_icci_8 >= 0.0)
{
return Green;
}
else if(l_icci_8 >= 0.0 && l_icci_0 < 0.0)
{
return Lime;
}
else if(l_icci_0 < 0.0 && l_icci_8 < 0.0)
{
return Red;
}
else if(l_icci_8 < 0.0 && l_icci_0 > 0.0)
{
return Maroon;
}
return CLR_NONE;
}