Learning and writing together in MQL5 - page 21

 

потому что вы берете каждый раз новое время тика, и оно конечно не равно предыдущему.

In the last function you took the start time of the bar. so here too, take the bar time, not the tick time.

Explain to someone who doesn't understand which parameter in the code to change to which one.

How to describe the bar time, not the tick time?

 
Khomtchenko:

Explain to someone who doesn't understand which parameter in the code to change to which.

How to describe the bar time rather than the tick time?

e.g. https://www.mql5.com/ru/docs/series/copytime
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyTime
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyTime
  • www.mql5.com
Доступ к таймсериям и индикаторам / CopyTime - Документация по MQL5
 
Khomtchenko:

Explain to someone who doesn't understand which parameter in the code to change to which.

How to describe the time of a bar, not a tick?

Here is a popular description of the "new bar" event handler

In general, do not be lazy to sometimes look at articles and code base before asking a question

 

Вот тут все популярно описано Обработчик события "новый бар"

In general, don't be lazy to look at articles and code bases before you ask a question.

Yeah, I looked there. They started for good health and ended up with a bunch of files that do something specific, but I just need a function and that's it. They couldn't give me the code of the final product. They made a mess...
 

In mql4 you could find out in five lines whether the bar was new or not. And now a whole bunch of files have been written, it's not clear where to put them, what to write inside the program...

In short, if there are experts, then give me an example of code, so that I do not suffer, and I can send anyone to the library myself, either to the electronic or real one.

Обработчик события "новый бар"
Обработчик события "новый бар"
  • 2010.10.04
  • Konstantin Gruzdev
  • www.mql5.com
Язык программирования MQL5 позволяет решать задачи на совершенно новом уровне. Даже те задачи, которые уже вроде имеют решения, благодаря объектно-ориентированному программированию могут подняться на качественно новый уровень. В данной статье специально взят простой пример проверки появления нового бара на графике, который был преобразован в достаточно мощный и универсальный инструмент. Какой? Читайте в статье.
 
Khomtchenko:
I don't doubt it, but I'm asking just to check mark - has anyone created one and the same EA in mql4 and mql5 and compared the test results? It should be perfect-similar if the code is properly transformed, shouldn't it? Or am I wrong?

If the testing is paralleled there and in mql5 the logic is placed in onTick, then it will be similar.

The only difference may be in spreads. In 5, the history contains the spreads. In the 4 version, the tester spread is equal to the current spread in the terminal.

If testing "every tick", it looks like it will be even smaller, as the tick generation algorithms are different in the versions.

 
Khomtchenko:

In mql4 you could find out in five lines whether the bar was new or not. And now a whole bunch of files have been written, it is not clear where to put them, what to write inside the program...

In short, if there are experts, then give me an example of code, so that I do not suffer, and I can send anyone to the library myself, either to the electronic or real one.

Here, declare lastbar variable as static or globally, iTime array globally

bool NewBar()
  {

   if(CopyTime(_Symbol,_Period,0,1,iTime)<1)return(false);

   if(lastbar!=iTime[0])
     {
      lastbar=iTime[0]];
      return(true);
     }
   else
     {
      return(false);
     }
  }
 

There is an example on the page with the isNewBar function

https://www.mql5.com/ru/forum/2804/38752#comment_38752

Что меняет режим тестера "только цены открытия"?
Что меняет режим тестера "только цены открытия"?
  • www.mql5.com
Собственно, для советника работающего по onTick, в режиме "Только цены открытия" при тестировании все вычисления индикаторов и вызов функции OnTick() в экспертах происходит только один раз на бар.
 

1. I did not ask for nothing about the results of testing the same strategies on mql4 and mql5.

I used to enter the market on a new bar if the conditions meet the entry requirements and close the position if the indicators show the opposite signal and enter again on a new bar.

On mql4 I used this procedure to enter on a new bar:

void Fun_New_Bar() // Ф-ия обнаружения ..

{ // ... new bar

static datetime New_Time=0; // Time of the current bar

New_Bar=false; // no new bar

if(New_Time!=Time[0]) // Compare times

{

New_Time=Time[0]; // Now the time is

New_Bar=true; // New bar is caught

}

}

This is what the result of testing the robot on mql4 using my strategy looks like:

Testing results of the mql4 EA

Thank you for sending the procedures to determine the new bar. They are working. I made a script that writes Alert on a new bar and tested it on M1 so I didn't wait too long.

But the same strategy gives completely different results (and the same ones) using both procedures in mql5 Expert Advisor:

Testing results of the mql5 advisor

I have not been tearing my shirt and stomping my feet for nothing. I want to repeat the results, but they do not coincide.

Here is what the onStart function in mql4 approximately looks like

int start()

{

GetIns();

Fun_New_Bar();

if (New_Bar==false) return(0);

if (Total()>0)

{

CloseSellEnd();

CloseBuyEnd();

}

if (Total()<1)

{

OpenBuy();

OpenSell();

}

return(0);

}

The same in mlq5:

void OnTick()

{

GetIns();

if (NewBar())

{

if (Total()>0) TryToClose();

if (Total()<1)

{

OpenBuy(Lots,10, "EUR/USD (Buy)",102406);

OpenSell(Lots,10, "EUR/USD (Sell)",102406);

}

}

}

GetIns to process indicator parameters, and Total() - gives the number of positions with the required magic for mql4 or with the required symbol for mql5.

Help.

 

I think I've found the reason for the discrepancy. You won't believe it. The MT4 and MT5 have a different quote history. Seems to be slightly different and the strategy is tested with a huge difference!!!!

Here's one plot on different terminals:

You take a closer look, there is a difference. A small one? And what is the difference between the test results of the strategy, also small???

I will contact the developers! What a beta!!!