The expert enters long on unexpected price

 

I have made a simple expert advisor with these specifications:

  • It is based on double simple moving average cross, fast=9, slow=21.
  • It should only enter positions on open price of new bars. To achieve this, the modeling type is "Open prices only".
  • It uses the CTrade class to open and close positions.

It works well most of the time.

However, in one instance, the expert enters long at a price other than the open price. A picture is attached below.

Why is this happening?

Files:
 

Forum on trading, automated trading systems and testing trading strategies

Weird positions of backtest orders

Fernando Carreiro, 2023.02.06 17:50

It's called "spread"! There is a Ask price and a Bid price. Charts only shows the bars/candles based on Bid prices.

  • A "buy" position opens at the Ask price and closes at the Bid price.
  • A "sell" position opens at the Bid price and closes at the Ask price.
EDIT: Enable the Ask price line on your chart so that you can track the current value visually.
    Reason: