Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 783

 

Is it possible to create one template and apply it to multiple functions?

template<typename T>
void Fun1(T &y)
{тело
}
void Fun1(T &r,T k)
{тело
}
int Fun1(T &r,T k)
{тело return(0);
}

If variables of the same type are used, it would be very useful to know if it is possible to use one template for several functions.

 
Good afternoon, could you please tell me how to add oil, indices and metals quotations?
 
vfrfhjybgjakjncmrb:
Hello, could you please tell me how to add quotes for oil, indices and metals?

It depends firstly on whether the office broadcasts them or not. It also depends on the terminal in which you work. If the office broadcasts them, then you need to know on what accounts and under what conditions these quotes are broadcasted, perhaps you just need to open the list of instruments and these instruments are there. If the office broadcasts them on conditions that are impossible for you, you have to create a chart with these quotes and update them every time. Do you know for sure that your brokerage firm will broadcast Oil?

 
Seric29:

Is it possible to create one template and apply it to multiple functions?

If variables of the same type are used, it would be very useful to know if it is possible to use one template for several functions.

No. A complete description of each function must be given separately. Otherwise you won't be able to read your own code later.

 
How can I remove a particular indicator from all charts in one move? Applying a new template doesn't work. How about a script?
 
Ilya Prozumentov:

No. A full description of each function must be given separately. Otherwise you won't be able to read your own code after a while.

That's a pity. You won't be able to read your own code anyway if you don't do it. I just want to write compact programs, because you often use variables of the same type in functions, that's why I asked. I thought it would be possible to use "classes", but I'm still not familiar with them. So I'll know if I have to make templates for many functions.

 

Who can tell me why this entry doesn't work. I want to access the fields of structures that store an array and rotate it depending on which condition is fulfilled.Execution of the condition depends on theArrayDimension function.

   struct SD1{
   int a[10];//int q[10][2];
};SD1 a1;

struct SD2{
   int a[10][2];
};SD2 a2;

template<typename T>//,typename W
void MoveArray(T & s){//,W&e
   //Alert(ArrayDimension(s.a));
     int r=0;r=ArrayDimension(s.a);Print("r-ранг: ",r);if(r==1)пишу условие что если ранг равен 1му 
      {for(int cn=0; cn<=8; cn++)                              то крутить этот цикл
     {                
      s.a[cn]=s.a[cn+1];
     }} else if (r==2)            если ранг равен 2ум
      {for(int cn=0; cn<=8; cn++) крутить этот цикл
     {                
      s.a[cn][0]=s.a[cn+1][0];
      s.a[cn][1]=s.a[cn+1][1];
     }}  
}

Eventuallyit gets in the first loop despite the fact that this conditionif(r==1)is false, why it gets there if the rank is 2um, how it despite the false gets into the body where something is executed.

   MoveArray(a2);в OnTick
   for(int i=0;i<10;i++){Print("q: ",i,": ",a2.a[i][0]);}
int yy=ArrayDimension(a2.a);Print("Ранг: ",yy," ");
 
Seric29:

Pity. You won't be able to read your own code anyway if you don't do it or if you don't do it. I just want to write compact programs, because you often use variables of the same type in functions, that's why I asked. I thought it would be possible to use "classes", but I'm still not familiar with them. So I'll know if I have to make templates for many functions.

I can't grasp the essence of how compactness would be achieved. In the example above it saves 2 lines. If you want to save them so much, you can write a macrosubstitution and use it in the line before the function

#define  templ(T) templeate<typename T>

templ(T1) void Funct(T1 a)
 
Ilya Prozumentov:
#define  templ(T) template<typename T>

templ(T1) void Funct(T1 a)

Is it necessary to writetempl(T1) in front of each functionand it will take a variable or the required argument? Why istempl(T) declaredandtempl(T1) called, should I add a number before each function(templ(T1)templ(T2)templ(T3)) or should I writetempl(T1) everywhere?And if several parameters are scored intemplate<typename T>then how would it be, like thistemplate<typename T,typename P,typename Q>-templ(T,P,Q).

 
I have a problem ! I want to trawl profit with another EA, but this EA does not let me pull stop loss for profit! Can anybody correct it! The author is not answering!
Files:
cm-MA_Gread.mq4  18 kb
Reason: