Why is there always a difference between a signal price and an order price?

 
Dear MQL community,

I have a little problem to solve with MQL, and hopefully someone can provide the good answer, and maybe it helps others because I really can't find a reason and a solution.

So I have developed an expert, and after doing some unit testing the second step has been to test over past data. I have run it over many datasets (days, weeks, periods, symbols) and the programme itself as well as the strategy as a whole show good results, i.e. modest but regularly positive which is what I am looking for as I am just a private beginner trader.

However, after testing it against the market by associating the EA to the different symbols I am interested in, results are very different, showing losses almost always.

Digging into it, it appears that it is not the strategy nor the programme, it is something related to the ways orders are sent to an FX broker. I have been researching, turning around and really can't figure out.

Problem as follows - when focusing at one symbol:

When the EA (whose basis is just a Moving Average expert made of 2 MA indicators that can be configured) detects a Buy, an Order is sent to the broker.
Between the price that the  EA has considered to take the decision and the price at which the broker has taken the order, there is a big difference!
Therefore, most of the time the expert's advice is followed by a position which doesn't make sense. Not very good ;)

I attach 2 snapshots as examples (one with MetaTrader + Oanda, one with MetaTrader + FXCC)




These 2 examples show a Buy order accepted by the broker at far higher price. In the second case, this position was opened at quite a stupid price!

I have tried the following:

- on M5, M15, M30 etc
- with 2 brokers, Oanda and FXCC
- with small slippages of 0 and 1 point
with similar behaviours :(

Would someone be kind enough to explain what I am doing wrong.... or what I ignore about FX orders?

Best regards
 
Chart is Bid, Buy orders are at Ask
 
GumRai: Chart is Bid, Buy orders are at Ask
Turn on the ask line so you can see the spread.
 

Thanks to both of you.

In fact, the above examples were for Buy decisions, but the same happens for Sell's. In other words, if the expert decides to sell based on the Bid line, I also have the same difference between current price and order price, except that for Sell's it's the contrary: the price is far lower. To me, a Sell decision is based on the Bid price; a Buy decision is based on the Ask price. And Ask = Bid + Spread.

Moreover, if I add an MA with period 1 and type = Ask (I don't see how you turn on the ask line), I still see a huge difference between current price and ordered price.

 
gadget:

Thanks to both of you.

In fact, the above examples were for Buy decisions, but the same happens for Sell's. In other words, if the expert decides to sell based on the Bid line, I also have the same difference between current price and order price, except that for Sell's it's the contrary: the price is far lower. To me, a Sell decision is based on the Bid price; a Buy decision is based on the Ask price. And Ask = Bid + Spread.

Moreover, if I add an MA with period 1 and type = Ask (I don't see how you turn on the ask line), I still see a huge difference between current price and ordered price.


Can you please show a screenshot of that ?
 

Salut Angevoyageur,

I did quite some live testing over the last days but got tired with issues which seem to come from Metatrader + MQL, so I haven't kept any further screenshot.

I also have a frequent issue with a Buy or Sell decision raised quite after the moment showed on the graph. Now imagine you're working on M30, the order is placed an hour later, the position already doesn't make sense!

So I 've started to re-write the strategy's core programme in Java which will also go beyond the limited tick-based EA execution in Metatrader.

Reason: