Problems with Time() - page 2

 

This also does not work ...

Day() == 1 || Day() == 2 || Day() == 3 || Day() == 4 

RaptorUK already reply you up there referencing TimeDayOfWeek(). The difference between Day(), TimeDayOfWeek() and DayOfWeek() are (read these carefully)

int Day() = Returns the current day of the month, i.e., the day of month of the last known server time.

int DayOfWeek() = Returns the current zero-based day of the week (0-Sunday,1,2,3,4,5,6) of the last known server time.

int TimeDayOfWeek(datetime Time) = Returns the zero-based day of week (0 means Sunday,1,2,3,4,5,6) for the specified date.


So Day() = 1 could be any day from Monday to Sunday.

BTW, Today is 31st May, Day() function will return 31 (Date) while DayOfWeek() will return 4 (Thursday).

Tomorrow is June 1st, Day() function will return 1(Date), and DayOfWeek() function will return 5 (Friday).

Use this as script :

Alert ("TimeDay of local time ",TimeDayOfWeek(TimeLocal())," and TimeDay of server time ",TimeDayOfWeek(TimeCurrent()));
Alert ("Day () is ",Day()," and DayOfWeek is ", DayOfWeek ());
 
toCFx:

LOL!

I'm starting to think that a majority of the "Time" based functions in MT4 are seriously flawed.

I mean, if I reset all of my position control logic to something as mundane as: TimeHour(TimeCurrent()) == 23 && TimeHour(TimeCurrent()) == 59, and not be able to get a solitary trade closed at all (the EA simply ignores the code!), then I would say that MT4 has some issues that need to be corrected with respect to these types of functions.

LOL dont you think if the MQL4 Time based functions have those serious flaws someone else probably would have noticed by now ?

Maybe you might try correcting your flawed code first before claiming the functions are flawed

in your closing criteria try changing:

TimeHour(TimeCurrent()) == 23 && TimeHour(TimeCurrent()) == 59

to:

if(TimeHour(TimeCurrent()) == 23 && TimeMinute(TimeCurrent()) == 59)

toCFx:

The code can't be more simple! I'm instructing the EA to open the damn trade between 00:00 and 00:05. That is not a difficult thing to code. A six year old could code that. Here it is yet again: [b]TimeHour(TimeCurrent()) == 00 && TimeHour(TimeCurrent()) <= 05[/b].

Also you might try correcting that too lol

change:

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

to:

if(TimeHour(TimeCurrent()) == 0 && TimeMinute(TimeCurrent()) <= 5)

 

Dear CFx,

My apology if I rant. I have bad day. I think we have other forumer that may must-have to re-install his PC coz he's not reading my replies throughoutly right.

1. If you want to close trades between Monday and Thursday, all at 23:57, and on Friday 21:57

   if (
       (DayOfWeek () >= 1 && DayOfWeek() <= 4 && TimeHour(TimeCurrent()) >= 23 && TimeMinute(TimeCurrent()) >= 57)
       || (DayOfWeek() == 5                   && TimeHour(TimeCurrent()) >= 21 && TimeMinute(TimeCurrent()) >= 57)
      )
      {
      // close it
      }

And you can modify the same code for Open Trade.

Read this about testing https://www.mql5.com/en/articles/1512


2. This is important : you mentioned "tools". If you be so kind to elaborate what you mean by "tools" - it's OK to mention it's name here. We only use MetaEditor. There's plenty forumers here that use some online tools out there and had us fix the errs. You have to tell us what it is, coz your codes may full with errors - e.g. your logic is correct but you use wrong kind of mql4 functions.

... who uses a tool for helping me build EAs. That tool allows the use of some MQL structure, but it does not execute on explicit MQL functions. It simply takes MQL code, evaluates whether the MQL based condition is true/false, and then executes a custom function such as OpenBuy, OpenSell, CloseBuy, CloseSell, DeletePendingBuy, DeletePendingSell, etc. But, it does not run MQL code explicitly. For example, you can(not) use the Print or Comment function to get something to appear on the chart window of MT4 (just one example).


3. It seem to me that you like writing a long pages a lot, there's nothing I can do about that, except please keep this in mind :

This is my first post. First, please not(e) that I am not an MQL developer.

so you won't get some embarrassment, especially after you said ...

I'm not an MQL developer, but I'm really good at developing logical constructs and I can detect a systemic problem when I sense one.

We're always here to help, even including reading your long essays.

Here's your - very long - first post.

Hello MQL4 Community!

This is my first post. First, please not that I am not an MQL developer. I am a Trader, who uses a tool for helping me build EAs. That tool allows the use of some MQL structure, but it does not execute on explicit MQL functions. It simply takes MQL code, evaluates whether the MQL based condition is true/false, and then executes a custom function such as OpenBuy, OpenSell, CloseBuy, CloseSell, DeletePendingBuy, DeletePendingSell, etc. But, it does not run MQL code explicitly. For example, you can use the Print or Comment function to get something to appear on the chart window of MT4 (just one example).

So, I know a tiny bit about MQL, which is just enough to enable me to use the EA development tool that I use to build my EAs. Thus far, I have built 10 EAs using the tool and have abandoned 7 of them due to non-profitability, which is about 30% better than my successful prototype ratio that I used to get with building trading systems in Excel. I typically expect that 7-8 ideas out of 10 will not be as profitable as expected, leaving 2-3 designs profitable enough to begin the optimization process. Ok, enough about me and how I roll.

Here's my problem and I hope that I came to the right place for help!

I'm running this code [b]to close trades:[/b]

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

Note: 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 also running this code through an MQL block [b]to open trades:[/b]

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

Note: 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 have ample available tick flow. So, there were no gaps in the data being used by Tester.

Any help would be appreciated. Why are these trades failing to close at the coded time? Why are no trades being executed when there is always a trade signal available between 00:00 through 00:05, Monday through Friday?

Thank you!
cfx

 
   if( DayOfWeek()<1 || DayOfWeek()>5 || TimeMinute(TimeCurrent()) < 57 )
      return(0);
   else if( TimeHour(TimeCurrent()) >= 23  || ( DayOfWeek() == 5 && TimeHour(TimeCurrent()) >= 21) ){
     //Close
   }
 
CFx:

I've used no Print statements for such a purpose.

Why not ? open your code in MetaEditor, add some Print functions to tell you what is going on . . .

MT4 does not have a debugger so one of the only tools available to us is Print . . . another is Comment . . and that is just about it.

 
RaptorUK:

Why not ? open your code in MetaEditor, add some Print functions to tell you what is going on . . .

MT4 does not have a debugger so one of the only tools available to us is Print . . . another is Comment . . and that is just about it.


I use Alert() quite a lot for that purpose too
 

The tools. Tell us about the tools, don't be embarrassing, I learnt from RaptorUK, dabbler, and SDC's comments the other day. So, please, tell us .

:D

 
SDC:

I use Alert() quite a lot for that purpose too
I don't . . . that's why I forgot it . . . thanks for the correction :-)
 
onewithzachy:

LOL. You are the one who unreal. This code of yours ...

... will never returns true.

You're the one who need to further develop "your" logical construct.

And construct this ...


Maybe you should try reading the OP. It clearly tells you that I'm not an MQL developer. Furthermore, there is a huge (massive) distinction between being able to logically construct a programming language, and being able to logically construct a consistently profitable trading system. Unfortunately, in this business, you find plenty of programmers online who don't have a solitary clue about what it takes to research, design, architect, build, engineer, integrate and implement, an intelligent trading system that actually works under any market condition (bull, bear and transitional). So, I understand your inability to understand where I'm coming from. I've built that intelligent trading system and I did it with Excel (of all things).

It has been profitable on a full-time basis for that past 3.27 years consistently, while having produced far better than average results over the past 7 years on a part-time basis, while it was still being designed, built and optimized - a fully integrated, decision support trading system designed with input from a 100% custom indicator framework. There are no standard 50+ year old indicators in my system, as every indicator in use throughout the system comes from a new design and indicator concept that I created from the ground-up through years of research and testing. The only thing left for me to do, is write a book about it.

So, in terms of designing trading systems that work, I would guess that you probably have not seen the likes of my kind on this board in a while - if ever. Who do you know that has created a new class of indicator design? I'm not talking about taking an existing indicator design, tweaking it and giving it a new name - that's called advancing the current generation of indicator. I'm talking a brand new indicator concept based on a theory of the market that has not been discussed in public on a large scale? They are called [b]Delta Differential Class Indicators[/b] and they are not based on the traditional market theories from anything you've ever seen before, I assure you of that fact.

My interest in MQL is to discover whether or not D2 class indicators have value in the lower time-frames, as the prototype system from whence they come ONLY uses Daily, Weekly, Monthly and Annual bars o data, to produce a single (1) trade signal ever 24 hours, which has been between 91% to 99% accurate to a specified target for the past 3.27 years. That's roughly 850+ trade signals between 91-99 percent target accuracy, in a target range of between 17 to 67 pips per 24 hours (core median).

The current prototype is NOT automated and it is far too complex for MQL to handle. OOP, would be the optimal environment for it, but I've been too busy with other things afforded me, to sit down long enough to learn C, or C++.

This test, is a POC to find out whether or not a handful of my indicator designs can function well below the Daily bar time frame. If I can find technical justification for automating lower time frames using my designs, then I can justify the time that I would need to spend learning OOP, and turning the prototype into a stand-alone proprietary Windows Trading application (not for sale under any circumstances).

Traders trade. Programers, program. I am NOT a programmer............ yet.

 
onewithzachy:

This also does not work ...

RaptorUK already reply you up there referencing TimeDayOfWeek(). The difference between Day(), TimeDayOfWeek() and DayOfWeek() are (read these carefully)

int Day() = Returns the current day of the month, i.e., the day of month of the last known server time.

int DayOfWeek() = Returns the current zero-based day of the week (0-Sunday,1,2,3,4,5,6) of the last known server time.

int TimeDayOfWeek(datetime Time) = Returns the zero-based day of week (0 means Sunday,1,2,3,4,5,6) for the specified date.


So Day() = 1 could be any day from Monday to Sunday.

BTW, Today is 31st May, Day() function will return 31 (Date) while DayOfWeek() will return 4 (Thursday).

Tomorrow is June 1st, Day() function will return 1(Date), and DayOfWeek() function will return 5 (Friday).

Use this as script :


I've used DayOfWeek(), as shown in one of my posts, and it still did not work properly.

Reason: