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

 
Aleksei Stepanenko:

A partir de dos puntos de una línea, se puede encontrar el precio de un tercer punto arbitrario de esa línea, también en el futuro (y viceversa).

Gracias. Lo probaré.

P.D. Lo único. No lo entiendo a simple vista. ¿Funcionará en el Asesor Experto, en MT4?

 
Hola, compañeros expertos. Necesito su ayuda para corregir el indicador. La esencia del indicador es la siguiente. Calcule el valor del aumento del precio en relación con la barra anterior. Para el cero se necesita una barra de estrella. Es decir, el precio de apertura es igual al de cierre. Al compilar no hay errores, pero al probar un error en la línea 80 20 caracteres. La línea de señal también está mal dibujada. Pero creo que esta es la razón del cálculo incorrecto del buffer principal. Por favor, ayúdenme a solucionarlo.
//+------------------------------------------------------------------+
//|                                                         MSBB.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#include <MovingAverages.mqh>

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  clrGreen
#property indicator_color2  clrRed
#property  indicator_width1  1
input int            InpMSBBPeriod=3;        // Period
input ENUM_MA_METHOD InpMSBBMethod=MODE_SMA;  // Method
//--- indicator buffers
double         ExtMSBBBuffer[];
double         ExtTempBuffer[];
double         ExtPriceBuffer[];
double         ExtSignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- indicator buffers mapping
   IndicatorDigits(Digits-2);
//--- drawing settings
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMSBBBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,ExtTempBuffer);
   SetIndexBuffer(2,ExtPriceBuffer);
   SetIndexDrawBegin(1,InpMSBBPeriod);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MSBB("+IntegerToString(InpMSBBPeriod)+")");
   SetIndexLabel(0,"MSBB");
   SetIndexLabel(1,"Signal");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int    i;//limit;
//------
   if(rates_total<=InpMSBBPeriod || InpMSBBPeriod<=2)
      return(0);
   /*//--- counting from 0 to rates_total
      ArraySetAsSeries(ExtMSBBBuffer,false);
      ArraySetAsSeries(ExtSignalBuffer,false);
      ArraySetAsSeries(open,false);
      ArraySetAsSeries(high,false);
      ArraySetAsSeries(low,false);
      ArraySetAsSeries(close,false);*/
//---
  // limit=rates_total-prev_calculated;
   //if(prev_calculated>0)
     // limit++;
//--- typical price and its moving average
   for(i=0; i<rates_total; i++)
     {
      ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2);
      ExtPriceBuffer[i] = NormalizeDouble((close[i+1]-open[i+1])/Point(),2);
      //ExtMSBBBuffer[i]=price_open+ExtTempBuffer[i];
      //Print("ExtPriceBuffer[i] = ", ExtPriceBuffer[i]);
      if(ExtTempBuffer[i]==0)
         ExtMSBBBuffer[i]=0.0;
      if(ExtPriceBuffer[i]>0 && ExtTempBuffer[i]>0)
        {
         double price_open = NormalizeDouble((open[i]-open[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-close[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i] = 0.0;
         if((price_open<0 && price_close<0)||(price_open>0 && price_close>0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]>0 && ExtTempBuffer[i]<0)
        {
         double price_open = NormalizeDouble((open[i]-close[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-open[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i] = 0.0;
         if((price_open>0 && price_close>0)||(price_open<0 && price_close<0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]<0 && ExtTempBuffer[i]<0)
        {
         double price_open = NormalizeDouble((open[i]-open[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-close[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i]=0.0;
         if((price_open<0 && price_close<0)||(price_open>0 && price_close>0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]<0 && ExtTempBuffer[i]>0)
        {
         double price_open = NormalizeDouble((open[i]-close[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-open[i+1])/Point(),2);
         if((price_open>0 && price_close<0)||(price_open<0 && price_close>0))
            ExtMSBBBuffer[i]=0.0;
         if((price_open>0 && price_close>0)||(price_open<0 && price_close<0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      //--- signal line counted in the 2-nd buffer
      //ExtSignalBuffer[i]=iMAOnArray(ExtMSBBBuffer,0,InpMSBBPeriod,0,InpMSBBMethod,0);
      SimpleMAOnBuffer(rates_total,prev_calculated,1,InpMSBBPeriod+2,ExtMSBBBuffer,ExtSignalBuffer);
      Print ("ExtSignalBuffer = ", ExtSignalBuffer[i]);
      //--- done
     }
   /* if(ExtPriceBuffer[i]>0||ExtPriceBuffer[i]<0)
     {
      ExtMSBBBuffer[i] = ExtPriceBuffer[i]+ExtTempBuffer[i];
      Print("ExtMSBBBuffer[i] = ", ExtMSBBBuffer[i]);
     }
   if(ExtPriceBuffer[i]==0)
     {
      ExtMSBBBuffer[i] = 0.0;
      Print("ExtMSBBBuffer[i] = ", ExtMSBBBuffer[i]);
     }
   }*/
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
 
¿Cómo puedo saber el número del agente local en el que se realiza la prueba única?
 

¡Buenas tardes!

¿Pueden ayudar con un EA?

Realiza operaciones sobre las señales del RSI a partir de los niveles 30 y 70 en la dirección adecuada, crea una cuadrícula.

Tengo una especie de stop loss % en él, pero de vez en cuando las órdenes se cuelgan y no se cierran hasta que las cierro manualmente o hasta que vendo el depósito.

Es decir, estas órdenes se abren cuando el precio ya se ha movido 5.000 pips y más, pero todavía están en rojo.

Tienes que encontrar el error. Si esto no es posible, debemos insertar un Stop Loss separado en pips en nuestro EA.

Intenté combinar 2 EAs en uno, pero no funcionó con mis habilidades.

Archivos adjuntos:
 

Hola. ¿Puedes darme una pista? Necesito obtener el número de puntos pasados en el último tick. Pero no puedo conseguirlo.

#property indicator_chart_window
#property indicator_buffers 1
double ExtMapBuffer[];
double dOldPriceEURUSD, dNewPriceEURUSD;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(5);
   SetIndexBuffer(0, ExtMapBuffer);
   SetIndexEmptyValue(0,0.0);        
   dOldPriceEURUSD=iClose("EURUSD",0,0);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   dNewPriceEURUSD=iClose("EURUSD",0,0);
   double delta=NormalizeDouble(dOldPriceEURUSD-dNewPriceEURUSD,5);
   ExtMapBuffer[0] = delta;
   Alert(delta);     
   dOldPriceEURUSD=dNewPriceEURUSD;
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Forallf:

Hola. ¿Puedes darme una pista? Necesito obtener el número de puntos pasados en el último tick. Pero no funciona.

Prueba esto.

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
double ExtMapBuffer[];
double dOldPriceEURUSD, dNewPriceEURUSD;
double delta;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(5);
   SetIndexBuffer(0, ExtMapBuffer);
   SetIndexEmptyValue(0, 0.0);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   dNewPriceEURUSD = NormalizeDouble(Close[0],Digits);
   delta = dOldPriceEURUSD - dNewPriceEURUSD;
   Comment(" delta = ", DoubleToStr(delta ,5));
   dOldPriceEURUSD = dNewPriceEURUSD;
   ExtMapBuffer[0] = delta;
 Alert(" delta = ", DoubleToStr(delta ,5));
   return(rates_total);
  }
//+------------------------------------------------------------------+
Domain Registration Services
  • www.registryrocket.com
Get a unique domain name plus our FREE value-added services to help you get the most from it. Call it a "dot-com name," a URL, or a domain. Whatever you call it, it's the cornerstone of your online presence, and we make getting one easy. Simply enter the name you want in the search field above, and we'll tell you instantly whether the name is...
 
Александр:

Inténtalo de esta manera.

Gracias.
 

Hola de nuevo.
Por favor, preste atención a la pregunta de un novato.
Necesito señalar errores en el código, porque en el probador, el Asesor Experto no abre órdenes...
El compilador no muestra ningún error o advertencia, el mismo diario no muestra errores...

extern double Lot=0.1;            
extern int Slippage = 3;
extern int TakeProfit = 30;
extern int StopLoss   = 30;
extern int MA_Smoth_S = 60;
extern int MA_Smoth_B = 12;
extern int MA_Simpl_S = 3;
extern int MA_Simpl_B = 1;
int start()
         {
          //___________________

          double SL, TP;
          int MA_Simpl_S_Cl,      //
              MA_Simpl_S_Op,      //
              MA_Simpl_B_Cl,      //
              MA_Simpl_B_Op;      //
         
          //________________

          //------------

          SL=NormalizeDouble(Bid-StopLoss*Point,Digits);      // 
          TP=NormalizeDouble(Bid+TakeProfit*Point,Digits);    //
          SL = StopLoss;                        
          TP = TakeProfit;
          if(_Digits==5 || _Digits==3)
            {
             SL = SL*10;
             TP = TP*10;
             return(0);
            }
            
          //_______________

          MA_Smoth_S = iMA(NULL,0,60,0,MODE_SMMA,PRICE_CLOSE,1);
          MA_Smoth_B = iMA(NULL,0,12,0,MODE_SMMA,PRICE_CLOSE,1);
          MA_Simpl_S = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_B = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_S_Cl = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_S_Op = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,2);
          MA_Simpl_B_Cl = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_B_Op = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,2);
          
          //______________________

          while(MA_Smoth_B > MA_Smoth_S)
               {
                if(MA_Simpl_B_Op < MA_Simpl_S_Op && MA_Simpl_B_Cl > MA_Simpl_S_Cl)
                  {
                   bool check = OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask, Digits),Slippage,SL,TP,"Buy",0,0,clrGreen);
                   return(0);
                  }
               }
               
          //_____________________

          while(MA_Smoth_S > MA_Smoth_B)
               {
                if(MA_Simpl_B_Op > MA_Simpl_S_Op && MA_Simpl_B_Cl < MA_Simpl_S_Cl)
                  {
                   check = OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Ask, Digits),Slippage,SL,TP,"Sell",0,0,clrRed);
                   return(0);
                  }   
               }     
          return(0);
         } 
 

¡Buenos días a todos!

Estoy intentando pasar de mql4 a mql5.

Pregunta: ¿Por qué mql5 calcula y muestra una expresión desconocida para mí como 2,99999999 - (menos) 05 en lugar de la diferencia entre el precio actual y el valor de la variable Hay, que debería ser <1 (como en mql4)?

¿Cómo puedo hacer que mql5 calcule correctamente la diferencia entre estos valores? Normalizo todos los valores utilizando NormalizeDouble(), pero los valores anteriores

los valores se muestran sin cambios. Esto me resulta extraño ya que ambos valores son de doble tipo

Gracias a todos por su ayuda.

#include <Trade\Trade.mqh>                                        
int tm, s1 ;                                    
double P=SymbolInfoDouble(Symbol(),SYMBOL_BID),S=P+0.0030,T=P-0.0010,Lou,Hay,DL=0.0030; 
CTrade            m_Trade;                 //структура для выполнения торговых операций
//=============================================================================================================
void OnTick()
  {
Print("===============",SymbolInfoDouble(Symbol(),SYMBOL_BID) - Hay,"===Hay====",Hay,"===SymbolInfoDouble()====",SymbolInfoDouble(Symbol(),SYMBOL_BID)); 

m_Trade.Sell(0.1,Symbol(),P,S,T);
Hay=SymbolInfoDouble(Symbol(),SYMBOL_BID);

   }


 
MrBrooklin:

Hola Iván, aquí nadie regaña a los novatos, al contrario, intentan ayudar. Yo mismo soy un principiante. Ahora, con respecto a su pregunta. Se abren varias posiciones porque se realizó la comprobación para abrir una posición, pero se olvidó detenerla. El operador return devuelve el control al programa que llama (tomado de la Referencia MQL5).

Debemos añadir el retorno al código del Asesor Experto (resaltado en amarillo):

Además, para evitar que el compilador genere advertencias, hay que añadir una condición más en las condiciones de apertura de las posiciones de compra y venta para comprobar OrderSend(mrequest,mresult). Esta condición está definida por el operador if y debería tener el siguiente aspecto:

Hay que tener en cuenta una cosa más. A veces, al pasar de un día de negociación a otro, a las 23:59:59, se cierra una posición abierta y luego, a las 00:00:00, se abre una nueva posición. Se trata de los denominados rollover close y rollover open, que dependen del operador de divisas concreto y de sus condiciones comerciales. Busca en el foro, tengo información al respecto en alguna parte.

Sinceramente, Vladimir.


Hola.

Muchas gracias por su respuesta. Pero no entiendo por qué necesito el operador de retorno? Hay dos condiciones en este código y la comprobación debe detenerse cuando se cumpla una de ellas.

//--- есть ли открытые позиции?
   bool Buy_opened=false;  // переменные, в которых будет храниться информация 
   bool Sell_opened=false; // о наличии соответствующих открытых позиций

   if(PositionSelect(_Symbol)==true) // есть открытая позиция
     {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)  // если истина, выполняем условие 1
        {
         Buy_opened=true;  //это длинная позиция
        }
      else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)  // иначе выполняем условие 2
        {
         Sell_opened=true; // это короткая позиция
        }
     }
¿O no?
Razón de la queja: