[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 1114

 
pr0fess0r64


1. We need to remove &&OrderSymbol()==Symbol() from the code.

2. Need to normalise the bid and aska.

3. It's better not to set the slippage at 10 points, but calculate it dynamically. For example, if an order for gold and this instrument transits 50 points per tick, then 10 points of slippage will cause requotes. Therefore it's better to calculate the minimum tick size and multiply it by this 10.

4. You must insert error handling into your code. Otherwise, in case of a failure you will not understand the reasons why orders were not closed.

 
drknn:


1. You should remove &&OrderSymbol()==Symbol() from the code

2. Need to normalise the bid and ask.

3. Slippage is better to calculate dynamically rather than 10 pips. For example, if an order on gold and this instrument moves 50 points per tick, then 10 points of slippage will cause you a lot of requotes. Therefore it's better to calculate the minimum tick size and multiply it by this 10.

4. You must insert error handling into your code. Otherwise, in the case of a failure you will not understand the reasons why orders have not closed

This is the general view, and you can come up with a whole host of details.
 
pr0fess0r64:
Thank you very much, I will try it in the tester, but about the modification of orders do you have any advice?
Are there any errors in the logbook when modifying?
 

Where does return send to?

Clearly, to line 0 and wait for a tick

int start()
  {
//----
   
//----
   return(0);
  }

it's clear here too - stop

   if(Lot_s<=0){
    Alert("Не выбран лот!");
    return;

And here?

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 28.11.2006                                                     |
//|  Описание : Возвращает количество ордеров.                                 |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любой ордер)                    |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
int NumberOfOrders(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersTotal(), ko=0, ot;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      ot=OrderType();
      if (ot>1 && ot<6) {
        if ((OrderSymbol()==sy || sy=="") && (op<0 || ot==op)) {
          if (mn<0 || OrderMagicNumber()==mn) ko++;
        }
      }
    }
  }
  return(ko);
}
The value of the number of orders is ko, so should the next function be written using ko? What does return do here?
 

return() does not send anyone anywhere.

The return operator terminates the current function and returns control to the calling program. The use of return(expression); terminates the current function and sends the result. The operator expression is enclosed in parentheses and must not contain an assignment operator.

 
Vinin:

return() does not send anyone anywhere.

The return operator terminates the current function and returns control to the calling program. The use of return(expression); terminates the current function and sends the result. The operator expression is enclosed in parentheses and must not contain an assignment operator.

Oh, so instead of explicit assignment of ko result, we pass it through return? I think I got it, thanks.
 
How, then, is it correct to stop the EA from working if the conditions are not met? Not to put it to sleep, but to stop it altogether.
 
Abzasc:
How, then, is it correct to stop the EA from working if the conditions are not met? Not to put it to sleep, but to stop it altogether.

What do you mean by "put it to sleep" and what do you mean by "stop"?
 
Vinin:

What do you mean by "put to sleep" and what do you mean by "stop"?

Put to sleep - put sleep, then it will try to start again.

Stop - completely, so that the Expert Advisor stops working (changes its "face").

For example, the Expert Advisor is under Eurobucks, but it was thrown on the EuroJPY. It checks the symbol and in case of a mismatch, it throws the alert and does not try to work anymore before the manual restart.

 
Abzasc:

Put to sleep - put sleep, then it will try to start again.

Stop - completely, so that the Expert Advisor stops working (changes its "face").

For example, the Expert Advisor is under Eurobucks, but it was thrown on the EuroJPY. It checks the symbol and in case of a mismatch, it throws an alert and does not try to work again before the manual restart.


Why so complicated?

It's enough to provide condition handling in start() function

int start(){
  if (Symbol()!="EURUSD") {
     Alert("Советник должен работать только на EURUSD");
     return(0);
  }
  // Далее обработка, принятие решений

}
In this case, if you put the EA on the wrong instrument, you will be flooded with Alerts, until you disable it (the EA) yourself

You can also add a siren sound, then you can turn it off for sure

Reason: