Librerie: Esperto - pagina 3

 
Un esempio di applicazione della libreria

Forum sul trading, sui sistemi di trading automatizzati e sulla verifica delle strategie di trading

ParametroGetRange()

fxsaber, 2018.11.16 09:17

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

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

// Raccoglie dati sulla gamma di parametri di ingresso per l'ottimizzazione
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
 
Bug risolto.
 
Bug risolto. Ultima versione.
 

Come si può eseguire un Expert Advisor in formato .ex4 collegandolo in un Expert Advisor con un nome diverso, ed è necessario che i parametri di input siano stati visualizzati, cioè che sia stato possibile lavorare completamente con esso.

Abbiamo un Expert Advisor compilato con il nome "Trade.ex4".

Creiamo un nuovo Expert Advisor con il nome "Hand.ex4".

Come combinarli in modo che quando viene lanciato "Hand.ex4", "Trade.ex4" sia completamente funzionante e "Trade.ex4" sia incorporato in "Hand.ex4".

Cioè, abbiamo solo il file Hand.ex4 sulla macchina, ma usiamo Trade.ex4 nel lavoro.

Grazie!

 
Vitaly Muzichenko:

Come si può eseguire un Expert Advisor in formato .ex4...

La libreria nella sua forma attuale funziona solo con EX5.

 
Sergey Eremin:

Io stesso, nell'ambito di un certo progetto, ho risolto in questo modo (con il tag "name" proprio così):

Grazie, funziona così!

Ho solo aggiunto chartId al nome del modello salvato, in modo che EA identici su grafici diversi non lottino per lo stesso file.


@fxsaber, c'è "#ifndef __MQL5__" nel codice, perché non portare la multipiattaforma alla sua logica conclusione?

Per far funzionare Is, aggiungiamo all'inizio del codice:

#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

E correggere la funzione stessa:

  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);
  }


Ci sono altre difficoltà?

 
Andrey Khatimlianskii:

Ci sono altre difficoltà?

Un grafico con un solo indicatore in funzione.


ZY Questo è il modo in cui dovrebbe funzionare

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

Tutte le funzionalità della libreria funzionano ora su MT4.

La libreria è diventata multipiattaforma.

 
Tutte le funzionalità della libreria funzionano ora su MT4.
La libreria è diventata multipiattaforma.


Esempio MT4:

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

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

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:

Qual è il modo migliore per eseguire un EA in .ex4...

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

void OnStart()
{
  MqlParam Params[2];

  // Percorso per diventare Counsellor
  Params[0].string_value = "Moving Average";
  
  // Il primo parametro di input dell'Expert Advisor
  Params[1].type = TYPE_DOUBLE;
  Params[1].double_value = 0.5;  

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