Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 112

 
Alexey Kozitsyn:
Can I see the code?
...
extern string   SYMBOLS ="EURUSD,GBPUSD,EURGBP,EURJPY,USDJPY";
string symbolsArray[1];
...
void init(){
   StringToArray(SYMBOLS, symbolsArray);
...
}

int start(){
  Comment(symbolsArray[0]+"|"+symbolsArray[1]+"|"+symbolsArray[2]+"|"+symbolsArray[3]+"|"+symbolsArray[4]);
  //при запуске советника комментарий выводит правильную информацию, но через время один из элементов массива становится равным совсем другому значению
  ...
  return(0);
}

void StringToArray (string stringOfSymbols, string &arrayOfSymbols[]){
...//функция заносит в массив названия торговых инструментов, здесь ошибок нету (проверено)
}
 
Maksym Mudrakov:
...
extern string   SYMBOLS ="EURUSD,GBPUSD,EURGBP,EURJPY,USDJPY";
string symbolsArray[1];
...
void init(){
   StringToArray(SYMBOLS, symbolsArray);
...
}

int start(){
  Comment(symbolsArray[0]+"|"+symbolsArray[1]+"|"+symbolsArray[2]+"|"+symbolsArray[3]+"|"+symbolsArray[4]);
  //при запуске советника комментарий выводит правильную информацию, но через время один из элементов массива становится равным совсем другому значению
  ...
  return(0);
}

void StringToArray (string stringOfSymbols, string &arrayOfSymbols[]){
...//функция заносит в массив названия торговых инструментов, здесь ошибок нету (проверено)
}
The first thing I would do is add #property strict, correct any errors/warnings (if any) and replace init() and start() with OnInit() and OnTick().
 
Alexey Kozitsyn:
The first thing I would do is add #property strict, correct any errors/warnings (if any) and replace init() and start() with OnInit() and OnTick().
Thank you!

Got 5 errors and 83 warnings ))))
 
Maksym Mudrakov:
Thank you!

5 errors and 83 warnings came out ))))
Try to write in a "new" language and there will be fewer hard-to-find mistakes.
 
Alexey Kozitsyn:
Try to write in a "new" language and there will be fewer hard-to-find mistakes.
I came across such a construction in the MQL4 tutorial:

//--------------------------------------------------------------------
start()                    // Специальная функция start()
   {
   while(!IsStopped())     // До тех пор, пока пользователь..
      {                    // ..не прекратит исполнение программы
      RefreshRates();      // Обновление данных
      //......................Здесь указывается основной код программы
      Sleep(5);            // Небольшая пауза
      }
   return;                 // Управление возвращается терминалу
   }
//--------------------------------------------------------------------
Can we use the "new" language as well, or is there a more modern solution?
 
Maksym Mudrakov:
I came across such a construction in the MQL4 tutorial:

//--------------------------------------------------------------------
start()                    // Специальная функция start()
   {
   while(!IsStopped())     // До тех пор, пока пользователь..
      {                    // ..не прекратит исполнение программы
      RefreshRates();      // Обновление данных
      //......................Здесь указывается основной код программы
      Sleep(5);            // Небольшая пауза
      }
   return;                 // Управление возвращается терминалу
   }
//--------------------------------------------------------------------
can it be applied in the "new" language as well, or is there a more modern solution?
Is it in a script or an Expert Advisor?
 
Alexey Kozitsyn:
Is it in the script or in the expert?
In the expert
 
Maksym Mudrakov:
in the examiner.
Um... then it depends on what is going on there in the main code. If sending an order is a bad option!
 
Alexey Kozitsyn:
Um... then it depends on what's going on in the main code. If sending an order is bad!
Yes, sending an order does happen. It is just not clear to me whether the quotes should be updated forcibly, in case the Expert Advisor is running in the window of one trading instrument, but sends an order for another trading instrument. If, for example, the quotes for EURUSD are not updated, and at the same time, the new quotes for GBPUSD are received. And if my Expert Advisor is run on EURUSD, and I don't performRefreshRates(), then the Expert Advisor will not send an order on GBPUSD, until the quotes on EURUSD are updated?
 
Maksym Mudrakov:
Yes, the order is being sent. It is not clear to me if the quotes should be updated forcibly in case the EA is launched in the window of one symbol but sends an order for another symbol. If, for example, the quotes for EURUSD are not updated, and at the same time, the new quotes for GBPUSD are received. And if my Expert Advisor is run on EURUSD, and I don't performRefreshRates(), then the Expert Advisor will not send an order on GBPUSD, until the quotes on EURUSD are updated?

There are several ways to get current prices:

1. For any symbol: if you want to get guaranteed current prices, call SymbolInfoDouble() with the correct identifiers before using them.

2. For the current symbol, you can also get the current prices through the predefined variables Bid and Ask. These can get out of date, so if the OnTick() function is running for a long time, you should refresh them using RefreshRates().

Reason: