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 Fri May 10, 2024 1:49 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Problem with Time() Functions
PostPosted: Wed May 30, 2012 12:18 am 
Offline

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

I'm running this code through an MQL block and then out to a CL and CS to close trades:

Day() == 1 || Day() == 2 || Day() == 3 || Day() == 4 && TimeHour(TimeCurrent()) >=23 && TimeMinute(TimeCurrent()) >=57 || Day() == 5 && TimeHour(TimeCurrent()) >=21 && TimeMinute(TimeCurrent()) >=57

The problem is that all trades remain open Monday through Thursday, through 23:57. Also, all trades remain open on Friday, through 21:57.

I'm running this code through an MQL block to open trades:

TimeHour(TimeCurrent()) == 00 && TimeMinute(TimeCurrent()) <= 05

The only trade that opens between 00:00 and 00:05, is the very first trade of the back-test, when clicking on the Tester Start button. That trade opens precisely at 00:00. However, none of the other trades open between 00:00 and 00:05, later in the week.

In summary:

- One trade opens after clicking on the Tester Start button at 00:00.
- No trade is ever subsequently closed at 23:57 (M-Thu), or 21:57 (Fri).
- No trade is ever then subsequently opened between 00:00 through 00:05.

All times shown above had ample available tick flow. So, there were no gaps in the test data.

Any help would be appreciated.

Thanks.
cfx


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 1:13 am 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
I went back to try to use the Time blocks once again without success.

I simply tried to use the Time block to close trades, by connecting it to the CL and CS functions.

Example Diagram Connections:
Start >>>> Time >>>> CL
Start >>>> Time >>>> CS

Image

I tried this with the Start's Trading Time Filter set to ON, and then OFF. Each Time block has its trading hours set to Monday through Thursday: Start Trading Hours 00, Start Trading Minutes 00, End Trading Hours 23, and End Trading Minutes 57.

After clicking on the Tester's Start button, the first trade is opened at 00:00, and then immediately closed.

I've had this kind of difficulty with using Time in Molanis before, where either the EA simply ignores my MQL Time based code, or incorrectly closes trades where clearly the End Trading Hours setting gets ignored (23:57).

Can you post a razor clear example of how to use the Time blocks in Molanis? I've tried all manner of configurations and none of them have resulted in consistent Opening and Closing of trades on time.

Thank you!
cfx


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 8:52 am 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
You mentioned that does not work but have not mention what you want to do. When do you want to open and close the trades?


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 1:28 pm 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
molanisfx wrote:
You mentioned that does not work but have not mention what you want to do. When do you want to open and close the trades?


Previously:
cfx wrote:
I'm running this code through an MQL block and then out to a CL and CS to close trades:

Day() == 1 || Day() == 2 || Day() == 3 || Day() == 4 && TimeHour(TimeCurrent()) >=23 && TimeMinute(TimeCurrent()) >=57 || Day() == 5 && TimeHour(TimeCurrent()) >=21 && TimeMinute(TimeCurrent()) >=57

The problem is that all trades remain open Monday through Thursday, through 23:57. Also, all trades remain open on Friday, through 21:57.

I'm running this code through an MQL block to open trades:

TimeHour(TimeCurrent()) == 00 && TimeMinute(TimeCurrent()) <= 05



Thanks.
cfx


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 2:49 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Sorry, I still do not get it.
Quote:
The problem is that all trades remain open Monday through Thursday, through 23:57. Also, all trades remain open on Friday, through 21:57.

Do you want to close the trades when? on thursday? on friday? At what time?


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 3:25 pm 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
molanisfx wrote:
Do you want to close the trades when? on thursday? on friday? At what time?


Sorry, I thought the answer to your question was provided in the code that I posted.

The above code attempts to:

Close the position Monday through Thursday, at 23:57.
Close the position on Friday, at 21:57.
Open the position Monday through Friday, between 00:00 through 00:05.

This is the MQL block connected to a Buy icon with the Time() function up front:

TimeHour(TimeCurrent()) == 00 && TimeMinute(TimeCurrent()) <= 05 && ((((iCustom(Symbol(),PERIOD_M1,"iCustom", true,0,0) + iCustom(Symbol(),PERIOD_M1,"iCustom", true,1,0)) / 2) + ((iCustom(Symbol(),PERIOD_M5,"iCustom", true,0,0) + iCustom(Symbol(),PERIOD_M5,"iCustom", true,1,0)) / 2) + ((iCustom(Symbol(),PERIOD_M15,"iCustom", true,0,0) + iCustom(Symbol(),PERIOD_M15,"iCustom", true,1,0)) / 2) + ((iCustom(Symbol(),PERIOD_M30,"iCustom", true,0,0) + iCustom(Symbol(),PERIOD_M30,"iCustom", true,1,0)) / 2) + ((iCustom(Symbol(),PERIOD_H1,"iCustom", true,0,0) + iCustom(Symbol(),PERIOD_H1,"iCustom", true,1,0)) / 2) + ((iCustom(Symbol(),PERIOD_H4,"iCustom", true,0,0) + iCustom(Symbol(),PERIOD_H4,"iCustom", true,1,0)) / 2) + ((iCustom(Symbol(),PERIOD_D1,"iCustom", true,0,0) + iCustom(Symbol(),PERIOD_D1,"iCustom", true,1,0)) / 2)) / 7) > 50


This is the MQL block connected to a CL icon:

Day() == 1 || Day() == 2 || Day() == 3 || Day() == 4 && TimeHour(TimeCurrent()) >=23 && TimeMinute(TimeCurrent()) >=57 || Day() == 5 && TimeHour(TimeCurrent()) >=21 && TimeMinute(TimeCurrent()) >=57

The Buy code works only once (when you click the Tester Start button for the first time). The Close code never works at all. Subsequently, no Buy code ever works after the first trade.

Thanks.
cfx


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 4:05 pm 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
In trying to solve the problem above, I removed the following from the Buy side MQL block:

TimeMinute(TimeCurrent()) <= 05

Doing this caused the Close side MQL block to work. The trade closes at 23:57, which is correct. However, the next trade does not open at 00:00, as the Buy side MQL block requires.

So, this worked on the close side using the CL icon:

Day() == 1 || Day() == 2 || Day() == 3 || Day() == 4 && TimeHour(TimeCurrent()) >=23 && TimeMinute(TimeCurrent()) >=57 || Day() == 5 && TimeHour(TimeCurrent()) >=21 && TimeMinute(TimeCurrent()) >=57

But, this still does not work on the buy side using the Buy icon - AFTER - the first trade (only the very first trade works when starting Tester):

TimeHour(TimeCurrent()) == 00

Thanks.
cfx


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 4:12 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Code:
Close the position Monday through Thursday, at 23:57.
Close the position on Friday, at 21:57.
Open the position Monday through Friday, between 00:00 through 00:05.


You cannot do it with the start icon since it does not have minutes. You need to use the time icons.
-Use one time icon for the open.
-Use one time icon for the Friday's close.
-Use one time icon for the Monday to Thursday's close .


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 4:38 pm 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
A picture to help visualize the problem:

Image

- Friday's close time not recognized by EA
- New trade open time not recognized by EA
- Several trade executions well after trade evaluation time

Something is not quite right, but I don't know what.

Thanks.
cfx


Top
 Profile  
 
 Post subject: Re: Problem with Time() Functions
PostPosted: Wed May 30, 2012 4:51 pm 
Offline

Joined: Wed Mar 14, 2012 12:31 am
Posts: 118
molanisfx wrote:
You cannot do it with the start icon since it does not have minutes. You need to use the time icons.


I know that. I only tried using the Start icon as a sanity check (only) - not as matter of protocol. I did it merely to see what would happen, in light of the MQL code not being recognized.

molanisfx wrote:
-Use one time icon for the open.


The Time function in Molanis has field settings for Start Hour, Start Minute, End Hour and End Minute. That framework logically speaks to a "range of time" within which a process will take place. The language used in the Time function itself, speaks to that function being the act of executing a trade. The paradigm is a little confusing, when using the Time icon for a specific "task" such as just opening a position.

Therefore, what times should I use in each field (expressly) for the Open Time icon?


molanisfx wrote:
-Use one time icon for the Friday's close.


I have the same question close as I do for open. What times should I expressly use in each field?



molanisfx wrote:
-Use one time icon for the Monday to Thursday's close .


Again, same question applies - what time settings in each field should I use?

Structurally, the use of a Time icon makes a lot of sense. The part that confuses me, is the arrangement, language and structure of the Time function itself, after you open it. You get the strong sense that you should only use one (1) Time icon, per trade type (Buy, or Sell). Not one (1) Time icon for each different time setting. That part was a bit confusing to me.

Thanks.
cfx


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

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