Ajouter une étiquette 9 juil.
2025 à 04:30
//+------------------------------------------------------------------+
//| Expert Advisor |
//+------------------------------------------------------------------+
#property strict
//+------------------------------------------------------------------+
//| Inputs |
//+------------------------------------------------------------------+
input int FastMAPeriod = 10; // Période de la
moyenne mobile rapide
input int SlowMAPeriod = 30; // Période de la
moyenne mobile lente
input double LotSize = 0.1; // Taille de la position
//+------------------------------------------------------------------+
//| OnInit function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Calcul des moyennes mobiles
double fastMA = iMA(Symbol(),
PERIOD_CURRENT, FastMAPeriod, 0,
MODE_SMA, PRICE_CLOSE, 0);
double slowMA = iMA(Symbol(),
PERIOD_CURRENT, SlowMAPeriod, 0,
MODE_SMA, PRICE_CLOSE, 0);
// Vérification des conditions pour acheter
if(fastMA > slowMA && fastMA[1] <=
slowMA[1])
{
// Acheter
int ticket = OrderSend(Symbol(), OP_BUY,
LotSize, Ask, 3, Bid-20*Point, Bid+20*Point,
"Achat", 0, 0, Green);
if(ticket > 0)
{
Print("Position d'achat ouverte avec succès");
}
}
// Vérification des conditions pour vendre
if(fastMA < slowMA && fastMA[1] >=
slowMA[1])
{
// Vendre
int ticket = OrderSend(Symbol(), OP_SELL,
LotSize, Bid, 3, Ask+20*Point, Ask-20*Point,
"Vente", 0, 0, Red);
if(ticket > 0)
{
Print("Position de vente ouverte avec
succès");
}
}
}