EA der bei Kreuzung von 2 EMAs - eine Long und eine Short Position eröffnet. Das darf er bei Kreuzung aber nur einmal machen, bis ich die Pos. geschlossen habe. EMAs müssen veränderbar werden können.

MQL5 Asesores Expertos

Tarea técnica

mql4
//+------------------------------------------------------------------+
//|                                                      MA_Cross.mq4|
//|                        Copyright 2024, MetaQuotes Software Corp. |
//|                                       https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
input int fastMA = 12; // Periode des schnellen MA
input int slowMA = 25; // Periode des langsamen MA
input double lotSize = 0.01; // Lotgröße

double fastMAValue, slowMAValue;
bool positionOpen = false;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   fastMAValue = iMA(NULL, 0, fastMA, 0, MODE_SMA, PRICE_CLOSE, 0);
   slowMAValue = iMA(NULL, 0, slowMA, 0, MODE_SMA, PRICE_CLOSE, 0);
   double fastMAValuePrev = iMA(NULL, 0, fastMA, 0, MODE_SMA, PRICE_CLOSE, 1);
   double slowMAValuePrev = iMA(NULL, 0, slowMA, 0, MODE_SMA, PRICE_CLOSE, 1);

   // Überprüfen, ob eine Position geöffnet ist
   if (PositionSelect(Symbol()))
     positionOpen = true;
   else
     positionOpen = false;

   // Long-Position eröffnen
   if (fastMAValue > slowMAValue && fastMAValuePrev <= slowMAValuePrev && !positionOpen)
     {
      OrderSend(Symbol(), OP_BUY, lotSize, Ask, 2, 0, 0, "MA Cross Long", 0, 0, clrGreen);
     }

   // Short-Position eröffnen
   if (fastMAValue < slowMAValue && fastMAValuePrev >= slowMAValuePrev && !positionOpen)
     {
      OrderSend(Symbol(), OP_SELL, lotSize, Bid, 2, 0, 0, "MA Cross Short", 0, 0, clrRed);
     }
  }
//+-------------------------------------------------

Han respondido

1
Desarrollador 1
Evaluación
(1095)
Proyectos
1451
45%
Arbitraje
49
73% / 12%
Caducado
36
2%
Libre
2
Desarrollador 2
Evaluación
(3)
Proyectos
6
33%
Arbitraje
0
Caducado
0
Trabaja
3
Desarrollador 3
Evaluación
(107)
Proyectos
166
33%
Arbitraje
12
25% / 33%
Caducado
0
Trabaja
4
Desarrollador 4
Evaluación
(354)
Proyectos
558
33%
Arbitraje
24
67% / 8%
Caducado
16
3%
Libre

Información sobre el proyecto

Presupuesto
30 - 35 USD
IVA (19%): 5.7 - 6.65 USD
Total: 36 - 41.65 USD
Para el ejecutor
27 - 31.5 USD
Plazo límite de ejecución
a 5 día(s)

Cliente

(1)
Encargos realizados2
Número de arbitrajes0