molanis.com/forum - Tools for MetaTrader : The place to ask about the best expert advisor builder, expert advisor downloads, and expert advisor programming

AFTER YOU REGISTER SEND US AN EMAIL TO ACTIVATE YOUR ACCOUNT - Before posting:-1- Please read the user guide -2- Try the examples -3- Search in the forum
It is currently Sat May 11, 2024 3:45 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Time Block
PostPosted: Sat May 12, 2012 8:06 pm 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
Hello Support,

Can you please post a clear example showing how to use the Time block in the following manner:

Monday:
-Open any position on or after 00:00
-Close all positions at 23:57

Tuesday:
-Open any position on or after 00:00
-Close all positions at 23:57

Wednesday:
-Open any position on or after 00:00
-Close all positions at 23:57

Thursday:
-Open any position on or after 00:00
-Close all positions at 23:57

Friday:
-Open any position on or after 00:00
-Close all positions at 19:57


When the Start block function "Trading Time Filter" = "On" and "Action before/after Trading Hours" = "Close All Open Positions," the EA does not close all open positions at the time specified. The EA simply ignores the "Action before/after Trading Hours" function when set to "Close All Open Positions."

When the Start block function "Trading Time Filter" = "Off" and I try to use the Time block to set the EA schedule as posted above, the EA once again, ignores all Ending Trading Hours settings and will not close all trades at the designated time.

I've read the manual on using the Time block and the instructions don't seem to match my requirements. I've tried turning On and Off, the Start block time filter and then using a Time block with each day set to the above schedule, but again, the EA seems to ignore the Ending Trading Hours settings.

The connection path was set to: Start block >>> Time block >>> AND >>> BUY >>> End. I've tried this with the Start block's "Trading Time Filter" = "On" and "Off," with the "Action before/after Trading Hours" = "Close All Open Positions."

The .mol attached attempts to use the exact method found in the Strategy Builder User Guide on page 24 and 25, which reads as follows:

"For time filters you have 3 options:

1. You use the START icon
2. You use a TIME icon
3. You use both

For 1) In the START icon you define a time filter for the whole ea. The ea works if the server time is in the time filter (between X hour and Y hour). The START icon has an option that you can set to close all positions when trading time is out of the time filter (before X and after Y). Again this applies to the
whole expert advisor.
"

Note: the above instructions on pages 24/25 do not seem to work in my version of Molanis.


This config shows what the instructions on pages 24 and 25 outline. Yet, "Action before/after Trading Hours" = "Close All Open Positions," does not result in any trade being closed, regardless of the Ending Time used:
Image

I also tried using the Time block and the CL block combination, connecting Start to Time, and then Time to Cl, and then CL to End. That DOES close the open trade, but it closes the trade instantly (immediately) after the trade is opened, not at 23:59 as the Time block is configured.

I need open all open positions closed precisely three (3) minutes before the end of each trading session Monday through Thursday, and at 19:53 on Friday's trading session.

Thanks for your help on this.

Regards,
cfx


Top
 Profile  
 
 Post subject: Re: Time Block
PostPosted: Sat May 12, 2012 10:52 pm 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
After having run through every possible Time block combination and configuration that I could think of, without success, I decided to try using an MQL block coupled to a CL icon:

Image

This worked. I was able to somehow figure out the MQL that was needed to get the MQL block to perform like a Time block and the trade closed right on schedule as the Journal entry shows:

2012.05.12 20:37:37 2009.06.01 23:57 EA_Saturn_V1.1_M1_MTF GBPUSD,M1: M-Order Closed. Symbol:GBPUSD. Lots:0.1. Ticket number:1. Closed at price:1.6438. Position was opened at price:1.624 Profit:198

I'm not a programmer and I certainly don't know MQL well enough to code an indicator, let along an EA. However, I have to find a way to use MQL on several occasions now as something of a work-around to get me EAs to behave according to their design.

I don't think that in this case, I should have needed to do that. I think there might be something going on with the Time block. At the same time, I don't see a lot of posts from other people regarding the same problems that I had - so that makes me wonder if I used the Time block incorrectly, or not.

This is the coded MQL block that I came up with for firing off the CL/CS at a specific Time:

Image


This is the coded I came up with for use inside an MQL block, to fire off the CL/CS on a specific Day (Friday) and at a specific Time:

DayOfWeek() == 5 && TimeHour(TimeCurrent()) == 19 && TimeMinute(TimeCurrent()) == 50


Of course, doing it this way, required two separate MQL blocks. One closing positions on Time, and one for closing positions on Day and Time:

Image

The EA runs fine and all sessions end with all open trades being closed out. However, if you see any problems with using the MQL block in this way to control the timing of trade execution, please alert me to any such issues that I might be overlooking. Thus far, things seem to be running smoothly without the Time block.


Thanks for the help!
cfx


Top
 Profile  
 
 Post subject: Re: Time Block
PostPosted: Mon May 14, 2012 9:16 am 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Quote:
For 1) In the START icon you define a time filter for the whole ea. The ea works if the server time is in the time filter (between X hour and Y hour). The START icon has an option that you can set to close all positions when trading time is out of the time filter (before X and after Y). Again this applies to the
whole expert advisor."


This is the way it works. Do not do from 0 to 24 since it relates to hours so 0=24 (the option in the START icon does not have a day component - the time icon has day option). Try 1 to 23.

Quote:
I need open all open positions closed precisely three (3) minutes before the end of each trading session Monday through Thursday, and at 19:53 on Friday's trading session.
You need to use the time icon. You need one logic to close the positions and another to make sure position are opened before the closing time. Since you need 19:53 just remember that the ea is executed every bar or every tick, to get 19:53 every tick is recommended.

Using the mql icon seems fine. Instead of using = minute, I would use >= just in case you don't get ticks in that minute


Top
 Profile  
 
 Post subject: Re: Time Block
PostPosted: Mon May 14, 2012 5:06 pm 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
molanisfx wrote:
This is the way it works. Do not do from 0 to 24 since it relates to hours so 0=24 (the option in the START icon does not have a day component - the time icon has day option). Try 1 to 23.


Yes, I noticed before that 0000hrs is the same as 2400hrs, but I was left with no other options in Molanis. I need to control the close down to the Minute and the closest that Molanis could get me was 2300hrs. That's a full 57 before I needed to close the position. So, the precision is simply not available when you use the Start icon, if you need tighter control.

molanisfx wrote:
You need one logic to close the positions and another to make sure position are opened before the closing time. Since you need 19:53 just remember that the ea is executed every bar or every tick, to get 19:53 every tick is recommended.


But, if I use just one (1) MQL block, I get the same net effect at 19:53, without the need for two structural components (one to close and one to check for open positions prior to close). Is there anyway you can design the Time function to run the check internally/automatically before closing the position? This would seem to fit the point-and-click model of Molanis as well.


molanisfx wrote:
Using the mql icon seems fine. Instead of using = minute, I would use >= just in case you don't get ticks in that minute


Absolute, thanks for reminding me! Using ">=" does make more sense for the reason you just stated.

Now, that I know the code snippet for controlling the time of the execution, I feel more comfortable using the MQL block, as it allows me to customize such control to a tighter specification. I can now include other logic that is related to Time, into the same MQL custom time block. This opens the door for some more creative thought.

Thanks or the help and thanks for including the MQL Blocks into Molanis! The MQL blocks have saved my bacon on more than one occasion and given me work-arounds that I otherwise would not have available to me.

It would be really, really, really nice and proper, if you could call an MQL block from within a TA+ block. Please keep that in mind for EAs that are a bit more complex than the simple cross-over designs.

Thank you,
cfx


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by Molanis © 2009