Toute question d'un PROFI à un SUPER PROFI - 1. - page 41

 
Sergey Dzyublik:

Super ! Une façon intéressante de procéder.

 
Ihor Herasko:

Super ! Une façon intéressante de procéder.

https://www.mql5.com/ru/search#!keyword=TOSTRING

Поиск - MQL5.community
Поиск - MQL5.community
  • www.mql5.com
Поиск выполняется с учетом морфологии и без учета регистра. Все буквы, независимо от того, как они введены, будут рассматриваться как строчные. По умолчанию наш поиск показывает страницы...
 
fxsaber:

https://www.mql5.com/ru/search#!keyword=TOSTRING

Oui, je me souviens que tu es un génie de la macro. Merci. Une autre chose est que l'œuvre n'est presque nulle part décrite. Pouvez-vous indiquer une source qui décrit ces subtilités ? Pour C/C++, bien sûr.

J'utilise les macros très rarement et à un niveau simple. Apparemment, je les ai négligés sans le mériter.

 
Merci pour votre réponse rapide et complète !
 
Ihor Herasko:

Pouvez-vous indiquer une source qui décrit ces subtilités ?

J'ai appris les macros à partir du seul exemple de MQ qui figurait dans l'annonce de l'une des versions de MT5. Vous avez saisi # et ## et c'était un bon exemple. Je ne trouve pas le lien.

 
fxsaber:

J'ai appris les macros à partir du seul exemple de MQ, qui se trouvait dans l'annonce de l'une des versions de MT5. On y a inscrit # et ## et il y avait un bon exemple. Je ne trouve pas le lien.

Je vois, merci encore.

 
Andrey Khatimlianskii:

Les coïncidences arrivent... Je viens d'envoyer à CodeBase un fichier include pour publication, que j'ai compilé sur la base de cette discussion en 2015: https://www.mql5.com/ru/forum/63951/page2#comment_1908129.

Les codes eux-mêmes dans le fichier de la bibliothèque que j'ai préparé pour la publication sont simples. En même temps, le sens est tel que vous l'avez demandé et approximativement tel queSergey Dzyublik l'a apporté.

P./S. : Avec le temps, il s'est avéré que c'est le plus simple qui est devenu le plus applicable pour moi. Avec le temps, je me suis rendu compte que sans ce fichier inclus - il manque quelque chose / *lorsque l'on sort certains résultats : lorsque l'on construit des codes, les fonctions fonctionnent*/.

 
fxsaber:

J'ai appris les macros à partir du seul exemple de MQ, qui se trouvait dans l'annonce de l'une des versions de MT5. On y a inscrit # et ## et il y avait un bon exemple. Je ne trouve pas le lien.

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

Changements dans les constructions du terminal client MetaTrader 5

MetaQuotes Software Corp., 2014.10.30 06:25

Mise à jour de la plateforme MetaTrader 5 build 1010 : Nouveaux signaux, marché et options

Une mise à jour de la plateforme MetaTrader 5 sera publiée le vendredi 31 octobre. La mise à jour contiendra les changements suivants :

MetaTrader 5 Client Terminal build 1010
  1. MQL5 : Ajout de la conversion des paramètres de macro en chaîne de caractères et de la concaténation des paramètres de macro. Voici un exemple où la concaténation de macros permet d'organiser la suppression automatique d'instances de classes.
  2. //+------------------------------------------------------------------+
    //|                                                     MacroExample |
    //|                        Copyright 2014, MetaQuotes Software Corp. |
    //|                                       http://www.metaquotes.net  |
    //+------------------------------------------------------------------+
    #property  script_show_inputs
    input bool InpSecond=true;
    
    #define  DEFCLASS(class_name) class class_name:public CBase{public:class_name(string name):CBase(name){}};
    #define  TOSTR(x) #x
    #define  AUTODEL(obj) CAutoDelete auto_##obj(obj)
    #define  NEWOBJ(type,ptr) do { ptr=new type(TOSTR(ptr)); \
                             Print("Create object '",TOSTR(type)," ",TOSTR(ptr),"' by macro NEWOBJ"); } \
                             while(0)
    //+------------------------------------------------------------------+
    //| Базовый класс, необходим для автоудаления объектов               |
    //+------------------------------------------------------------------+
    class CBase
      {
    protected:
       string            m_name;
    
    public:
                         CBase(string name):m_name(name) { }
       string            Name(void) const{ return(m_name); }
    
      };
    //+------------------------------------------------------------------+
    //| Класс автоудаления объектов позволяет не следить за созданными   |
    //| объектами. Он удаляет их в своем деструкторе                     |
    //+------------------------------------------------------------------+
    class CAutoDelete
      {
       CBase            *m_obj;
    
    public:
                         CAutoDelete(CBase *obj):m_obj(obj) { }
                        ~CAutoDelete()
         {
          if(CheckPointer(m_obj)==POINTER_DYNAMIC)
            {
             Print("Delete object '",m_obj.Name(),"' by CAutoDelete class");
             delete m_obj;
            }
         }
      };
    //+------------------------------------------------------------------+
    //| Объявим два новых класса CFoo и CBar                             |
    //+------------------------------------------------------------------+
    DEFCLASS(CFoo);
    DEFCLASS(CBar);
    //+------------------------------------------------------------------+
    //| Основная функция скрипта                                         |
    //+------------------------------------------------------------------+
    void OnStart()
      {
       CFoo *foo;
    //--- создадим объект класса CFoo
       NEWOBJ(CFoo,foo);
    //--- создадим экземпляр класса автоудаления объекта CFoo foo
       AUTODEL(foo);
    //---
       if(InpSecond)
         {
          CBar *bar;
          //---
          NEWOBJ(CBar,bar);
          AUTODEL(bar);
         }
    //--- Удалять foo не нужно, он будет удален автоматически
      }
    //+------------------------------------------------------------------+
 
fxsaber:

Merci. Je vais faire la même chose.

A en juger par l'heure de publication (06:25), j'ai stupidement trop dormi aux nouvelles))).

 

Bonjour, on m'a envoyé un indicateur MA avec tous les niveaux dont j'ai besoin. Le problème est que lorsque je passe ma souris sur l'indicateur (chaque MA), il n'affiche pas la période de cette MA. Comment le réparer ? Erreur de syntaxe constante lors de la modification deIndicatorShortName("MASHKI =)") ; Veuillez m'aider.

//+------------------------------------------------------------------+
//|                                                       ManyMA.mq4 |
//|                                                              VVM |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "VVM"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Gold
#property indicator_color2 Aqua
#property indicator_color3 Blue
#property indicator_color4 Magenta
#property indicator_color5 Red
#property indicator_color6 Green
#property indicator_color7 BurlyWood
#property indicator_color8 DarkViolet

extern int MA1_Period=8;
extern int MA1_Shift=0;
extern int MA1_Method=1;

extern int MA2_Period=13;
extern int MA2_Shift=0;
extern int MA2_Method=0;

extern int MA3_Period=21;
extern int MA3_Shift=0;
extern int MA3_Method=1;

extern int MA4_Period=50;
extern int MA4_Shift=0;
extern int MA4_Method=1;

extern int MA5_Period=50;
extern int MA5_Shift=0;
extern int MA5_Method=0;

extern int MA6_Period=100;
extern int MA6_Shift=0;
extern int MA6_Method=0;

extern int MA7_Period=200;
extern int MA7_Shift=0;
extern int MA7_Method=0;

extern int MA8_Period=350;
extern int MA8_Shift=0;
extern int MA8_Method=1;

extern int MA9_Period=1000;
extern int MA9_Shift=0;
extern int MA9_Method=0;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
double ExtMapBuffer9[];

int ExtCountedBars=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin1;
   int    draw_begin2;
   int    draw_begin3;
   int    draw_begin4;
   int    draw_begin5;
   int    draw_begin6;
   int    draw_begin7;
   int    draw_begin8;
   int    draw_begin9;
   
   string short_name;
   SetIndexStyle(0, DRAW_LINE, 0, 2);
   SetIndexStyle(1, DRAW_LINE, 0, 2);   
   SetIndexStyle(2, DRAW_LINE, 0, 2);   
   SetIndexStyle(3, DRAW_LINE, 0, 2);   
   SetIndexStyle(4, DRAW_LINE, 0, 2);   
   SetIndexStyle(5, DRAW_LINE, 0, 3);   
   SetIndexStyle(6, DRAW_LINE, 0, 3);   
   SetIndexStyle(7, DRAW_LINE, 0, 3);   
   SetIndexStyle(8, DRAW_LINE, 0, 4);   
   
   SetIndexShift(0, MA1_Shift);
   SetIndexShift(1, MA2_Shift);
   SetIndexShift(2, MA3_Shift);
   SetIndexShift(3, MA4_Shift);
   SetIndexShift(4, MA5_Shift);
   SetIndexShift(5, MA6_Shift);
   SetIndexShift(6, MA7_Shift);
   SetIndexShift(7, MA8_Shift);
   SetIndexShift(8, MA9_Shift);
   
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   
   draw_begin1=MA1_Period-1;
   draw_begin2=MA2_Period-1;
   draw_begin3=MA3_Period-1;
   draw_begin4=MA4_Period-1;
   draw_begin5=MA5_Period-1;
   draw_begin6=MA6_Period-1;
   draw_begin7=MA7_Period-1;
   draw_begin8=MA8_Period-1;
   draw_begin9=MA9_Period-1;
   
   IndicatorShortName("MASHKI =)");
   
   SetIndexDrawBegin(0,draw_begin1);
   SetIndexDrawBegin(1,draw_begin2);
   SetIndexDrawBegin(2,draw_begin3);
   SetIndexDrawBegin(3,draw_begin4);
   SetIndexDrawBegin(4,draw_begin5);
   SetIndexDrawBegin(5,draw_begin6);
   SetIndexDrawBegin(6,draw_begin7);   
   SetIndexDrawBegin(7,draw_begin8);
   SetIndexDrawBegin(8,draw_begin9);
   
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexBuffer(7,ExtMapBuffer8);
   SetIndexBuffer(8,ExtMapBuffer9);
   
   
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   ExtCountedBars=IndicatorCounted();
   if (ExtCountedBars<0) return(-1);
   if (ExtCountedBars>0) ExtCountedBars--;
   switch(MA1_Method)
     {
      case 0 : sma(1, MA1_Period);  break;
      case 1 : ema(1, MA1_Period);  
     }
   switch(MA2_Method)
     {
      case 0 : sma(2, MA2_Period);  break;
      case 1 : ema(2, MA2_Period); 
     }
   switch(MA3_Method)
     {
      case 0 : sma(3, MA3_Period);  break;
      case 1 : ema(3, MA3_Period); 
     }
   switch(MA4_Method)
     {
      case 0 : sma(4, MA4_Period);  break;
      case 1 : ema(4, MA4_Period); 
     }
   switch(MA5_Method)
     {
      case 0 : sma(5, MA5_Period);  break;
      case 1 : ema(5, MA5_Period);
     }
   switch(MA6_Method)
     {
      case 0 : sma(6, MA6_Period);  break;
      case 1 : ema(6, MA6_Period);  
     }
   switch(MA7_Method)
     {
      case 0 : sma(7, MA7_Period);  break;
      case 1 : ema(7, MA7_Period);  
     }                  
   switch(MA8_Method)
     {
      case 0 : sma(8, MA8_Period);  break;
      case 1 : ema(8, MA8_Period);  
     }
   switch(MA9_Method)
     {
      case 0 : sma(9, MA9_Period);  
      case 1 : ema(9, MA9_Period);  
     }      

   return(0);
  }

void sma(int MAnum, int MA_period)
  {
   double sum=0;
   int    i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<MA_period) pos=MA_period;
   for(i=1;i<MA_period;i++,pos--)
      sum+=Close[pos];
//---- main calculation loop
   while(pos>=0)
     {
      sum+=Close[pos];
      switch(MAnum)
        {
          case 1 : ExtMapBuffer1[pos]=sum/MA_period; break;
          case 2 : ExtMapBuffer2[pos]=sum/MA_period; break;
          case 3 : ExtMapBuffer3[pos]=sum/MA_period; break;
          case 4 : ExtMapBuffer4[pos]=sum/MA_period; break;
          case 5 : ExtMapBuffer5[pos]=sum/MA_period; break;
          case 6 : ExtMapBuffer6[pos]=sum/MA_period; break;
          case 7 : ExtMapBuffer7[pos]=sum/MA_period; break;
          case 8 : ExtMapBuffer8[pos]=sum/MA_period; break;
          case 9 : ExtMapBuffer9[pos]=sum/MA_period;    
        }        
                       
           sum-=Close[pos+MA_period-1];
           pos--;
     }
//---- zero initial bars
      if(ExtCountedBars<1)
      switch(MAnum)
        {
          case 1 : for(i=1;i<MA_period;i++) ExtMapBuffer1[Bars-i]=0; break;
          case 2 : for(i=1;i<MA_period;i++) ExtMapBuffer2[Bars-i]=0; break;
          case 3 : for(i=1;i<MA_period;i++) ExtMapBuffer3[Bars-i]=0; break;
          case 4 : for(i=1;i<MA_period;i++) ExtMapBuffer4[Bars-i]=0; break;
          case 5 : for(i=1;i<MA_period;i++) ExtMapBuffer5[Bars-i]=0; break;
          case 6 : for(i=1;i<MA_period;i++) ExtMapBuffer6[Bars-i]=0; break;
          case 7 : for(i=1;i<MA_period;i++) ExtMapBuffer7[Bars-i]=0; break;
          case 8 : for(i=1;i<MA_period;i++) ExtMapBuffer8[Bars-i]=0; break;
          case 9 : for(i=1;i<MA_period;i++) ExtMapBuffer9[Bars-i]=0;
        }                 
  }
  
  void ema(int MAnum, int MA_Period)
  {
   double pr=2.0/(MA_Period+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      switch(MAnum)
        {
          case 1 : if(pos==Bars-2) ExtMapBuffer1[pos+1]=Close[pos+1]; break;
          case 2 : if(pos==Bars-2) ExtMapBuffer2[pos+1]=Close[pos+1]; break;
          case 3 : if(pos==Bars-2) ExtMapBuffer3[pos+1]=Close[pos+1]; break;
          case 4 : if(pos==Bars-2) ExtMapBuffer4[pos+1]=Close[pos+1]; break;
          case 5 : if(pos==Bars-2) ExtMapBuffer5[pos+1]=Close[pos+1]; break;
          case 6 : if(pos==Bars-2) ExtMapBuffer6[pos+1]=Close[pos+1]; break;
          case 7 : if(pos==Bars-2) ExtMapBuffer7[pos+1]=Close[pos+1]; break;
          case 8 : if(pos==Bars-2) ExtMapBuffer8[pos+1]=Close[pos+1]; break;
          case 9 : if(pos==Bars-2) ExtMapBuffer9[pos+1]=Close[pos+1];
        }     
      switch(MAnum)
        {
          case 1 : ExtMapBuffer1[pos]=Close[pos]*pr+ExtMapBuffer1[pos+1]*(1-pr); break;
          case 2 : ExtMapBuffer2[pos]=Close[pos]*pr+ExtMapBuffer2[pos+1]*(1-pr); break;
          case 3 : ExtMapBuffer3[pos]=Close[pos]*pr+ExtMapBuffer3[pos+1]*(1-pr); break;
          case 4 : ExtMapBuffer4[pos]=Close[pos]*pr+ExtMapBuffer4[pos+1]*(1-pr); break;
          case 5 : ExtMapBuffer5[pos]=Close[pos]*pr+ExtMapBuffer5[pos+1]*(1-pr); break;
          case 6 : ExtMapBuffer6[pos]=Close[pos]*pr+ExtMapBuffer6[pos+1]*(1-pr); break;
          case 7 : ExtMapBuffer7[pos]=Close[pos]*pr+ExtMapBuffer7[pos+1]*(1-pr); break;
          case 8 : ExtMapBuffer8[pos]=Close[pos]*pr+ExtMapBuffer8[pos+1]*(1-pr); break;
          case 9 : ExtMapBuffer9[pos]=Close[pos]*pr+ExtMapBuffer9[pos+1]*(1-pr);
        }             
           pos--;
     }
  }

On ne voit pas la période, juste le nom Mashki =))