Discussion of article "Cross-Platform Expert Advisor: Time Filters"

 

New article Cross-Platform Expert Advisor: Time Filters has been published:

This article discusses the implementation of various methods of time filtering a cross-platform expert advisor. The time filter classes are responsible for checking whether or not a given time falls under a certain time configuration setting.

For filtering by days, the filtering by days parameter is set to true. Also, the filtering by date range remains enabled, but with the Friday parameter is disabled. The last trade from the previous test shows that the last trade entered was on 01/06 (Friday). Thus, if we see that this trade was no longer entered on the test, we can confirm that this particular time filter to be working. The test result is also shown at the bottom of this article (tester_time_days.html). A screen shot of the last trade is shown below:

time days last trade

Author: Enrico Lambino

 

Hi,

Thanks for sharing this great solution.

Could you explain how do I set  SL/TP when sending an order? That's what I found in COrderManager::TradeOpen :

ret=SendOrder(type,lotsize,price,0,0);

Looks like SL/TP are always set to 0. How do I change that? Any other method must be used to send order with SL or TP?

 

That's really weird.. Published so many articles and none of them explains how to use SL, TP. Why do I need these time filters if I don't know how to set SL for my position?

Can you please share at least some piece of code demonstrating stops usage until the corresponding article is issued? Thanks.

 

Any method for getting open time of trade/position?

 
Hi mbjen,
mbjen:

Hi,

Thanks for sharing this great solution.

Could you explain how do I set  SL/TP when sending an order? That's what I found in COrderManager::TradeOpen :

Looks like SL/TP are always set to 0. How do I change that? Any other method must be used to send order with SL or TP?

mbjen:

That's really weird.. Published so many articles and none of them explains how to use SL, TP. Why do I need these time filters if I don't know how to set SL for my position?

Can you please share at least some piece of code demonstrating stops usage until the corresponding article is issued? Thanks.

To be honest, it's not that easy to implement. See Cross-Platform Expert Advisor: Stops.


mbjen:

Any method for getting open time of trade/position?

In MQL5, you can get it from either COrderInfo or CPositionInfo, but this also depends if you are using netting or hedging mode. For example, I may be wrong, but as far as I know, if you reverse a position in netting mode, you still get the open time of the original position, not the time when you reversed it. So I think tracking the order that generated the position is much better. For the MQL4 version, I think you are already aware of this.

 
Enrico Lambino:

In MQL5, you can get it from either COrderInfo or CPositionInfo, but this also depends if you are using netting or hedging mode. For example, I may be wrong, but as far as I know, if you reverse a position in netting mode, you still get the open time of the original position, not the time when you reversed it. So I think tracking the order that generated the position is much better. For the MQL4 version, I think you are already aware of this.


Yes, I'm aware of it. But in this case the code will be different for MT4 and MT5 versions... It won't be fully cross-platform. Are you going to implement any solution for that? 

upd. Anyway this is not a big deal. I can use #ifdef command for that.

Also, can you please advise how do I add a time filter to close all trades before end of day on Friday

I mean I know how to close. I didn't fully get how to add a filter including both time range filter and day filter? How do I add different time ranges for specific days of week?

 
MetaQuotes Software Corp.:

New article Cross-Platform Expert Advisor: Time Filters has been published:

Author: Enrico Lambino

Thank you for your work its been enlightening. Its saved me days of work. Please write more!!