[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 374

 
Arles:
Please advise how to solve the problem: The same EA is on several charts, a signal to open an order appears on two charts at the same time, for example. However, we need the second order not to open. The EA has a check for an open order but it does not help because the first EA has to open the order and the second one also sends a request to open the order. Do you have any solution?
It is not quite clear for what purposes several identical EAs on several charts are used. - Based on this understanding, it would be more logical to advise something. However, based on the information we have, if you want only one EA to trade, you can disable the second EA from trading either in the settings (if any are provided inside the EA) or in the tab "General" - Allow EA to trade (deselect the checkbox).
By the way, all of the Expert Advisors do not work in parallel in the same terminal, but sequentially. - Until the 1st one finishes its work, the 2nd one will not process data. So if the EA is correctly written, i.e. it checks for the order placed, then the second one will already take this order into account. - This is one. But this will only happen if the Expert Advisors are set up to work coherently. Let's say they have the same Magik and accounting for Money Management. Otherwise, only by disabling "unnecessary" EAs. - Then why put them in...?
 
Chiripaha:
It is not quite clear for what purposes several identical EAs on several charts are used.

The Expert Advisor only analyses the pair on which it is hovering. On which pair a signal appears first, it opens an order. But sometimes a signal appears on two pairs at the same time. And, strange as it may seem, 2 orders are opened, though there is a check in the Expert Advisor for each open order and it should not open the second one. This is necessary because we have not enough money on the deposit.

Until the 1st has not finished working, the 2nd will not process data.

Yes, but when the 1st has finished work and opened an order, the 2nd, having started work, for a short time does NOT see that there is already an order. Either he gets to work before the order opens.
--

One more thing: when the 1st EA is Sleep(1000), the second EA waits or starts working?

 

Good afternoon everyone!

Coded the following idea

Condition N1 ..If High[1] exceeds some maximum X

and at the same time

Condition N2 .The difference between High[1] and Low of the first of the next 150 candles >= 150 p.

------------------------------------------------------------------

Action N1 . Delete previous order

Action N2 ..Place pending order

Action N3 . Assign values to variables.

PROBLEM. Despite the fact that the pending order should be placed only if there are no orders in the market, or the last order is not placed on the current bar. if (ot==0|| last_order_bar>0)

When Condition N1 and Condition N2 are fulfilled, SEVERAL pending orders are placed simultaneously.

I want to place only ONE pending order.

-----------------------------------------------

The ot and last_order_bar values are calculated above in this code

                                                                                                                        
                                                                                                                
int last_order_bar = 0;                                                                                                                 
int ot = OrdersTotal();                                                                                                                 
                                                                                                                        
 if (ot>0) //если есть ордера в рынке                                                                                                                   
 {                                                                                                                      
   if (OrderSelect (ot-1,SELECT_BY_POS)) //выбрали последний ордер                                                                                                                      
      if ( OrderType ()==OP_SELLSTOP) //проверили тип
        last_order_bar = iBarShift (Symbol (),0,T ); //запомнили, на каком  баре открыт последний ордер (если он есть)                                                                                                                  
 }                                                                                                                      
if(High[1] > X )
 {
   
   for(int i=1;i<150;i++)
     {
      if((High[1]-Low[i])>=1500*Point)//
      break;         //
             {
     if (ot>0) 
         {
           bool R = OrderDelete(OrderTicket());  
         }
if(R==0)                      //если последний выставленный SELLSTOP удален
         {
if (ot==0 || last_order_bar>0)        
int Ticket=OrderSend(Symbol(),OP_SELLSTOP,0.1,iHigh( Symbol (), 0,1)-1500*Point,1,iHigh( Symbol (), 0,1),iHigh( Symbol (), 0,1)-1610*Point,"jfh",123 );//выставить новый SELLSTOP       
if (Ticket>0)                // если SELLSTOP выставлен
 N = (OrderTicket());        //запомнить в глобальную переменную N тикета данного SELLSTOP .
 T = Time [0];               //запомнить в глобальную переменную время выставления данного SELLSTOP
 X=iHigh( Symbol (), 0,1);   //запомнить в глобальную переменную High свечи N1 после которой был выставлен данный SELLSTOP
   
 }
 }
 }
 }
}
 }   
                        
return(0);
 
Arles:

The Expert Advisor only analyses the pair on which it is hovering. On which pair a signal appears first, it opens an order. But sometimes a signal appears on two pairs at the same time. And, strange as it may seem, 2 orders are opened, though the Expert Advisor has a check for any open order and it should not open the second one. This is necessary because we have not enough money on the deposit.

Yes, but when the 1st one has finished its work and opened an order, the 2nd one, having begun to work, does not see for a short time that the order already exists. Or he gets to work before the order opens.
--

One more thing: when the 1st EA is Sleep(1000), does the second EA wait or start working?

Regarding the first question: I've stipulated that if the EAs are written correctly... Of course, it can happen the way you've described, if there is no check in the EA for an placed (open) order and for calculating the money management - this all depends on the level (and laziness) of the programmer - whether he has thought these things through and prescribed them in the EA or not. If everything is implemented correctly, then none of your concerns will happen. - The signal, yes, may appear at 2 pairs simultaneously, but (see the previous post), the Expert Advisors work sequentially. Therefore, until the first EA has not processed the quotes, the next one will not start working. - I think that this is the reason we decided to use sequential order (even if it were possible to process quotes in parallel, it would be a different topic for discussion).

It also depends on the level of the EA. Because all of the things you asked about are quite a pain to prescribe - very not a small job, requiring knowledge of finances. That's why EAs tend to be "simple", and are geared towards being given the entire account for the current currency. Usually one currency is traded. Because, to trade several currencies, for example, you need to have quite a different type of deposit, and such simple systems are not really applicable there. The only exception to this would be operations (I forgot the exact term, I will rephrase it differently) of hedging, when one opens at one price and immediately reopens at another (or even several) - the difference is to itself. But this is a different type of EA and everything will be accounted for there (all in one). - And in general, in my opinion, if there is no more money than liquidity on a pair, then trading on all pairs at once is a bad tone. (but this is my private opinion) Portfolios etc. - This is not for speculative trading. For some reason people don't take that into account at all. - If you are not a firm that produces or trades internationally then you don't need lots of currencies at all. - That's my point - why don't they usually implement such blocks for accounting for different currencies in EAs - because they are irrelevant.

And to the second question: Frankly speaking, I myself have this question open - I'm not quite sure how the terminal reacts when Sleep(1000) function - I'm appealing to those who know this to give me advice. Ideally, the terminal at this moment will only process the streaming prices - i.e. it will receive quotes and draw charts and indicators. But while this EA is "waiting", it will not pass its turn to anyone else. - But this is my assumption, of which I am not entirely sure. Perhaps, another exception to this "queue" are scripts that can be launched for execution while the EA is waiting. - I have the same question.

However, I get out of this ignorance by building my Expert Advisors based on correctness of the first point.

 
solnce600:

Good afternoon everyone!

Coded the following idea

Condition N1 ..If High[1] exceeds some maximum X

and at the same time

Condition N2 .The difference between High[1] and Low of the first of the next 150 candles >= 150 p.

------------------------------------------------------------------

Action N1 . Delete previous order

Action N2 ..Place pending order

Action N3 . Assign values to variables.

PROBLEM. Despite the fact that the pending order should be placed only if there are no orders in the market, or the last order is not placed on the current bar. if (ot==0 || last_order_bar>0)

When Condition N1 and Condition N2 are fulfilled, SEVERAL pending orders are placed simultaneously.

I need only ONE pending order to be placed.

: )) Andrey, you are asking those questions that are already explained in the textbook. Look through the Terminal example in the tutorial, where the principles and logic of how orders need to be considered are described in detail. - Then most of your questions will disappear by themselves. In general, the tutorial is built on the fact that the structure of ANY competent Expert Advisor is completely presented as an example. - This is the beauty of it. + basic theoretical concepts of programming are given. But it has one hitch - it's not intended for the lazy reader - it follows from the structure of what's written. That is, to remove questions on specific points you must read the entire textbook. But few will agree to retell it (the textbook).

You are building piles on the accounting of orders. - You need a simpler approach. The order is either there or not - and it does not matter on what bar (under your conditions) it is open. - Due to these complexities, we get confusion in considering orders and conditions. - Hence, the algorithmic errors, that any programmer should look for. Change the logic of writing the program and the algorithmic errors will disappear (by themselves).

 
OK. Thank you.
 
Arles:

The Expert Advisor only analyses the pair on which it is hovering. On which pair the signal appears first, it opens an order. But sometimes a signal appears on two pairs at the same time. And, strange as it may seem, 2 orders are opened, though there is a check in the Expert Advisor for each open order and it should not open the second one. This is necessary because we have not enough money on the deposit.

This is quite elementary! The first Expert Advisor opens an order. If it doesn't matter which EA opened the order... then create a condition in both of them. Create a Boolean function that finds the last order opened, and respectively extract the time of its opening. Ifthis opening time isequal to the opening of the current bar, we exit the function with TRU. Place the function at the beginning ofthe start and if the mode is TRU, then exit from the start.
 
Chiripaha:

And as for the second question: to be honest, I myself have this question open - I'm not yet completely sure how the terminal reacts when Sleep(1000) function - I also turn to those who know - to give me an answer. Ideally, the terminal at this moment will only process the streaming prices - i.e. it will receive quotes and draw charts and indicators. But while this EA is "waiting", it will not pass its turn to anyone else. - But this is my assumption, of which I am not entirely sure. Perhaps, another exception to this "queue" are scripts that can be launched for execution while the EA is waiting. - I have the same question.

However, I try to get out of this ignorance by building my Expert Advisors based on the correctness of the first point.



As far as I understand, after Sleep() the Expert Advisor simply falls asleep, i.e. its work is paused and at this moment it receives quotes and reacts to nothing. Accordingly, the terminal passes the "queue" to another one.

If anyone disagrees, please correct me!

 
hoz:


As far as I understand, when Sleep() has been processed, the Expert Advisor simply falls asleep, i.e. its work is suspended and at this moment the Expert Advisor receives quotes and reacts to nothing at all. Accordingly, the terminal passes the "queue" to another one.

If anyone disagrees, please correct me!

I am not prepared to agree. - Because from this position the logic of correct work and calculation of both money and positions by Expert Advisors is lost. - This is one. Second. - If my EA is sleeping, for example, for 100 milliseconds, and another one starts working at the same time, then what will happen, that as soon as these 100 milliseconds pass, the other one will have to stop its work... and pass it back to this one in the middle and so on indefinitely... On the other hand. I've seen (not infrequently) in EAs when they send to "sleep" for minutes and many times at each execution block. - Then, if all other owls are not working during this time, it's also somehow wrong. - So the question is quite pertinent. I would like to understand the logic of operation at this point. But I have not come across a detailed explanation in official documents.

But out of two evils I would choose the latter. In this case, I would simply leave the owl that I am sure of. If not, all the same: at least the correctness of recalculations is preserved, although their work is slowed down.

The problem is not as trivial as it seems. - The point is that my experiments have shown that if the"Allow EAs to trade" box is unchecked, then the EA's work does not stop - all calculations are performed the same way on every tick. Just transactions of the EA are not sent to the server. But, if these calculations are filled with these "slips" (not quite correctly), then if there are 5-10 of these EAs, then they specifically can slow the execution of the actual EA that is currently trading.

Yes, some programmers place control over permissions to trade and let the owl work on this basis. But it is not done more often. And if the code is closed, we cannot at all understand whether the operation is braking or not (and which owl exactly). - Now I will poke around this topic on forum search. Something has slowed down.

Thanks to Arles for the question, for reminding me and updating me. I was not experienced enough to understand what was written on the subject. I'll do it again now.

 
Arles:

The Expert Advisor only analyses the pair on which it is hovering. On which pair the signal appears first, it opens an order. But sometimes a signal appears on two pairs at the same time. And, strange as it may seem, 2 orders are opened, though there is a check in the Expert Advisor for each open order and it should not open the second one. This is necessary because we have not enough money on the deposit.

Yes, but when the 1st one has finished its work and opened an order, the 2nd one, having begun to work, does not see for a short time that the order already exists. Or he gets to work before the order opens.
--

One more thing: when the 1st EA Sleep(1000) the second one waits or starts working?

With a small deposit one does not trade on several pairs (worldly advice).

Technically, in order to make different EAs take into account the total number of orders, we may try this scheme:

    int li_total - OrdersTotal();
    if (li_total == 0) Sleep (1000);
    li_total - OrdersTotal();
    if (li_total == 0) OrderSend();

I do not know how well it will work (it should work with 2). It would be safer to do it through global variables of the terminal arranging "Semaphore" working sequentially. Then it does not matter how many Expert Advisors work in parallel.