Tester different Bar Open price in different testing modes - page 2

Fernando Carreiro
6948
terminalstat: Thank, info is 100%? where did you get it?

Because it is common sense! If you are using only "open price data", you don't have any information on ticks to be able to know what the spread was on the opening tick. You only have the "MqlRates" data available to you and that has an average spread component.

https://www.mql5.com/en/docs/constants/structures/mqlrates

struct MqlRates
  {
   datetime time;         // Period start time
   double   open;         // Open price
   double   high;         // The highest price of the period
   double   low;          // The lowest price of the period
   double   close;        // Close price
   long     tick_volume;  // Tick volume
   int      spread;       // Spread
   long     real_volume;  // Trade volume
  };


Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / History Data Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / History Data Structure
  • www.mql5.com
Constants, Enumerations and Structures / Data Structures / History Data Structure - Reference on algorithmic/automated trading language for MetaTrader 5
terminalstat
139
terminalstat  
Fernando Carreiro:

Because it is common sense! If you are using only "open price data", you don't have any information on ticks to be able to know what the spread was on the opening tick. You only have the "MqlRates" data available to you and that has an average spread component.

Ok, good point. Do you have poof of " has an AVERAGE spread component" some where in docs. Or it's just your thoughts. Nothing personal, I just need to be sure about this. And thank's for helping  me)
Fernando Carreiro
6948
terminalstat: Ok, good point. Do you have poof of " has an AVERAGE spread component" some where in docs. Or it's just your thoughts. Nothing personal, I just need to be sure about this. And thank's for helping  me)

Easy! Look at the documentation about the MqlRates which I provide in previous post and in your code print out the bar's "spread" component and see for yourself.

terminalstat
139
terminalstat  
Fernando Carreiro:

Easy! Look at the documentation about the MqlRates which I provide in previous post and in your code print out the bar's "spread" component and see for yourself.

Exactly, I don't see the word "AVERAGE" for spread. For example I was assuming this spread should be for bar opening price only(exacly as it was at moment of opening), but not for all bar in AVERAGE. Where did you find about average, kindly?
Fernando Carreiro
6948
terminalstat: Exactly, there is no word "AVERAGE" for spread. For example I was assuming this spread should be for bar opening price only(exacly as it was at moment of opening), but not for all bar in AVERAGE. Where did you find about average, kindly?

There is two explanations for this "spread" component in the MqlRates - some defend it is the Maximum spread and some defend that it is the Average.

Irrespective of what it is Average or Maximum, it does not matter, because the only import fact here in your case, is that it is the spread that is used during the Open Price only testing.

So, in order to prove me right (or wrong), update you code to print out that value and compare it to the difference (Ask-Bid). Should it be consistently always the same, then you have confirmed what I stated, and if it is different, then you can state that I am wrong.

So, run the test!

EDIT: Here is supposedly the official information about what the "spread" component represents, namely the "maximum":

Forum on trading, automated trading systems and testing trading strategies

How to calculate spread from ticks

Christoph Stallmann, 2015.04.07 22:23

Service desk reply:

MqlRates stores maximal spread for period.

SymbolInfoInteger() returns current spread.
Alain Verleyen
42593
terminalstat:
Exactly, I don't see the word "AVERAGE" for spread. For example I was assuming this spread should be for bar opening price only(exacly as it was at moment of opening), but not for all bar in AVERAGE. Where did you find about average, kindly?

What is stored in rate spread is not documented and it has already changed in the past. It's also no consistent between different timeframes. (That's last time I checked).

On your backtests you get different ask prices because different spread are used, on Open Prices it's the spread of the bar of the timeframe you used. On Every tick it's the spread of M1 bar (and also on 1 Minute OHLC of course). All these modes are using emulated ticks.

Only on Every tick using real ticks, the tick bid/ask prices are used from history.

Alain Verleyen
42593
Fernando Carreiro:
...

EDIT: Here is supposedly the official information about what the "spread" component represents, namely the "maximum":

I am afraid it's obsolete information. It was not like that the last time I checked (some months ago).

Fernando Carreiro
6948
Alain Verleyen:I am afraid it's obsolete information. It was not like that the last time I checked (some months ago).

That is why I stated "supposedly", because MetaQuotes has yet to declare an official position about this in the documentation. It also seems that brokers use their own rules for this as well.

Fernando Carreiro
6948
terminalstat

some defend it is the Maximum spread and some defend that it is the Average

Who are this "some", ain't there a strict directive in documentation? Do you know this for sure or it's just forum experience. Thank's.

See my previous post as well as @Alain Verleyen's previous posts!

Also, plenty of the information we users use is provided by other users on the forum, because MetaQuotes themselves are not very forthcoming and transparent. Their attitude towards users most of the time, is in my opinion, one of contempt.

terminalstat
139
terminalstat  
Alain Verleyen:

What is stored in rate spread is not documented and it has already changed in the past. It's also no consistent between different timeframes. (That's last time I checked).

On your backtests you get different ask prices because different spread are used, on Open Prices it's the spread of the bar of the timeframe you used. On Every tick it's the spread of M1 bar (and also on 1 Minute OHLC of course). All these modes are using emulated ticks.

Only on Every tick using real ticks, the tick bid/ask prices are used from history.

Thank's, that helped. Just wanted to be sure my code is ok and I'm not crazy, that happens to me))