Bibliothèque: Expert - page 3

 
Un exemple d'une autre application de la bibliothèque

Forum sur le trading, les systèmes de trading automatisés et les tests de stratégies de trading

ParameterGetRange()

fxsaber, 2018.11.16 09:17

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

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

// Collecte des données sur l'éventail des paramètres d'entrée pour l'optimisation
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
 
Correction d'un bug.
 
Bogue corrigé. Dernière version.
 

Comment exécuter un Expert Advisor au format .ex4 en le connectant à un Expert Advisor portant un nom différent, et il est nécessaire que les paramètres d'entrée soient affichés, c'est-à-dire qu'il soit possible de travailler pleinement avec lui.

Nous disposons d'un Expert Advisor compilé portant le nom "Trade.ex4".

Nous créons un nouveau conseiller expert portant le nom "Hand.ex4".

Comment les combiner de sorte que lorsque "Hand.ex4" est lancé, "Trade.ex4" soit entièrement fonctionnel et que "Trade.ex4" soit intégré dans "Hand.ex4".

En d'autres termes, nous n'avons que le fichier Hand.ex4 sur la machine, mais nous utilisons Trade.ex4 dans le cadre de notre travail.

Nous vous remercions de votre attention.

 
Vitaly Muzichenko:

Comment faire fonctionner un Expert Advisor au format .ex4...

La bibliothèque, dans sa forme actuelle, ne fonctionne qu'avec EX5.

 
Sergey Eremin:

Pour ma part, dans le cadre d'un certain projet, j'ai résolu le problème de cette manière (avec la balise "name" comme ça) :

Merci, ça marche comme ça !

J'ai seulement ajouté chartId au nom du modèle sauvegardé, afin que des EA identiques sur des graphiques différents ne se battent pas pour le même fichier.


@fxsaber, il y a "#ifndef __MQL5__" dans le code, pourquoi ne pas pousser le cross-platform jusqu'à sa conclusion logique ?

Pour faire fonctionner Is, on ajoute au début du code :

#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

Et corriger la fonction elle-même :

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


D'autres difficultés ?

 
Andrey Khatimlianskii:

D'autres difficultés ?

Un graphique avec un seul indicateur en cours d'exécution.


ZY Voici comment cela devrait fonctionner

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

Toutes les fonctionnalités de la bibliothèque fonctionnent désormais sur MT4.

La bibliothèque est devenue multiplateforme.

 
Toutes les fonctionnalités de la bibliothèque fonctionnent désormais sur MT4.
La bibliothèque est devenue multiplateforme.


MT4-exemple :

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

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

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:

Quelle est la meilleure façon d'exécuter un EA en .ex4...

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

void OnStart()
{
  MqlParam Params[2];

  // Parcours pour devenir conseiller
  Params[0].string_value = "Moving Average";
  
  // Le premier paramètre d'entrée du conseiller expert
  Params[1].type = TYPE_DOUBLE;
  Params[1].double_value = 0.5;  

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