[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 30

 
AndrewX:

Please advise how to set the correct check in the position opening condition - whether there is an open position for this instrument or not. And if there is a position for the symbol (any sell or buy), then the opening does not take place, otherwise the signal to open the position is triggered?

Here is the code (I think it is responsible for opening positions):

Seems to be correct in logic, but it does not work still opens several poses on one tool.

P.S. I am not a programmer. If it is possible to explain in more detail to the dummie.


This is not difficult. It is best to organise 2 subprogrammes that count the orders.

// =================================================================================================
// ************************* Счётчики ордеров ******************************************************
// =================================================================================================


//=========== SchBuy()  ===============================
//  Функция возвращает количество Buy-ордеров
//   SchBuy      - счётчик Buy ордеров
//-----------------------------------------------------------
int SchBuy(int MAGIC){
  string SMB=Symbol();
  int SchBuy=0;
  int i;
  for (i=OrdersTotal()-1;i>=0;i--) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {Print("Ошибка № ",GetLastError()," при выборе ордера № ",i);}
    else {
      if(OrderSymbol()!= SMB || OrderMagicNumber()!= MAGIC){ continue;}
      if(OrderType()==OP_BUY){ 
        SchBuy++;
      }  
    }
  }
  return(SchBuy);
}                  
//==================================================================================================


//=========== SchSell()  ===============================
//  Функция возвращает количество Sell-ордеров
//  SchSell  - счётчик Sell ордеров
//-----------------------------------------------------------
int SchSell(int MAGIC){
  string SMB=Symbol();
  int SchSell=0;
  int i;
  for (i=OrdersTotal()-1;i>=0;i--){
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {Print("Ошибка № ",GetLastError()," при выборе ордера № ",i);}
    else {
      if(OrderSymbol()!=SMB || OrderMagicNumber()!=MAGIC){ continue;} 
      if(OrderType()==OP_SELL){
        SchSell++;
      }
    }
  }
 return(SchSell);     
}                  
//==================================================================================================

Further, in the code itself, prich:

if(SchBuy(MAGIC)+SchSell(MAGIC)<=0){
// ордеров нет - устанавливаем ордер при наличии торгового сигнала
}

The MAGIC constant is better declared in user variables. Like this:

extern int      MAGIC=467223; // У ордеров открытых вручную MAGIC=0
 

Tried


if (NumberOfPositions(Symbol_1,-1,Magic)<1

все равно не пашет
 
drknn:


It's not complicated. It is best to organise 2 subprograms that count the orders.

Next, in the code itself, prich:

It is better to declare the MAGIC constant in user variables. Like this:

Thanks, I'll have a look, but it's probably a bit complicated for me.
 
AndrewX:
Thanks, I'll have a look, but it's probably a bit complicated for me.

I've attached an EA file to this post. Have a look at it.
Files:
 
Good morning ! Maybe my question about not optimising is complicated or of no interest ?
 
volshebnik:
Good morning ! Maybe my question about not optimising is complicated or of no interest ?

There are many possible reasons for this. From the trivial - lack of history to the variant - no profitable options. Although it could be simpler - a bug in the Expert Advisor
 

Please tell me if the robot creates pending orders.

Commands for pending orders are sent to the server.

Are the pending orders placed in the queue displayed on the terminal?

The same as if I set pending orders manually? Are the open orders at the top, pending orders at the bottom displayed in the terminal?

 
Jaguar1974:

Please tell me if the robot creates pending orders.

Commands for pending orders are sent to the server.

Are the pending orders placed in the queue displayed on the terminal?

The same as if I set the pending orders manually?


What do you mean by "queued"? The Expert Advisor sends an order to the server to set a pending order. If the parameters of this order are correct, the server sets the pending order and this is immediately displayed in the client terminal. If the Expert Advisor sends an order to place pending orders at a certain step (it is done through a loop), then each new order is processed by the server separately. These orders are placed in queue - Expert Advisor has given an order - server has responded. The Expert Advisor has given an order again and is waiting for the server's reply.

What do orders queued up mean? What do you mean by that?

 
Vinin:

There are many possible reasons for this. From the trivial one - lack of history to the variant - no profitable options. Although it may be simpler - an error in the Expert Advisor.
I checked it and it has the history of Expert Advisors since 1999. I have checked all variants (not profitable too). If I set only one МА parameter, for example from 100 to 110, then optimization "dies" - no results, no chart.... Not to mention the inclusion of other parameters.
 
volshebnik:
I checked - there is a history of minutes from 1999. I checked the checkbox to show all variants (non-profitable ones too). I put even only one MA parameter on optimization, for example from 100 to 110 and all - optimization "dies" - no results, no chart.... Not to mention the inclusion of other parameters.

I have to look at the Expert Advisor. I cannot say anything in this way