Questions from Beginners MQL5 MT5 MetaTrader 5 - page 970

 
Friends. Together we've worked together to write the Expert Advisor algorithm I had in mind,
and thank you very much. You could say we all did it)
It works, the results are as expected and we can move on.
---
Question about testing in OHLC M1 mode.
Is it realistic to program the Expert Advisor so that the test results on OHLC M1 would be close to those on "all ticks"?
I searched the whole forum, there are clear explanations why the OHLC M1 mode with 4 reference points generation does not coincide
with the tick-based modes.

But I have not found any recommendations, examples how to program this condition to be similar to OHLC M1, and is it possible at all?

I like OHLC M1 mode solely because of speed of calculations.
Specifics of the EA. (If it is important)
Sets stop orders with fixed SL and TP, many times it modifies orders at new price levels, waiting for triggering.
There are no indicators, only price counters.
If it is not possible to simulate "OHLC M1" mode, maybe it would be better to use "By opening prices" mode?
In the end, I would like to understand what mode is reasonable to use, so that calculations would be quick and
I'd like to understand what I should use to make calculations fast and to minimize divergence between all-technical modes.

So far I got the following divergence on the same type of settings.

"OHLC M1 ; 8 years; 1681 trades. (initially I used this method)

OHLC M1

"Opening prices" ; 8 years; 1655 trades.

Opening prices only

"All ticks" 8 years; 1676 trades.

all tics

The algorithm seems to be robust, and I may even be able to improve results of each method separately,

but it would lose versatility and appear redundant.




 
vladzeit:


In short, as an example, if you have TP buy positions set at 1.16000, then "all ticks" will close at about this price. OHLC will close at that price above 1.16000 and that can be quite a big difference, so OHLC will always show better results. Same story with "At opening prices".

 
Nauris Zukas:

Briefly, as an example, if TP buy positions are set at 1.16000, "all ticks" will close at approximately this price. OHLC will close at the price that was above 1.16000 this and may be quite a big difference, so always OHLC will show better results. Same story with "At opening prices".

Nauris, thank you. I understand (I can guess) why the results differ from method to method. But what I want to understand is this:

If the tester simulated "OHLC M1" method, then how to repeat the same method in the Expert Advisor programmatically.

The tester reproduced it somehow...

 
vladzeit:

Nauris, thank you. I understand (I can guess) why the results differ from method to method. But what I want to understand is this:

If the tester simulated "OHLC M1" method, then how to repeat the same method in the Expert Advisor programmatically.

The tester has somehow reproduced it...

Trust me, you don't need such precision, optimize the result and run it on all ticks, the best option ...

If you're not 3-4 pips away, it wouldn't make much difference if it closed with two pips more or less...

And playing something in the Expert Advisor won't make your time go faster, but on the contrary, it will take too long...

 
xxz:

Believe me, you don't need such precision, optimize the result and run it on all ticks, the best option ...

If you're not 3-4 pips away, then there's no big difference if you closed with two pips more or less...

Playing something back in the Expert Advisor won't speed up the time, but on the contrary, it will slow it down...

Thank you. If no one will continue the way to implement"OHLC M1" method, I will just be condemned to use your advice)))

 
vladzeit:

Thank you. If no one will continue the method of"OHLC M1" I will be condemned to use your advice))))

If you don't think of a particularly brilliant idea, the difference is in the direction of ticks, in real trading, the ticks may open, bottom, top, close, and if the candle is big, you can buy at the bottom and get a profit by the close, in simulation the candle is formed as open, top, bottom, close, let's say the open and top coincide with the bottom and close too, then on such a candle, you can buy, but not get profit, and if the market has gone down, then here you have a hanging loss order ...

... hence the divergence...

 
vladzeit:

Thank you. If no one continues on how to implement the"OHLC M1" method, I'll just be condemned to take your advice)))

The method speaks for itself. Use only OHLC prices of all minute bars included in the current bar in your EA.
 
vladzeit:

Thank you. If no one continues on how to implement the"OHLC M1" method, I will just be condemned to take your advice)))

Open/close in Expert Advisor not by price levels but by Open. There is an open/close signal, wait for the next 1M candle and open/close.

 
Artyom Trishkin:
The method speaks for itself. Use in your EA only the OHLC prices of all the minute bars included in the current bar.

Artyom, I have tried it. On all conditions, opening and modification of orders I have put a condition "on birth of a new bar" through boolean functionisNewBar()

like this:

if (Buys==true )
   {
   int count_buy_stops=0;   int count_pos_buy=0;
   CalOrders_Buy(count_buy_stops);   CalPosition_Buy(count_pos_buy);
   if(count_buy_stops==0 && count_pos_buy==0) && isNewBar())
   {
   BuyStop();
   }
   }

TheisNewBar() function itselffrom the examples and code.base articles.

bool isNewBar()
  {
//--- в статической переменной будем помнить время открытия последнего бара
   static datetime last_time=0;
//--- текущее время
   datetime lastbar_time=(datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);
   if(last_time==0)//--- если это первый вызов функции
   {
   last_time=lastbar_time;    //--- установим время и выйдем 
   return(false);
   }
   if(last_time!=lastbar_time)//--- если время отличается
   {
   last_time=lastbar_time;    //--- запомним время и вернем true
   return(true);
   }
//--- дошли до этого места - значит бар не новый, вернем false
   return(false);
  }

It seems to work and places orders and modifies them only at a new bar, but for some reason there is a discrepancy.

There is a discrepancy betweenOHLC on M1 which I have applied withoutisNewBar() and "all ticks" withisNewBar() function.

I expected that by applyingisNewBar() on "all ticks" I would get the same result asOHLC on current prices.

So, I do not understand whether I must have screwed up the code or else I do not understand correctly theOHLC modeand expect that it is impossible.

I don't know where to dig.

Artyom, tell me more, if it is not difficult.

The order can be set and modified on a new bar, but SL and TP (in the tester) will work inside the old bar anyway?

 
Tried and failed in trying to convert from fixed lot to percentage lot. Can anyone advise on the full code?
Files:
Experiment.mq5  38 kb
Reason: