Librerías: Expert - página 3

 
Un ejemplo de otra aplicación de la biblioteca

Foro sobre negociación, sistemas automatizados de negociación y comprobación de estrategias de negociación

ParameterGetRange()

fxsaber, 2018.11.16 09:17

#include <fxsaber\Expert.mqh> // https://www.mql5.com/es/code/19003

#define  TOSTRING(A) (" " + #A + " = " + (string)(A))

// Recoge datos sobre la gama de parámetros de entrada para la optimización
string OptimizationData( void )
{
  string Str = NULL;
  MqlParam Params[];
  string Names[];
  
  if (EXPERT::Parameters(0, Params, Names))
  {
    const int Size = ArraySize(Names);
    bool Enable;
    long Value, Start, Step, Stop;
    long Total = 1;
    
    Str = Params[0].string_value;
    
    for (int i = 0; i < Size; i++)
      if (ParameterGetRange(Names[i], Enable, Value, Start, Step, Stop))
      {
        const long Interval = Stop - Start + 1;
        const long Amount =  Enable ? Interval / Step + ((bool)(Interval % Step) ? 1 : 0) : 1;
        
        Str += "\n" + Names[i] + " = " + (string)Value + (Enable ? TOSTRING(Start) + TOSTRING(Step) + TOSTRING(Stop) + TOSTRING(Amount) : NULL);
        
        Total *= Amount;
      }
      
    Str += "\n" + TOSTRING(Total);
  }
  
  return(Str);
}

input int Range1 = 5;
input int Range2 = 5;
input int Range3 = 5;

void OnTesterInit()
{
  ParameterSetRange("Range1", true, 5, 1, 2, 3);
  
  Print(__FUNCTION__ + "\n" + OptimizationData());
}

void OnTesterDeinit()
{
  Print(__FUNCTION__ + "\n" + OptimizationData());
  
  ChartClose();
}

int OnInit()
{
  return(INIT_FAILED);
}


OnTesterInit
Experts\fxsaber\Test3.ex5
Range1 = 5 Start = 5 Step = 1 Stop = 50 Amount = 46
Range2 = 5 Start = 23 Step = 1 Stop = 78 Amount = 56
Range3 = 5 Start = 26 Step = 5 Stop = 83 Amount = 12
 Total = 30912

OnTesterDeinit
Experts\fxsaber\Test3.ex5
Range1 = 5 Start = 1 Step = 2 Stop = 3 Amount = 2
Range2 = 5 Start = 23 Step = 1 Stop = 78 Amount = 56
Range3 = 5 Start = 26 Step = 5 Stop = 83 Amount = 12
 Total = 1344
 
Error corregido.
 
Error corregido. Última versión.
 

¿Cómo se puede ejecutar un Asesor Experto en el formato .ex4 conectándolo en un Asesor Experto con un nombre diferente, y es necesario que los parámetros de entrada se mostraron, es decir, que era posible trabajar plenamente con él.

Tenemos un Asesor Experto compilado con el nombre "Trade.ex4".

Creamos un nuevo Asesor Experto con el nombre "Hand.ex4".

Cómo combinarlos para que cuando se lance "Hand.ex4", "Trade.ex4" sea totalmente funcional y "Trade.ex4" esté incrustado en "Hand.ex4".

Es decir, sólo tenemos el archivo Hand.ex4 en la máquina, pero usamos Trade.ex4 en el trabajo

Gracias.

 
Vitaly Muzichenko:

¿Cómo se puede ejecutar un Asesor Experto en formato .ex4...

La biblioteca en su forma actual sólo funciona con EX5.

 
Sergey Eremin:

Yo mismo, como parte de cierto proyecto, lo resolví así (con la etiqueta "nombre" a secas):

Gracias, ¡funciona así!

Sólo que añadí chartId al nombre de la plantilla guardada, para que EAs idénticos en gráficos diferentes no se peleen por el mismo archivo.


@fxsaber, hay "#ifndef __MQL5__" en el código, ¿por qué no tomar multiplataforma a su conclusión lógica?

Para que funcione Is, añadimos al principio del código:

#property strict

#ifdef __MQL4__
        class SubstringParser
        {
           private:
              string m_text;
              string m_subStart;
              string m_subEnd;
           
           public:
              SubstringParser(const string text, const string subStart, const string subEnd)
              {
                 m_text = text;
                 m_subStart = subStart;
                 m_subEnd = subEnd;
              }
              
              string Get()
              {
                 int startPhraseLengt = StringLen(m_subStart);
                 int startPos = StringFind(m_text, m_subStart) + startPhraseLengt;
                 int endPos = StringFind(m_text, m_subEnd, startPos);
                         
                 if(startPos >= startPhraseLengt && endPos > startPos)
                 {
                    return StringSubstr(m_text, startPos, endPos - startPos);      
                 }
                 else
                 {
                    return "";
                 }
              }
        };

   string GetChartEAName(const long chartId)
   {
      if(!SaveTemplate(chartId))
      {
         return "";
      }
      
      string result = "";
      
      int handle = FileOpen("ea_name_checking_" + (string)chartId + ".tpl",FILE_TXT|FILE_READ);
      if(handle == INVALID_HANDLE)
      {
         Print
         (
            "Error in ", __FILE__,", line ", __LINE__,
            ": can't open template file 'ea_name_checking_" + (string)chartId + ".tpl', error code = ", GetLastError()
         );
      }
      else
      {
         string text = "";
         
         while(!FileIsEnding(handle)) 
         { 
            text = text + FileReadString(handle, (uint)FileSize(handle)) +"\r\n";
         }
         
         SubstringParser eaSectionTextParser(text, "<expert>", "</expert>");            
         string eaSectionText = eaSectionTextParser.Get();
         
         if(StringTrimLeft(StringTrimRight(eaSectionText)) != "")
         {
            SubstringParser eaNameParser(eaSectionText, "name=","\r\n");
            string eaName = StringTrimLeft(StringTrimRight(eaNameParser.Get()));
            
            if(eaName != "")               
            {
               result = eaName;
            }
         }            
      }
      
      FileClose(handle);
      FileDelete("ea_name_checking_" + (string)chartId + ".tpl");
      
      return result;
   }
   
   bool SaveTemplate(const long chartId)
   {
      ResetLastError();
      
      if(!ChartSaveTemplate(chartId, "\\Files\\ea_name_checking_" + (string)chartId + ".tpl"))
      {            
         Print
         (
            "Error in ", __FILE__,", line ", __LINE__,
            ": can't save template to the file 'ea_name_checking_" + (string)chartId + ".tpl', error code = ", GetLastError()
         );
         
         return false;
      }
      
      return true;
   }      
 #endif

Y corregir la función en sí:

  static bool Is( const long Chart_ID = 0 )
  {
                #ifdef __MQL4__
                        string chartEAName = GetChartEAName(Chart_ID);
                #endif 
                
                #ifdef __MQL5__     
                        string chartEAName = ChartGetString(Chart_ID, CHART_EXPERT_NAME);
                #endif
                return(chartEAName != NULL);
  }


¿Alguna otra dificultad?

 
Andrey Khatimlianskii:

¿Alguna otra dificultad?

Un gráfico con un solo indicador funcionando.


ZY Así es como debería funcionar

SubstringParser eaSectionTextParser(text, "\r\n\r\n<expert>", "</expert>");
 

Toda la funcionalidad de la librería funciona ahora en MT4.

La biblioteca se ha convertido en multiplataforma.

 
Toda la funcionalidad de la librería funciona ahora en MT4.
La biblioteca se ha convertido en multiplataforma.


MT4-ejemplo:

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Библиотеки: Experto

fxsaber, 2019.04.09 13:19

#include <fxsaber\Expert.mqh> // https://www.mql5.com/ru/code/19003

void OnStart()
{
  MqlParam Params[2];

  // Путь к советнику
  Params[0].string_value = "Moving Average";
  
  // Первый входной параметр советника
  Params[1].type = TYPE_DOUBLE;
  Params[1].double_value = 0.5;  

  Print(EXPERT::Run(ChartOpen(_Symbol, _Period), Params));
}
 
Vitaly Muzichenko:

¿Cuál es la mejor manera de ejecutar un EA en .ex4...

#include <fxsaber\Expert.mqh> // https://www.mql5.com/es/code/19003

void OnStart()
{
  MqlParam Params[2];

  // Camino a Consejero
  Params[0].string_value = "Moving Average";
  
  // El primer parámetro de entrada del Asesor Experto
  Params[1].type = TYPE_DOUBLE;
  Params[1].double_value = 0.5;  

  Print(EXPERT::Run(ChartOpen(_Symbol, _Period), Params));
}