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

 
Hi, could you tell me how to make 2 pending buy and sell orders be placed when a new M1 candle is formed?
 
Иван Титов:
Hi, how do I make 2 pending buy and sell orders to be placed when a new M1 candle is formed?

int timeM1=0;

int PlaceOrdersOnM1() {

  datetime candleOpenTime=iTime(Symbol(),_Period,0);

  if (timeM1==0) {

     timeM1=candleOpenTime;

     return 0;

  }

 if (timeM1!=candleOpenTime) {

   timeM1=candleOpenTime;

   int ticket1=OrderSend(...); // выставляет отложку 1

   int ticket2=OrderSend(...);// отложку 2

   return !(ticket1<0 || ticket2<0);

 }

 return 0;

}

// вызывать каждый тик или по таймеру (по вкусу)

written "by hand", never checked in any way

 
Иван Титов:
Hi, could you tell me how to make 2 pending buy and sell orders be placed when a new M1 candlestick is formed?

is the new candle open check function for any TF (very useful)

bool NewBar(ENUM_TIMEFRAMES TF = PERIOD_CURRENT)
  {
   static datetime NewTime=0;
   if(NewTime!=iTime(Symbol(),TF,0))
     {
      NewTime=iTime(Symbol(),TF,0);
      return(true);
     }
   return(false);
  }
 

What does this warning mean in the tester?

2020.02.06 09:55:17.596 TestGenerator: unmatched data error (volume limit 95 at 2020.01.20 08:10 exceeded)

Direct translation is "volume limit 95 exceeded". But what does it mean? There is no volume limit... And other candlesticks (M5) have much bigger volumes, but no warning...
 

Is it possible to create functions where the parameter can be a variable of any type at once?

void Function (any_type A);
 
Viatcheslav Pashkov:

What does this warning mean in the tester?

2020.02.06 09:55:17.596 TestGenerator: unmatched data error (volume limit 95 at 2020.01.20 08:10 exceeded)

Direct translation is "volume limit 95 exceeded". But what does it mean? There is no volume limit... And other candlesticks (M5) have much bigger volumes, but no warning...
Download the history on the symbol. F2
 
Viatcheslav Pashkov:

Is it possible to create functions where the parameter can be a variable of any type at once ?

Yes, the pattern is called

template<typename T>
void Foo(T param){
...
}
 
Vladimir Simakov:

Yeah, the pattern is called

I don't get it.

Read the FAQ.

Still don't get it. Give a simple example between int, double and string please?

 
Viatcheslav Pashkov:

didn't get it.

Read the FAQ.

still do not understand. Give me a simple example between int, double and string please?

https://www.mql5.com/ru/docs/basis/oop/templates

Why put it in the OOP section?

Документация по MQL5: Основы языка / Объектно-ориентированное программирование / Шаблоны функций
Документация по MQL5: Основы языка / Объектно-ориентированное программирование / Шаблоны функций
  • www.mql5.com
Перегруженные функции обычно используются для выполнения похожих операций над различными типами данных. Простой пример такой функции в MQL5 - ArraySize(), которая возвращает размер массива любого типа. На самом деле эта системная функция является перегруженной, и вся реализация такой перегрузки спрятана от разработчика программ на MQL5: То есть...
 
Vladimir Simakov:

https://www.mql5.com/ru/docs/basis/oop/templates

Why did you put it into the OOP section?

that's exactly what I read.

But it must have been written for those who knew but had forgotten.

That information didn't help me one bit.

Can you give me a simple example?

Reason: