Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1502

 
psihodelit import a function from one EA to another?

For example, there is an EA that opens orders, and there is an EA that monitors the state of the account, where the parameters drawdown, etc. are specified,

I need that when the drawdown of the second advisor is reached, the first advisor does not open orders....

How to do it for example?

There are several options.

You can use the advice above. It is quite a working variant.

You can use Global variables of the terminal.

You can set up an exchange between Expert Advisors by writing/reading a file.

As they say, all felt-tip pens are different for taste and colour.)

 
psihodelit import a function from one EA to another?

For example, there is an EA that opens orders, and there is an EA that monitors the state of the account, where the parameters drawdown, etc. are specified,

I need that when the drawdown of the second advisor is reached, the first advisor does not open orders....

How to do it for example?

To begin with (IMHO of course) you need to understand a few subtleties

  1. Whether the code of both EAs is available for editing.
  2. Do EAs leave traces of their activity in Global Variables
  3. Do you have at least basic coding skills?
If the answer to all three subtleties is positive, it will be easy to implement what you have planned, if there are gaps it will be more difficult, but it is also possible - we will think of something together.
 
Sergey Voytsekhovsky #:

If the answer to all three subtleties is positive, ...

then this question would not arise here.

 
Yuriy Bykov #:

Thank you very much for the idea suggested above. Here's what came out of it, if you're interested.

//---
   NOD = 1;
   ArraySort(Arr_ZigLag);
   size_zigLag = ArraySize(Arr_ZigLag);
   for(int i = size_zigLag - 1; i > 0; i--)
     {
      if(NOD != 1)
         if(Arr_ZigLag[i] != Arr_ZigLag[i-1])
            NOD = CalculateNOD(Arr_ZigLag[i-1], NOD);
      if(NOD == 1)
         if(Arr_ZigLag[i] != Arr_ZigLag[i-1])
            NOD = CalculateNOD(Arr_ZigLag[i], Arr_ZigLag[i-1]);
           }
   return(NOD);
  }
//+------------------------------------------------------------------+
//| Функция НОД(НаибольшийОбщийДелитель)                             |
//+------------------------------------------------------------------+
int CalculateNOD(int a=1, int b=1)
  {
   int Nod = (int)MathMod(a, b);
   while(Nod > 0)
     {
      a = b;
      b = Nod;
      Nod = (int)MathMod(a, b);
     }
   if(Nod == 0)
      Nod = b;
   return(Nod);
  }
 
Sergey Voytsekhovsky #:

Or you could go like this:

//+------------------------------------------------------------------+
//| Наибольший общий делитель чисел a и b                            |
//+------------------------------------------------------------------+
int gcd(int a, int b) {
   int c;

   while(b > 0) {
      c = a % b;
      a = b;
      b = c;
   }

   return a;
}

//+------------------------------------------------------------------+
//| Наибольший общий делитель массива чисел a                        |
//+------------------------------------------------------------------+
int ArrayGcd(int &a[]) {
   int n = ArraySize(a);
   if(n == 1) {
      return 0;
   }
   int c = gcd(a[0], a[1]);

   for(int i = 2; i < n; i++) {
      c = gcd(a[i], c);
      if(c == 1) {
         break;
      }
   }
   return c;
}


int OnCalculate(...) {
   ...
   ArraySort(Arr_ZigLag);
   NOD = ArrayGcd(Arr_ZigLag);
   return(NOD);
  }
 
Yuriy Bykov #:

Or you could go like this:

I agree, beautiful! May I put it in the library?

 
Yuriy Bykov #:

Or you could go like this:

Can you give me a hint if I can get the question across?

You used the maths f. "Residue from division", but I have the inbuilt function" MathMod", it talks about"real remainder from division of two numbers". What does the word "real" mean????

 
Sergey Voytsekhovsky #:

What does the word EVERYTHING mean???

In this case, fractional numbers are implied.

 
Aleksandr Slavskii #:

There are several options.

You can use the advice above. It is quite a workable option.

You can use Global terminal variables.

You can set up exchange between Expert Advisors by writing/reading a file.

As they say, all felt-tip pens are different for taste and colour)))))

How only to understand in what direction to move, where to start and how. There is almost no knowledge...

  1. Is the code of both advisors available for editing?
    Yes.
  2. Do advisors leave traces of their activity in Global Variables
    I can't say for sure.
  3. Do you have at least basic coding skills
    A little bit at all.
 
psihodelit #:

How to understand in what direction to move, where to start and how. I have almost no knowledge...

  1. Is the code of both Expert Advisors available for editing?
    Yes.
  2. Do advisors leave traces of their activity in Global Variables
    I can't say for sure.
  3. Do you have at least basic coding skills
    A little bit at all.

First of all, answer these three questions to yourself. If you can not answer, you need to fill out, study. This is what-to understand in what direction to move.

If the essence of the question, you need the files of advisors that you want to mix, they will show what can be done. If you can't or don't want to upload them, you can look at screenshots of the necessary places.

Reason: