Cualquier pregunta de los recién llegados sobre MQL4 y MQL5, ayuda y discusión sobre algoritmos y códigos - página 1658

 
artem artem el MACD. Y tiene que ser confirmado 4 veces y la orden debe abrirse en la 4ª vela. Adjunto un archivo para que quede visualmente claro.


SanAlex, ¿puedes hacer un zoom para que se vean claramente las barras del MACD y la rapidez con la que se cruzan las lentas? Apenas puedo verlo.

Prueba con

#define  MagicNumber  122122
extern string s1             = "Trading options";
extern double Lot            = 0.01;    // размер лота 0 - авт.расчет
extern double StopLoss       = 40;     // стоплосс
extern double TakeProfit     = 10;     // тейкпрофит
extern double TrailStop      = 21;     // уровень без убытка
extern int    Trailing       = 0;      // трейлинг стоп 1 вкл. 0 выкл.
extern int    Breakeven      = 0;      // перенос стоп лосса в без убыток
extern string s2             = "Day & Hour";
extern int    HrStart        = 0;      // время начала торговли
extern int    HrEnd          = 23;     // время окончания торговли
extern int    Monday         = 1;      // Понедельник 1 вкд. 0 выкл.
extern int    Tuesday        = 1;      // Вторник
extern int    Wednesday      = 1;      // Среда
extern int    Thursday       = 1;      // Четверг
extern int    Friday         = 1;      // Пятница
//+------------------------------------------------------------------+
// параметры индикаторов
double MovingPeriodLw        = 5;      
double MovingPeriodS1        = 75;
double MovingPeriodS2        = 85;
double StopLevel;
double TrailStep             = 3;      // шаг трейлинг стопа
bool OrderBuy = true, OrderSell = true, Order = false, Init = true;
int timeprev = 0, Slip = 3.0, start, cnt;

//+------------------------------------------------------------------+
//| Init function                                                    |
//+------------------------------------------------------------------+
void OnInit()
{
   if (Digits == 3 || Digits == 5) { // Пересчет для 5-ти знаков                                                    
      TakeProfit *= 10;
      TrailStop *= 10;
      TrailStep *= 10;
      StopLoss *=10;
      Slip *=10;
   } 
   return; 
}
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
{
   StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); 
   if(CheckForOpen()!=start)
     {start=CheckForOpen(); cnt=0;}
   else
     {cnt+=1;}
   // Определение направления пересечения мувингов
//   if (Init) InitMetod(); 
   
   // Трейлинг стоп открытых позиций
   if (Trailing != 0 ) RealTrailOrder(TrailStop, TrailStep, StopLevel, MagicNumber);
   
   // Ожидание нового бара на графике
   if(timeprev == Time[0]) return;
   timeprev = Time[0];

   if(cnt==3)
     {
      // Открытие ордера по методу Пуриа
      if(CheckForOpen()==0 && OrderBuy==true) // Если сигнал для покупок 
        {
         if(OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slip,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MagicNumber,0,Blue))
           {OrderBuy=false; Print("BUY OK");}
        } 
      if(CheckForOpen()==1 && OrderSell==true) // Если сигнал для продаж 
        {
         if(OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slip,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MagicNumber,0,Red))
           {OrderSell=false; Print("SELL OK");}
        }
     }   
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
int CheckForOpen() // Открытие ордера по методу Пуриа
  {
   double malw,mas1,mas2,macd;
   int    res=-1, buy=0, sell=0;
   // Считывание параметров индикаторов 3 свечи (4ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,3);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,3);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,3);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,3);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 2 свечи (3ей)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,2);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,2);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,2);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,2);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 1 свечи (2ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,1);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,1);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,1);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,1);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 0 свечи (1ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,0);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,0);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,0);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,0);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   
   if(buy <4)  OrderBuy=true; 
   if(sell<4)  OrderSell=true;
   if(buy ==4) { res=0; OrderSell=true;} 
   if(sell==4) { res=1; OrderBuy =true;}
   return(res);
  }
 
MakaeFX, ahora por alguna razón no se abre a partir de la 4ª vela de confirmación, sino en realidad a partir de la 7ª. Se adjunta captura de pantalla del probador
Archivos adjuntos:
 
artem artem #:

SanAlex, ¿puedes hacer un zoom para que se vean claramente las barras del MACD y que la rápida se cruce con la lenta? Apenas puedo verlo.

pero lo que añadí allí - el propósito del Asesor Experto es diferente. El objetivo es obtener el beneficio total de todos los pares abiertos y cerrar todos los Asesores Expertos.

Captura de pantalla 2021-10-09 192219

Captura de pantalla 2021-10-09 192331

Archivos adjuntos:
 
artem artem #:
MakaeFX, ahora por alguna razón no se abre a partir de la 4ª vela de confirmación, sino en realidad a partir de la 7ª. Adjunto una captura de pantalla del probador
Sube tu archivo de EA, voy a mirar en el probador
 
SanAlex, así que la cuestión es que lo que quiero implementar será aún mejor + Llevo unos días haciéndolo, y ya me interesa fundamentalmente cómo debería ser el código correcto. Y será muy útil para el futuro, y el Asesor Experto será realmente bueno. Pero tu versión también es buena, no puedo decir nada en contra.
 
MakarFX, adjunta un EA
Archivos adjuntos:
 
artem artem #:
MakarFX, EA adjunto
¿Qué versión de MetaEditor?
 
Exactamente MetaEditor - versión 5.00 build 2382
 
artem artem #:
exactamente MetaEditor - versión 5.00 build 2382

No está claro cómo has compilado el archivo que has publicado...

Aquí, intenta añadir lo que necesites

Archivos adjuntos:
artem.mq4  13 kb
 

MakarFX, ¿está bien si pruebo en todos los ticks - de 01.08.21 a 03.09.21 - entonces 46 órdenes

y si hago la prueba sólo por los precios de apertura dentro del mismo período - 29 órdenes ?

+ varias órdenes que explícitamente se perdieron su precio de apertura si se probaron por ticks. Adjunto una captura de pantalla, que muestra

Archivos adjuntos:
Razón de la queja: