Is the task solvable in principle in MQL4 ? - page 2

 

Give me the code, we'll figure it out by tonight.

You can write it in person :)

 
tara:
Give me the code, we'll figure it out by evening.

#property copyright "Copyright 2013, MetaQuotes Software Corp.
#property link "http://www.metaquotes.net"

//#include <WinUser32.mqh>
//int whwnd;
//#include <stdlib.mqh> // Standard library
double b;
double percent;
double maxpercent = 0;
int timetoresume = 10;
int selecttime = 1;
string status,status1;
int total;
int magic[100];
int kol=0;
int tempkol =0;
//+------------------------------------------------------------------+
//| expert initialisation function |
//+------------------------------------------------------------------+
int init()
{

return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
// while(!IsStopped()) // until user.
/// { // ...does not stop executing the program
// RefreshRates();
b = AccountBalance()/100;
percent = AccountProfit()/b;
if (maxpercent > percent) maxpercent = percent;
Timetoresume = TimeLocal();
if (percent*(-1) > 1) status = "Freeze Active";
else status = "Running";
total=OrdersTotal();
kol = 0;
for (int i=total; i>0; i--) { //assign each element of the array to the value of each open order
OrderSelect (i-1,SELECT_BY_POS,MODE_TRADES);
magic[i] = OrderMagicNumber ();
// Print ("Magic " + i+" " +magic[i];
}
for (int k = 1; k <= 1; k++){ // compare the magic number of the first open order with the subsequent ones
tempkol = magic[k];
for ( int l = 1; l <=total;l++){
if (tempkol != magic[l]) kol++;
}
}
if(kol >= 2){ // if more than 2 EAs have already entered the trade
GlobalVariableSet ("Freeze1",200) ; // other EAs must listen to these global variables
GlobalVariableSet ("Freeze2",200); // and not to enter into deals, while the rest of them have time to open orders
status1="test2"; // advisor GlobalVariableSet ("Freeze1",200) does, having waited its turn
} //waiting for its turn in the terminal
Comment ( AccountProfit()
,"\n"
, "DrawDown " , NormalizeDouble (percent,1)*(-1), " % ", " MaxDrawDown " , NormalizeDouble (maxpercent,1)*(-1), " % "
, Timetoresume
,"\n"
",status," ",percent*(-1)
,"\n"
, "order total ",total
,"\n"
, "OrderSymbol()," Magic ",OrderMagicNumber()," ",kol
,"\n"," ",status1
);
return;
}

//+------------------------------------------------------------------+

Don't judge, last time I wrote a program in Sinclair, in Basic when I was at school .....


 
Zakyza:


Is it possible to set a system of priorities in MQL4, so that first the code of the managing EA is executed, and then all other EAs?


Of course it is possible.

Organise the work of EAs according to "master-slave" scheme

 
avtomat:


Of course you can.

Organise master-slave advisers to work in a "master-slave" way


Please tell me more about how to do it. Trading Expert Advisors can be influenced only by changing the global variable and they listen to this variable GlobalVariableSet ("Freeze1",200) when my "manager" deigns to wait his turn and write there 200
 
Zakyza:

Please tell me more about how to arrange this. Trading Expert Advisors can be influenced only by changing the value of global variable and they listen to this variable GlobalVariableSet ("Freeze1",200) when my "manager" deigns, waiting for his turn, to write 200 there

Why does your manager, if he is the manager, wait for some kind of turn?

It's the slaves who should wait for theirs: manager has written a trade ban in GV - they sit, stay quiet (slave has checked global flag first tick, if 'sit no bleep' - said JawolGerGeneral, and return(0))...

Why is your manager waiting his turn to access the GV flag?

 
It's all done by one Expert Advisor )))) You can cram 100 pairs into it ))))
 
artikul:
It's all done by one Expert Advisor )))) You can put as many as 100 pairs into it ))))

That's not what we're talking about...
 

master

//+------------------------------------------------------------------+
int deinit()
  {
      GlobalVariableSet(work,0);   // запрещение работы ведомым
   return(0);
  }
//+------------------------------------------------------------------+
.....

int start()
   .....

   work=GlobalVariableGet(work);

   if( work==0 && всё_хорошо )   GlobalVariableSet(work,1);   // разрешение работы ведомым

   if( work==1 && всё_плохо )    GlobalVariableSet(work,0);   // запрещение работы ведомым

// можно организовать систему запретов/разрешений любой сложности   

   .....

slave

.....

int start()


   work=GlobalVariableGet(work);

   if( work==0 )   { стоп } ;    // здесь возможны некоторые действия для завершения текущих процессов

   if( work==1 )   { работа };   // ведомым разрешена работа -- можно работать в нормальном режиме

.....

I hope I have made myself clear.

 
avtomat:

master

slave

I hope I have made myself clear.


All clear, thank you.

I've tried it this way (i.e. to prohibit and allow according to the situation), but it works the following way for me:

After this initialization of the master: int deinit().... // prohibition of work by sl aves is silent, but as soon as the wizard relaxes ( if (number of identical majik <=2) ) and writes in GlobalVariableSet(work,1); // enabling slaves , and there are 8 slaves on 8 different pairs, manage to open in 4 - 6 pairs instead of 2 as specified in the master's conditionThey open BEFORE the master "understands" that the "number of identical majicies" is significantly greater than 2. After that of course the other slaves are silent, but it is no longer open 2 copies as desired, but 4 - 6.

As I understand it, control is given to int start ( ) slave EAs after I execute int start() code and it depends on int start( )of slave EAs and how many copies of each pair will open before start of the wizard and a global one becomes prohibitive. Please correct me if I have misunderstood the terminal's algorithm and the essence of the problem. Roughly speaking so: if one master and one slave is most likely to work correctly, but the slaves then 8-10 !

That's why I wrote, I tried to loop start master and make it stay on forever, but my terminal just hung.

artmedia70: " why is your manager, if it is a manager, waiting for some kind of queue? " - that's what I'd like to know.

 

And why and why are two identical magicians being made?

Global variables can be used to assign non-overlapping magic areas to the included EAs. The corresponding checks and assignments are made in init().

Besides, we can limit the number of orders opened for each symbol by specifying it explicitly or by assigning a master, depending on the current general situation, which is exactly what the master should control.

This means that if the slave makes an action, he/she has to report to the master. The master, in turn, must give his summary, on which the slave's further actions (or inaction) depend.

Reason: