Wrong prices when trades open MQL5 - page 3

 
RiccardoBorello01 #: The virtual ticks are the ones obtained by setting the modeling to "every tick", right? In this case I did everything and I noticed that obviously the trades are different between virtual ticks and real ticks, but the problem is still present in both cases

Don't just say that the problem persists. That helps no one.

Show the log entries of the very first trade in both cases, "Every tick" and "Every tick based on real ticks".

Show log entries of the very first trade for "floating" spread, for 100 points and for 1000 points, both for virtual ticks and real ticks.

In total you will need to show the log entries of the first trade for 6 variations as described above.

 
Fernando Carreiro #:

Don't just say that the problem persists. That helps no one.

Show the log entries of the very first trade in both cases, "Every tick" and "Every tick based on real ticks".

Show log entries of the very first trade for "floating" spread, for 100 points and for 1000 points, both for virtual ticks and real ticks.

In total you will need to show the log entries of the first trade for 6 variations as described above.

Here are all the logs

 
RiccardoBorello01 #: Here are all the logs

Your EA code seems inconsistent and maybe has a few bugs. So I decided to code a very simple simple EA to print out to the log, the bid and ask prices for the very first tick it gets.

void OnTick()
{
   static bool bFirstTick = true;
   if( bFirstTick )
   {
      MqlTick oTick;
      if( SymbolInfoTick( _Symbol, oTick ) )
      {
         PrintFormat("Ask: %s, Bid: %s, Spread: %s",
            DoubleToString( oTick.ask, _Digits ), DoubleToString( oTick.bid, _Digits ),
            DoubleToString( oTick.ask - oTick.bid, _Digits ) );
         bFirstTick = false;
      };
   };
};



Here are my results for build 3320:

  • Floating spread:


Spread: Floating, Modelling: Every tick
2022.06.26 14:14:21.819 Core 1  2022.06.01 00:05:30   Ask: 0.95956, Bid: 0.95877, Spread: 0.00079

Spread: Floating, Modelling: Every tick based on real ticks
2022.06.26 14:15:04.781 Core 1  2022.06.01 00:05:28   Ask: 0.95956, Bid: 0.95877, Spread: 0.00079
  • 100 point spread:

Spread: 100 points, Modelling: Every tick
2022.06.26 14:20:06.898 Core 1  2022.06.01 00:05:30   Ask: 0.95977, Bid: 0.95877, Spread: 0.00100

Spread: 100 points: Every tick based on real ticks
2022.06.26 14:21:04.329 Core 1  2022.06.01 00:05:28   Ask: 0.95956, Bid: 0.95877, Spread: 0.00079
  • For 1000 points

Spread: 1000 points, Modelling: Every tick
2022.06.26 14:28:25.311 Core 1  2022.06.01 00:05:30   Ask: 0.96877, Bid: 0.95877, Spread: 0.01000

Spread: 1000 points: Every tick based on real ticks
2022.06.26 14:29:15.393 Core 1  2022.06.01 00:05:28   Ask: 0.95956, Bid: 0.95877, Spread: 0.00079


Observations:

I noticed that for USDCHF, when using real tick data, the spread was not changed. Only the virtual ticks functioned correctly.

So I decide to test EURUSD has I had tested before, and to my surprise my previous demonstration no longer worked. It failed for "real ticks" but worked correctly for virtual ticks.

I tried deleting cache files, log files, metatester config files and restarting MetaTrader, but the results were the same. I was not able to reproduce my original test where the spread worked correctly for real ticks.


Conclusion:

The OP is undeed correct, that when using real ticks, a change in spread of the contract specification for the tested symbol, does not have any effect. It only seems to work on virtual ticks.

I do not know if this is a bug, a new "feature" or if this has always been like this and I was just not paying attention. However, what troubles me is that when I did the initial test for the OP on the very first time for post #13 I had it working correctly.


Note to other users, moderators and admin:

With the provided code and log results, can others please carry out the test to see if they can confirm the situation or provide further information on the subject.

 

I ran a search on the forum and also found this thread that should maybe be of relevance:

Forum on trading, automated trading systems and testing trading strategies

Problem in changing the spread in the strategy tester of MT5

Hadi Hadizadeh, 2021.11.01 21:30

Hi,

I want to test my expert advisor in the strategy tester of MT5. However, when backtesting on any Forex instruments, I always get a fixed spread of 50. I tried to change the spread of the symbol but it seems that the strategy tester always uses a spread of 50. Do you know what is wrong? Thanks.

Forum on trading, automated trading systems and testing trading strategies

Problem in changing the spread in the strategy tester of MT5

Eleni Anna Branou, 2021.11.01 21:40

You can't adjust MT5 strategy tester's spread, because it downloads tick data from your broker server so you have the real spread from the bid/ask prices.

 
Fernando Carreiro #:

I ran a search on the forum and also found this thread that should maybe be of relevance:

thanks for your time. So as a solution I exported the data from mt4 (where my EA works fine) and I imported them on a custom symbol on mt5 and now I can change the spread correctly. The only problem is that those aren't very reliable, so maybe it's best to download them from external sources and then import them to mt5

 
RiccardoBorello01 #: thanks for your time. So as a solution I exported the data from mt4 (where my EA works fine) and I imported them on a custom symbol on mt5 and now I can change the spread correctly. The only problem is that those aren't very reliable, so maybe it's best to download them from external sources and then import them to mt5

Why import from MT4 when you can more easily just create the CustomSymbol from the MT5 data itself, and adjust the spread.

That will provide a more consistent test between the normal data and the spread adjusted data.

 
Fernando Carreiro #:

Why import from MT4 when you can more easily just create the CustomSymbol from the MT5 data itself, and adjust the spread.

That will provide a more consistent test between the normal data and the spread adjusted data.

I tried to create the custom symbol using mt5 data but the situation was the same as the normal symbol, because the bars I imported each already had their own spread

 
RiccardoBorello01 #: I tried to create the custom symbol using mt5 data but the situation was the same as the normal symbol, because the bars I imported each already had their own spread

But you can change that spread. That is why it is a Custom Symbol. You can make whatever changes you want. Just set your code that generates the Custom Symbol, to change the quote prices as you need.

 
Fernando Carreiro #:

But you can change that spread. That is why it is a Custom Symbol. You can make whatever changes you want. Just set your code that generates the Custom Symbol, to change the quote prices as you need.

How can I do that? Do I have to export the ticks from a normal symbol and import them into a custom symbol?

 
RiccardoBorello01 #: How can I do that? Do I have to export the ticks from a normal symbol and import them into a custom symbol?

You have to build that logic into your code, using the CustomTicksAdd with an MqlTick array of data, where the ask prices of that array have been changed.