[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 385

 
granit77:
Victor, you're wrong. Thanks to this somewhat lengthy discussion, two programmers were answering questions from newcomers at the same time, which only benefited the thread :))

Well, I enjoyed reading it. And it was very revealing the attitude of advanced (I don't know how to call you programmers now or not - I'm confused now : )) ) - Let's put it this way - specialists, solving advanced problems : ))) and their views on seemingly simple tasks. I sincerely hope that this is an emotionless and friendly discussion, despite all the disagreements. I, unfortunately, still have my differences (unresolved) too. But I am just here professing a philosophical approach. If the solution to a problem in that way is not obvious, you have to find another way. But it is very useful to know about the problem.

Thank you very much for the discussion. It is a pity that we have not come to a consensus. (But, no consensus has emerged yet... (the song "There, far away, by the metro" comes to mind))

And it's a pity, of course, that there were no obvious answers to my and Arles' questions. I think these questions are not just for him and me, but for many less experienced professionals who find it difficult to build their own threads and I.T., and that's why they turn to programs and shells written by advanced professionals.

Well, that's all right. In time we will solve these issues too. : )) Thank you very much for your efforts. All the parties have a positive attitude in the end (although they have different ways of solving them). And it pleases.

By the way, in my pedagogical researches I often say: not all questions can be solved, we often don't know all the answers; therefore, they can still... remain open. (I'm trying to find a delicate end to the discussion) Thanks again!
 
Need help 1 how to know the price of the top open or pending sell order 2 how to check if there is an open or pending sell order at the price I have specified
 

Sergei, what issues have been unresolved? If this:

Chiripaha:

I.e. answering Arles' question, if one EA has made accounting of orders and "took a nap" for a while, at that moment another EA that has not exceeded the limit of allocated funds (let us assume 80% of deposit - both EAs will have this size) will place an order (enter a deal at the market). And when the 1st one resumes the work (and the money management terminal has already been calculated the day before), he/she will also open a deal exceeding the limits set by the Expert Advisor?

If this system (hypothetically) is multiplied by several EAs, then may there be one, where the Risk-Management will be in critical system?

Do I understand this multi-threading correctly? - If so, then from a financial point of view, of course, it is a mess. But because the probability is small in small accounts, it's only hypothetical. And on larger accounts, they will probably write something themselves. But still, does it turn out to be the case?

And I have a question - is this the official position or is it just speculation and experiences like mine?

There is a code on page 378. Here it is again:

#property show_inputs

extern int Pause = 1000;

int    hwndChart = NULL; // Уникальный идентификатор скрипта.
string sName = "Condition";

void init()
 {
  hwndChart = WindowHandle(Symbol(), 0);
  // Создаём глобальную переменную синхронизации скриптов.
  if (!GlobalVariableCheck(sName)) GlobalVariableSet(sName, 0);
 }
 
void deinit()
 {
  GlobalVariableDel(sName);
 }

void start()
 {
  while (!IsStopped())
   {// Начало блока синхронизации.
    GlobalVariableSetOnCondition(sName, hwndChart, 0);
    if (GlobalVariableGet(sName) == hwndChart)
     {
      Print("Start");
      Sleep(Pause); // Имитация работы.
      Print("End");
     }
    GlobalVariableSetOnCondition(sName, 0, hwndChart);
    // Завершение блока синхронизации.
    Sleep(200);
   }
 }
Where the delay is "imitation work" you insert a reference to the deposit or another resource.

You can turn this sync block into a function and put it in the library. You will have a synchronous function of access to the deposit from any EA.

 
Replace the index with the chart window handle
 
FAQ:
Instead of the index, substitute the chart window handle

Right! It's hard to figure out what's what with indices.

I've redone it.

===================

Although, indexing will allow to correctly delete a global variable.

We should decrement the index in the deinit. And delete the global variable when the index is equal to zero.

But this decrement will not allow to reload the script after deletion. The indexes will be mixed up.

We should create a global array of indices of all the modules that access the resource. Well, and work with it.

It is also possible to make two global variables. One with last index, the other with current number of modules. Indexes only increase. Probably, it will be easier.

Or don't bother with global variable at all. Manually delete it before first run.

 
this will work fine until the first deinitial failure, when the experimenter does not decrement the total counter
 
I've got it! We have to exit in sync as well. In deinit wait for your turn and exit with global variable reset. If the resource is accessed for a short time, it will be fine in the deinit.
 

1) Problem : each script (EA) has to be aware of the presence of all the others.

2) Problem : if there is a failure, the globals from the failed one will hang unoccupied and the queue will get stuck.

3) Solution :

Each exp organizes 1 globalka with name - common prefix + window handle + symbol. value of the globalka is time of last tick on that instrument. 2 common global with its own handle (after working it writes its own handle into it or clears it if it is the oldest)

The queue is arranged in ascending order (handles), the most senior sets the second globale to zero

in each exp, we create three arrays (for lack of structures) - symbol/handle/last access time/last tick time.

all EXPs keep track of (last access time/last tick time) for all of them and as soon as they are different (one of EXPs fails) both globals of the failed EXP are deleted and it is considered inactive. its cells in the arrays are deleted (the array is rebuilt).

queue is restored

this will actually be done by the EA standing on the most active chart (frequent ticks).

when deinitialized normally, each expo will clean up after itself.

max skip - one tick.

ZS. and in general it's better to do one multicurrency

 
Zhunko:

Sergei, what issues have been unresolved? If that:

There is a code on page 378. Here it is again:

Where there is a delay "imitation of work" you insert a reference to the deposit or to another resource.

You can turn this sync block into a function and put it in the library. You'll get a synchronous function of access to the deposit from any Expert Advisor.

This is an atomic access block and there is no synchronization. It makes no sense to apply only to the deposit. The calling of any of the deposit parameters functions will be atomic by itself, without any nudges. If you do it atomically, all the work of the Expert Advisor. That's how you solve problems - you think you've done something, but in fact it's an illusion.

 
FAQ:

1) Problem : each script (EA) must be aware of the presence of all the others.

2) Problem : if there is a failure, the globals from the failed one will hang unoccupied and the queue will get stuck.

3) Solution :

Each exp organizes 1 globalka with name - common prefix + window handle + symbol. value of the globalka is the time of last tick on that instrument. 2 common global with its own handle (after working it writes its own handle into it or clears it if it is the oldest)

The queue is arranged in ascending order (handles), the most senior sets the second globale to zero

in each exp, we create three arrays (for lack of structures) - symbol/handle/last access time/last tick time.

all EXPs keep track of (last access time/last tick time) for all of them and as soon as they are different (one of EXPs fails) both globals of the failed EXP are deleted and it is considered inactive. its cells in the arrays are deleted (the array is rebuilt).

queue is restored

this will actually be done by the EA standing on the most active chart (frequent ticks).

when deinitialized normally, each expo will clean up after itself.

max skip - one tick.

ZS. and in general it is better to do one multicurrency


He will not understand, too badly seen from above)))) I have this task solved in about this style. It's nice to have someone who understands the essence of the problem. Only I still have a queue, in which order the tasks began to be performed, and are performed further in a circle.
Reason: