1 (edited by GD 2015-06-24 06:29:36)

Topic: Bar Closing and Bar Opening

Dear Miroslav

I think there is a good chance now to explain how to use

Bar Closing and Bar Opening.

Does "Bar opening" i.e. means "open the trader at the OPEN price"

Or it means

"open the trade at the OPEN price IF the following condition happened"?

Does "Closing Bar" i.e. means "Close the trade at the Close price of this bar"

Or it means

"close the bar at the CLOSE price IF the following conditions happened"?

I think the second  in both cases to do not have ambigous bars

Finally for both cases 4 boxes at least are nesecarry (2 red + 2 green).

Maybe Close at the End of the Bar is not good English

Maybe Close at the End of Bar IF is better.

"IF" should be added where is necessary in all existed Opening and Closing Point indicators except someones who cannot have logic conditions.

One good example is the following

http://s17.postimg.org/3p0c6cal7/2015_06_24.jpg

The strange thing is that in FSB Indicators chart exist many trades but in MT4 testing only ONE happens as it should be. BAR closing Condition does not exist.

This is a bug for FSB. The trades in FSB should not close.

Please check and explain (existance of losses is not important in the example)

Re: Bar Closing and Bar Opening

There are several articles in the User Guide for the strategy structure: Indicator Slots

Reed this texts. If you have any comments or questions, you can use the disquisitions fields below the articles.

There are video lessons for every article.

Re: Bar Closing and Bar Opening

Does "Bar opening" i.e. means "open the trader at the OPEN price"
Or it means
"open the trade at the OPEN price IF the following condition happened"?

It means both.
* If there is no opening logic conditions, it means: Open position at the Open price. (First tick for the bar.) If the market reverses and reaches the Open price later during the bar, it doesn't count as Bar Opening.
  * If there is opening logic conditions, it means: Open position at the Open price IF all the conditions are satisfied.

The strategy behavior explanation is automatically generated and shown in the Overview sub-page.

User guide article: Opening Point of the Position

http://s28.postimg.org/rudy8m1u1/screenshot_1007.jpg

Re: Bar Closing and Bar Opening

Does "Closing Bar" i.e. means "Close the trade at the Close price of this bar"
Or it means
"close the bar at the CLOSE price IF the following conditions happened"?

It can be either of these cases depending on the presence of closing logic conditions.

See the article Closing Point of the Position. There are videos and examples there.

You can see also a textual explanation in the Overview:

http://s28.postimg.org/8qkms9ozt/screenshot_1008.jpg

Re: Bar Closing and Bar Opening

The strange thing is that in FSB Indicators chart exist many trades but in MT4 testing only ONE happens as it should be. BAR closing Condition does not exist.

This is a bug for FSB. The trades in FSB should not close.

Both experts and strategies in FSB must work at the exact same way.


Here is a MT backtest for such strategy:

http://s28.postimg.org/p2uoi03bd/screenshot_1009.jpg

6 (edited by GD 2015-06-24 08:59:49)

Re: Bar Closing and Bar Opening

Dear Miroslav

could you please email me or upload the above example of strategy here using Momentum as it is to help me to check? I mean without closing condition as yours. I cannot see any closing condition to yours.

I receive this  (I use every tick). The same behavior happened with ALF I used at the same way

http://s3.postimg.org/ubhfx43un/image.jpg

http://s4.postimg.org/8e3zaqvdl/image.jpg

In FSB I have many trades like You in MT4
In MT4 only ONE. But YOU HAVE A lot!!!

Maybe we have different files!!!  I do not know. Maybe Some parameter I do not use correctly.

Thanks for all explanation.

Re: Bar Closing and Bar Opening

What do you set for "Bar closing advance in seconds"? MT does not notify the expert that a bar closes, so the expert closes a position at the first tick in the last 15 seconds.

http://s28.postimg.org/9mlplgo21/screenshot_1014.jpg

8 (edited by GD 2015-06-24 10:23:01)

Re: Bar Closing and Bar Opening

It was that

9 (edited by GD 2015-06-24 11:27:12)

Re: Bar Closing and Bar Opening

Dear Miroslav

I understand "Bar closing advance in seconds" that is important in MT4

Is it important also for MT5?

The value for some indicators is important in order to see the EAs working normally

So How to use it correctly in MT4 Tester and MT5 Tester?

Thanks in Advance

Re: Bar Closing and Bar Opening

Is it important also for MT5?

MT4 and MT5 works at the same way. This parameter is important for both platforms at the exactly same way.

So How to use it correctly in MT4 Tester and MT5 Tester?

In the same way as in the trading experts. There is no correct answer because MT4 is absolutely negligent when generates the bar data.
For example, if you trade on M5 chart on 24/5 forex market and you want to close you position at the end of the day. The correct solution would be to send a close order at 23:59:59, but not in the MT case.
If you send the order at that time, the broker's backend may lag and t execute the order on 00:00:15.
Also if the market is slow and there is no ticks, MT will cancel the order because there is no fresh price. What MT means by "fresh price" is questionable. It is different for every broker.

FSB tries to workaround this issue. It uses the "Bar closing advance" parameters. The default value is 15 seconds. It means that when there are 15 seconds left to the theoretical bar closing time, FSB (and EAs) wait for the first tick. When there is a tick in this time interval, the expert sends a close order. The EA also suspend further trading on that bar.

If you make  "Bar closing advance" lower, the EA will close the position more precisely and closer to Close price. However if there is no tick in that interval, the EA will not close the position. The close signal will be resend at the first tick f the next bar.


If you make  "Bar closing advance" higher (lets say 30 seconds), it will be more sure that the market will produce a tick in that interval. The drawback is that the closing will be less precise.

As a rule, you may increase the value if you trade on H1 and longer period. You may decrease the value if you trade on M1 chart and the market is fats. For example if you trade only on the London session on a volatile couple, you may decrease the value. If you close at midnight on H1 or daily chart, you may increase the value.

11 (edited by GD 2015-06-24 12:42:15)

Re: Bar Closing and Bar Opening

These things are very important.

12 (edited by GD 2015-06-24 12:52:15)

Re: Bar Closing and Bar Opening

Dear Mriroslav

Relative to strategy testers what parameter value to use in EAs in order to find same results like FSB during testing?

I found that to receive enough same results in MT4 I need to use large values for this parameter i.e. 999.

Is it Normal? Is there a logic to that? Do I have some problem Or it is normal?

This situation does not happened in MT5. I have this problem only with MT4. MT5 tester works with 15.

Re: Bar Closing and Bar Opening

Now relative to strategy testers what parameter value to use in order to find same results like FSB

The FSB backtester closes the positions at the exact Close price. On the other hand, MT backtester fabricates ticks and times on it's own algorithm. 15 seconds must work well but you can test with other values.

I use numbers like 999 etc. Do I have some problem Or it is normal?

You are the one that do not want limits, so you can try it.
But I definitely would not set anything higher than 30 or 60 (for H1 charts and upper).

Read this carefully: http://forexsb.com/forum/post/30191/#p30191

14 (edited by GD 2015-06-24 13:08:30)

Re: Bar Closing and Bar Opening

Popov wrote:

Now relative to strategy testers what parameter value to use in order to find same results like FSB

The FSB backtester closes the positions at the exact Close price. On the other hand, MT backtester fabricates ticks and times on it's own algorithm. 15 seconds must work well but you can test with other values.

I use numbers like 999 etc. Do I have some problem Or it is normal?

You are the one that do not want limits, so you can try it.
But I definitely would not set anything higher than 30 or 60 (for H1 charts and upper).

Read this carefully: http://forexsb.com/forum/post/30191/#p30191

The behavior depends a lot on this parameter in back testing. The other thing could happened is some problems on some indicators. Not all but some of them.

Re: Bar Closing and Bar Opening

MT4 backtest with default settings.

http://s28.postimg.org/p2uoi03bd/screenshot_1009.jpg

Another one with MT4 and closing at Bar Closing at every bar.


http://s23.postimg.org/h2d90ppev/FSB_Expert_Stress_Test.jpg.

16 (edited by GD 2015-06-24 13:18:56)

Re: Bar Closing and Bar Opening

With the above results we have agreement.

And I just verified them to MT5 also.

The problem can be in the writing of some of the indicators.

Re: Bar Closing and Bar Opening

I experienced this issue on the MT4 backtester. I added a printing status code in the expert to see what is happening and the full beauty of the MT backester shined as a bright sun.

http://s28.postimg.org/8ghpmnzrd/screenshot_1021.jpg

My Bar closing advance parameter is the default 15 seconds, but the problem is other. The shiny MT backtester normally fabricates ticks every 2-3 seconds, but not for the whole bar. There are 37 seconds missing from the end of that bar. And from the next ... and from the next ...

Re: Bar Closing and Bar Opening

I opened a ticked in the MT5 community for that case. MT4 Strategy Tester doesn't generate ticks near to the end of M5 bars

There is no solution so far.

Re: Bar Closing and Bar Opening

It is good that the topic in the MT forum is not deleted. I hope MetaQuotes will comment.

..

Please test your terminal with the attached expert. It prints the time of the previous bar last tick.

string previousRecord = "";

void OnTick()
  {
   string time = TimeToString(TimeCurrent(), TIME_DATE|TIME_MINUTES|TIME_SECONDS);
   string bid = DoubleToString(Bid,_Digits);
   string ask = DoubleToString(Ask,_Digits);
   if(Volume[0] == 1)
      Print(previousRecord);
   previousRecord = "TimeCurrent: " + time + ", Bid: " + bid + ", Ask: " + ask;
  }

On my ActiveTrades terminal the last ticks are either at xx:35 or at xx:25 +- 1 second for EURUSD M5 and M15.

http://s28.postimg.org/rqtbjub49/screenshot_1027.jpg

Post's attachments

PrintTimeCurrent.mq4 368 b, 3 downloads since 2015-06-29 

You don't have the permssions to download the attachments of this post.

20

Re: Bar Closing and Bar Opening

In MT5 the things work better but in MT4, inside one bar trading gave me hard time

I will test it and answer you soon cause today things go wrong...

Re: Bar Closing and Bar Opening

Case development:

Alain Verleyen - a MQL5 moderator with 19000 post said:

Which pitfalls are you talking about ? MT4 or MT5 ? They are NOT the same. Please don't mix MT4 and MT5

Hmm. Of course they are not the same, but we expect both MT4 and MT5 to work, trade and test at the exactly same way.  I assume he has an internal info to the subject. Well, we have been warned.

The Strategy Tester will NEVER by accurate, no matter which algorithm is used.

He stressed on the world never. I'm sure he doesn't understand the backtesting theory well enough or he knows something more for the MT backtester.

Of course, there are cases where a backtester is not correct. That's why FSB shows ambiguous bars. However, there are many cases where a backtester should work fine. It depends on the backtesting algo and the strategy structure. A a backtester should never show an overestimated result.

It seams I have to make a series of seminars or videos on the bakctesting theory and the best way to apply it in the practice.

Mr. Verleyen stated also that:

If you use TimeCurrent(), that will give you the time of the tick.

Unfortunately, it doesn't work.

I finally wrote directly to the MT development team. I hope they will fix the issue or at least they will comment the case.

By mean time, I'm not going to wait for their response and think to workaround the issue by myself.
You can expect a new version of our expert code in 2-3 days.

22 (edited by GD 2015-06-30 06:05:47)

Re: Bar Closing and Bar Opening

That is why I had problems with Advanced Time in some cases.
MT5 worked better but MT4 was a problem
I had to use big time to see same results, which of course was not normal.

I could not believe what I saw and finally you came to discover a big problem in MT4.

I hope to find time to think on it.

http://s28.postimg.org/sl9xz938p/2015_06_30.jpg

Real events look to be like that.

If we want to apply classic analysis then we have to use our own definition of bars.

MT4 and MT5 cannot make that...

The other way is to find a sophisticated approximation.

Re: Bar Closing and Bar Opening

Popov wrote:

By mean time, I'm not going to wait for their response and think to workaround the issue by myself.
You can expect a new version of our expert code in 2-3 days.

Even though I'm in fever, do I get you right you are going to "fix" backtesting issues in MT?

Re: Bar Closing and Bar Opening

do I get you right you are going to "fix" backtesting issues in MT?

I cannot entirely fix it, but I can workaround it to make the backtest acceptable.
Actually, I'm ready and testing now the new script.

The idea is simple.
1. Normally the Bar Closing sends the close signal at the first tick XXX seconds before the theoretical end of a bar, where XXX is the number of seconds you set on EA Input form on startup.
2. When a new bar starts, the EA checks if the strategy uses Bar Closing (Day Closing, ....) and if there is an open position. If it is true, the EA proceeds with the closing procedure in the same way as if it was the last tick. We may think for it as sending the close order at Bar Open, if it was not executed on Bar Closing.
3. If a missed close order was executed at Bar Open, the expert checks if the strategy opens a position at Bar Open. If it is true, the EA checks if the position entry rules are satisfied and send the entry order at the same tick.

As a result of that changes, the EA sends a missed closing order at the Bar Open without missing the next entry. Other benefit is that we can reduce the closing time advance to 5-6 seconds for fast markets in order to improve the closing precision.

Now I'm testing it with closing time 1 sec on a demo and on backtest and it works fine.

It is possible to have a Gap between the Open and the Close price. However, if there were no ticks in the last seconds and the closing was not activated, it means that the market is very slow and an eventual gap will be minimal.

Re: Bar Closing and Bar Opening

Popov wrote:

do I get you right you are going to "fix" backtesting issues in MT?

I cannot entirely fix it, but I can workaround it to make the backtest acceptable.
Actually, I'm ready and testing now the new script.

The idea is simple.
1. Normally the Bar Closing sends the close signal at the first tick XXX seconds before the theoretical end of a bar, where XXX is the number of seconds you set on EA Input form on startup.
2. When a new bar starts, the EA checks if the strategy uses Bar Closing (Day Closing, ....) and if there is an open position. If it is true, the EA proceeds with the closing procedure in the same way as if it was the last tick. We may think for it as sending the close order at Bar Open, if it was not executed on Bar Closing.
3. If a missed close order was executed at Bar Open, the expert checks if the strategy opens a position at Bar Open. If it is true, the EA checks if the position entry rules are satisfied and send the entry order at the same tick.

As a result of that changes, the EA sends a missed closing order at the Bar Open without missing the next entry. Other benefit is that we can reduce the closing time advance to 5-6 seconds for fast markets in order to improve the closing precision.

Now I'm testing it with closing time 1 sec on a demo and on backtest and it works fine.

It is possible to have a Gap between the Open and the Close price. However, if there were no ticks in the last seconds and the closing was not activated, it means that the market is very slow and an eventual gap will be minimal.

Seems like a waste of resource, why focus on MT backtest when FSB offers all we need?