Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? Order your application from a developer!
Marcelo Coutinho
1103
Marcelo Coutinho 2014.04.23 18:52 

Good Afternoon,

I have an EA with two moving averages triggering an order execution as described below.

The problem I am facing is a delay between the order execution itself and the cross of moving averages.

In this example you see the cross occurred below 205 (past candlestick) but order was sent only @ 205 (coincidentally next candlestick)

Regards,

Marcelo

Files:
Aaronsebaronse
563
Aaronsebaronse 2014.04.23 19:05  
YouTrade:

Good Afternoon,

I have an EA with two moving averages triggering an order execution as described below.

The problem I am facing is a delay between the order execution itself and the cross of moving averages.

In this example you see the cross occurred below 205 (past candlestick) but order was sent only @ 205 (coincidentally next candlestick)

Regards,

Marcelo

Your EA is set to trade on the close of the candle. Hence the first candle close that occurs, meeting the conditions, will determine the trade. The open of that candle in the picture is the close of the previous candle according to the server time(which can leave out huge gaps in price), which was the 1st candle close triggering the MA cross. 
Marcelo Coutinho
1103
Marcelo Coutinho 2014.04.23 19:07  
Thank you ! How can I fix that ? Where can I change it ?
Aaronsebaronse
563
Aaronsebaronse 2014.04.23 19:27  
YouTrade:
Thank you ! How can I fix that ? Where can I change it ?

You cant change it completely, because an EA can only make a trade on the next available price after your conditions have been met. Sometimes the next available price is nearby, sometimes it's miles away. If you want your EA to trade as close to the top of the hour as possible, you would need to construct a dummy candle of 59 minutes and 59 seconds for example, then instruct your EA to trade on the next available price. But even then you are not guaranteed to be filled at that point...you are at the mercy of liquidity/broker. 

 

Save yourself a lot of time and hassle, don't trade crosses on a low time-frame, it doesn't work, it never did, and it never will. 

Marcelo Coutinho
1103
Marcelo Coutinho 2014.04.23 19:41  
Thank you very much !
Rogerio Figurelli
Moderator
37654
Rogerio Figurelli 2014.04.23 20:48  
Aaronsebaronse:
Your EA is set to trade on the close of the candle. Hence the first candle close that occurs, meeting the conditions, will determine the trade. The open of that candle in the picture is the close of the previous candle according to the server time(which can leave out huge gaps in price), which was the 1st candle close triggering the MA cross. 

Hi Aaronsebaronse, can you clarify why the EA is set to trade just on the first candle close?

Note that YouTrade EA is checking moving average at buffer position [0], and tick by tick, so this is not the last moving average from the real time price close value after the last know tick?

Thanks in advance.

Aaronsebaronse
563
Aaronsebaronse 2014.04.23 21:21  
figurelli:

Hi Aaronsebaronse, can you clarify why the EA is set to trade just on the first candle close?

Note that YouTrade EA is checking moving average at buffer position [0], and tick by tick, so this is not the last moving average from the real time price close value after the last know tick?

Thanks in advance.

Hi,

Whoever has coded it for him has probably set it to trade on bar close, regardless of how the MA's are calculated, i think that's just the standard thing to do. Otherwise you are just trading MA crosses on ticks, which is unprofitable to say the least. 

Rogerio Figurelli
Moderator
37654
Rogerio Figurelli 2014.04.23 22:16  
Aaronsebaronse:

Hi,

Whoever has coded it for him has probably set it to trade on bar close, regardless of how the MA's are calculated, i think that's just the standard thing to do. Otherwise you are just trading MA crosses on ticks, which is unprofitable to say the least. 

OK, thanks, just to clarify that the problem can have another root cause, mainly if the EA is trading based on the last tick, and that YouTrade must be aware about that.
Rodrigo Malacarne
Moderator
9763
Rodrigo Malacarne 2014.04.24 11:03  

It should also be interesting to know two things:

1) Is he using any sort of "new bar" event handler?

2) In the case he uses a new bar event handler, how is it written?

The way you write a new bar event handler can definitely affect how and when events occur on MT5.

Rogerio Figurelli
Moderator
37654
Rogerio Figurelli 2014.04.24 15:21  
Malacarne:

It should also be interesting to know two things:

1) Is he using any sort of "new bar" event handler?

2) In the case he uses a new bar event handler, how is it written?

The way you write a new bar event handler can definitely affect how and when events occur on MT5.

Hi Malacarne, the idea here is trade after moving averages crossing in real time, i.e. asap, just using the last tick. In this sense, why you need control the new bar?
Thanks.
Rodrigo Malacarne
Moderator
9763
Rodrigo Malacarne 2014.04.24 15:47  
figurelli:
Hi Malacarne, the idea here is trade after moving averages crossing in real time, i.e. asap, just using the last tick. In this sense, why you need control the new bar?
Thanks.

So, usually how this works in real life?

Do you wait for confirmation of MA crossover, or do you trade directly on tick, even if the bar is not yet closed? As we all know, one single tick is no guarantee that the crossover will actually take place...

That's why we need a new bar event handler...

/ /12
To add comments, please log in or register