Home
Search Forums
Keywords:
Search Titles Only
User Name:
Exact Match
Show Results As:
Advanced Options
Reply
 
Thread Tools Search this Thread
  #1  
Old Sep 25, 2008 6:24pm
Member
 
Member Since Apr 2007
3 Vouchers  275 Posts
Default New very cool CandleTime and session time Clock indicators

Last "P4L Clock.mq4" update: Feb 23, 2010, posted new v2_7
Last "P4L CandleTime.mq4" update: Nov 13, 2009, posted new v1_2

Hi all,

I have used CandleTime.mq4 (aka b-Clock.mq4) for a long time, and it had some quirks in the display of single digits (e.g. ":9" instead of ":09"), and sometimes the number of seconds remaining went negative, which I thought was strange and a bit hard to notice the "-" sign.

I cleaned up the code and added some user variables to control color, and/or display of the time by the bar, and/or display of a comment. The by-the-bar text displays single-digit seconds just fine. (":09")

FYI, when the seconds remaining is a negative number, the old bar is over but the new bar is yet to be formed, or in a sense it's overdue. In such cases I now display a "WAIT4BAR:-MM:SS" text so it is clearly distinct from the normal display. (FYI, when markets are slow a lot of M1 and even M5 (and higher) bars never form at all, so the "WAIT4BAR" condition can persist for quite a long while).

The above program I have called "P4L CandleTime.mq4". You can rename it if you like.

I also decided to modify another time related program, Clock_v1_3.mq4, aka Clock.mq4, that had some similar display issues. That tool displays an array of market names and hours in one corner of your chart. I made some significant enhancements to the indicator which I call "P4L Clock.mq4" :

* Different highlight color(s) used for Market Open hours (Assuming 8AM - 5PM local market hours)
* Added seconds display, and used method such that single digits look better (":09" not ":9")
* Added "Broker_Time_Is_Gold_Standard" to adjust (by a few seconds or minutes) the market hours, because as if often the case, the local computer clock may be off by a small amount.
* Two extern variables to control display of seconds: bool Display_Time_With_Seconds, int Display_Bar_With_Seconds.
* When Display_Bar_With_Seconds=2 (Auto mode), seconds display when < 2min, OR, if Display_Time_With_Seconds=True.
* "Bar:" changed to "Bar Left:" (remaining time!). Also, it will say "wait4bar" (rather than to display a negative number as would have occurred) during periods of low activity until a new bar is formed.
* "Suppress_Bar_HH_Below_H1" displays only [MM:SS] for H1 and below since HH in [HH:MM:SS] is always "00"
* Adjusted pixel distance between labels depending on options.
* "Bar Left:" time does not display above D1 charts. A future enhancement (not planned) could report DD_HH:MM[:SS]
* Added Show_DIBS_London clock with user-setable start/stop hour relative to London (6AM and 7PM at present). (The DIBS method is discussed over in thread http://www.forexfactory.com/showthread.php?t=86766 )
(Further enhancements & features are described in the "Update" section below).

FYI, I found a modification of Clock_v1_3.mq4 called Clock_v1_4.mq4 but which is actually a script. (I posted it elsewhere -- and can't delete it now -- a copy I called Clock_v1_4_script.mq4 ). I posted it without first fully testing it. I had problems using that script. After a bar completed, the bar time wasn't working for me. ('Time[0]' was frozen because it was in an infinite loop with 'Sleep(1)' ). I also couldn't change timeframes without stopping the script and then re-adding it. Maybe I was doing something wrong, but it didn't work well for me.

My version updates on a by-tick basis (but not more than once-per-second). It should be relatively CPU friendly compared to an infinite loop (??). Please NOTE: The clocks do not update unless new ticks come in. Also note that on weekends, the broker clock is frozen and even with simulated ticks you will not see updates! You could try "Weekend_Test_Mode=true", or better... wait for the market to open.


Installation:
// Copy this file to: C:/Program Files/--your-MT4-directory-here---/experts/indicators/
// Review the "extern" variable settings below. Change as desired, then restart MT4 or do "Compile" in MetaEditor.
//
// Open a chart and add this indicator. Assuming you compiled with the "extern" defaults you prefer,
// you shouldn't need to change any of the defaults, *except* one: (FOR "P4L Clock.mq4" ONLY!)
// This Version requires "Allow DLL Imports" to be set under the Common Tab when you add this to a chart!
// FYI, the DLLs retrieve the local CPU clock time and timezone info as well as world timezone info.
// A word of caution: You can see my entire source code and what the DLL's do which should be harmless.
// Personally, I *never* enable DLL's on any binary .EX4 file because I don't trust what the program might do.
// For all I know, it could be sending out very private information about me or my account!
//
// NOTE! The world timezone times are only as accurate as your LOCAL CPU CLOCK or, if variable
// Broker_MMSS_Is_Gold_Standard=True, your Broker's clock! At least verify your own clock and set it accurately!
// NOTE! Your Broker time is independent of your local CPU clock and, though unlikely, may change at any time.


(Thanks go to the previous authors for their ideas and implementation which I have further enhanced.)

Please report any issues/problems...

Enjoy!

Pips4life (Kent)

UPDATES:
2008-09-27: New "P4L Clock.mq4" v2_1
"P4L Clock.mq4" version v2_1 addresses all timezone/ST/DST issues. Also adds Sydney TZ. Given reports of problems with the old DST/timezone code, I rewrote that section entirely. TimeZone and ST/DST changeovers should display the correct times regardless of your own timezone and ST/DST change dates. However, plan on revisiting this post early in 2009 (and each year) for an annual update with new ST/DST crossover dates! (Correction: no annual update is required!).
2008-09-28: New "P4L Clock.mq4" v2_2
Turns out version v2_1 will NOT require annual updates! The timezone info was not limited to 2008 after all. Updates will only be required if ST/DST changeover dates are changed legislatively (such as Tokyo adopting DST, or US/London/Sydney changing their dates). This version has mostly cosmetic changes to remove the reference to "annual" updates. My apologies for the confusion.
2008-09-28: New "P4L Clock.mq4" v2_3 (Downloaded 1074 times before next version update).
(Note: Covers all issues and enhancements requested through Post #12)
Added Auckland, Moscow, Berlin, Seattle for Jodie(jhp2025). Default topOffsetPixels is now 10.
2008-10-02: New "P4L CandleTime.mq4" v1_1 (Downloaded 974 times before next version update!)
For H4 and above, display "#hours:MM:SS" bar-remaining time. However, for W1 and MN, the bar remaining time may not be accurate (depending on your broker weekend closing time) since the Period() function is not precise, and some weekend time may be included in "remaining" time.
2009-11-13: New "P4L CandleTime.mq4" v1_2
For Weekly and Monthly charts, the number of remaining hours might be excessive (well over 24 hours), so a new format is used: D_HH:MM:SS
The program was also updated to be compatible with timeshifted charts as created by the new "P4L PeriodCon.mq4" indicator. (See http://www.forexfactory.com/showthread.php?t=206301 for "Improved multi-timeframe/offset/chart period converter, P4L PeriodCon.mq4"
2009-11-29: New "P4L Clock.mq4" v2_4 (Downloaded 105 times before next version update!)
Changes: New colors plus user control over font name/size, vert. & horiz. offsets and spacing. Reworked auto-spacing of labels based on AM/PM vs. 24 hour, and display of seconds (or not) and ShowBarTime (or not). Added timezones for: China, Jakarta, India, Israel, Helsinki, Brazil, Mexico, Central and Mountain; renamed "Seattle" to "Pacific". Label order is consistent for any LabelCorner but can also be reversed. Can be drawn in a chart sub-window. New "OverrideShowALL" to see every timezone. New defaults for zones and display-style but user can change as desired. AM/PM is off. Seconds are displayed to better allow precise calibration of local CPU Clock vs. Broker time (Very helpful for news events).
2010-01-14: New "P4L Clock.mq4" v2_5 (Downloaded 26 times before next version update!)
Changes: New "Background_Under_Labels" feature draws a rectangle (actually several) under the labels to make them more readable. The rectangle COVERS price bars and other lines/objects (so long as your F8 "Chart on foreground" variable is un-checked, and if other objects have their Background=true. (Traderathome suggested the rather clever use of OBJ_LABEL with font Webdings, key "g", and large fontsize to create the background rectangle). (See GBPJPY H1 picture below which also shows every market zone supported. This shows bottom-left corner, but any corner can be used for the labels).
2010-01-21: New "P4L Clock.mq4" v2_6 (Downloaded 96 times before next version update!)
Changes:
* New "ShowPipSpread" (Ask-Bid) in pips (including automatic 1/10th pips for extra-digit-brokers).
* New "ShowBidPrice" where color indicates last tick was higher/lower.
* New "ShowVolume". Color indicates higher/lower vs. the last bar. Also, the label changes to "*HiVol*" if the volume is >= the-12th-highest-of-last-120-bars.
* Flag LowSpread by setting "LowSpreadHighlightThreshold" to >0
* New popup Alerts (once-per-bar): DoHighVolumeAlerts & DoLowSpreadAlerts
* New arrows using DoLowSpreadArrows to mark LowSpread events on the chart. (Because they can't be recreated, these arrows persist unless you remove them by changing "Delete_Old_SpreadArrows" to true.
* An Alert ERROR now occurs if the user forgets to enable DLLs.
* Regular MarketOpenHours (8A-5P) (and those for Sydney, 7A-4P) can now be customized with external variables if desired.

2010-02-23: New "P4L Clock.mq4" v2_7
Changes:
* Added option for Dubai timezone
* New "ShowRange" to show current bar High-Low (in pips)
* New "ShowPips2open" to display current currentBarPrice-Open in +/- pips
* New "ShowAvgPeriodRange" to display APR (or A#R). The period, lookback and display are controled with APR_Period, APR_Bars and APR_LabelShowMinutes
* New "ShowAvgDailyRange". Lookback controlled with ADR_Bars
* Renamed old "Background_Name_Pixels" to "Background_AddWidth_Pixels"
* Fixed a few bugs with v2_6
* KNOWN issue with ADR/APR: When calculations are based on a different chart timeframe, the calculations are only correct if your history data is current for the other timeframe (i.e. ADR will be accurate if your Daily history data is current). Best way to be sure is to have a Daily chart open in addition to the chart you attach this indicator to.

P.S. New screenshots contain a few useful notes. Several new market zones and bar info may not be shown in the older screenshots.

-----------------------------------------------
FYI, see also: Collection of programs by pips4life
-----------------------------------------------
Attached Images
     
Attached Files
File Type: mq4 P4L CandleTime.mq4 (9.4 KB, 460 views)
File Type: mq4 P4L Clock.mq4 (96.9 KB, 316 views)

Last edited by pips4life, Feb 23, 2010 2:04am Reason: 2010-02-23: New "P4L Clock.mq4" v2_7.
Reply With Quote
  #2  
Old Sep 25, 2008 6:38pm
Member
 
Member Since Aug 2008
Default

Thanks Dear..

I observe that

In 30 min TF ,1H TF and 4H , Daily , ..

the candel time is same..it dose not change time..
Reply With Quote
  #3  
Old Sep 25, 2008 6:45pm
Member
 
Member Since Apr 2007
3 Vouchers  275 Posts
Default

Quote:
Originally Posted by WedWed View Post
Thanks Dear..

I observe that

In 30 min TF ,1H TF and 4H , Daily , ..

the candel time is same..it dose not change time..
That is correct... this is a count-down timer! For each of those timeframes you will get new bars in exactly the same number of MM:SS.

The number updates only when you get new ticks and right now the market is pretty slow. To simulate ticks, you can use the right-click menu and select "Refresh". As an alternative, type -- sequentially, not at once -- Alt, c, r This also does "Refresh".

(FYI, I *really* would love a one-keystroke method to do Refresh. If anyone knows how, please post...)

(Whew... you scared me. Thought I posted a bad version All is well AFAIK...)

Kent
Reply With Quote
  #4  
Old Sep 25, 2008 7:04pm
Member
 
Member Since Aug 2008
Default

Quote:
Originally Posted by pips4life View Post
That is correct... this is a count-down timer! For each of those timeframes you will get new bars in exactly the same number of MM:SS.

The number updates only when you get new ticks and right now the market is pretty slow. To simulate ticks, you can use the right-click menu and select "Refresh". As an alternative, type -- sequentially, not at once -- Alt, c, r This also does "Refresh".

(FYI, I *really* would love a one-keystroke method to do Refresh. If anyone knows how, please post...)

(Whew... you scared me. Thought I posted a bad version All is well AFAIK...)

Kent
Thanks dear for clearification
Reply With Quote
  #5  
Old Sep 25, 2008 8:06pm
Multiple Usernames
 
Member Since May 2007
Default Clock! Around the Clock!

Hi Kent P4L,

Still it doesn't work for me tho'.

Always come to some wrong time between local and gmt one.
Reply With Quote
  #6  
Old Sep 25, 2008 8:28pm
NuckingFuts's Avatar
Nudist
 
Member Since May 2008
Default

Quote:
Originally Posted by jhp2025 View Post
Hi Kent P4L,

Still it doesn't work for me tho'.

Always come to some wrong time between local and gmt one.
Me too, try this one

EDIT: Wrong file, sorry, try it now
Attached Files
File Type: mq4 P4L Clock.mq4 (17.3 KB, 501 views)

Last edited by NuckingFuts, Sep 25, 2008 8:42pm
Reply With Quote
  #7  
Old Sep 25, 2008 8:44pm
NuckingFuts's Avatar
Nudist
 
Member Since May 2008
Default

There seems to be a bug in mt4 when your system clock has daylight savings turned off. I do not have daylight savings in my timezone.

Here's what I did to the code to fix it:

Code:
   int gmt_shift=0;
   int dst=GetTimeZoneInformation(TZInfoArray);
   //if(dst!=0) gmt_shift=TZInfoArray[0];
   //Print("Difference between your local time and GMT is: ",gmt_shift," minutes");
   //if(dst==2) gmt_shift+=TZInfoArray[42];
   if (dst == 1) gmt_shift = 3600;

   datetime brokerTime = TimeCurrent();
   datetime brokerCorrection = 0;
   
   if (Broker_Time_Is_Gold_Standard) 
   {
      brokerCorrection = TimeMinute(brokerTime)*60 + TimeSeconds(brokerTime) - TimeMinute(localTime)*60 - TimeSeconds(localTime);
      if (brokerCorrection > 1800) brokerCorrection = brokerCorrection - 3600;
      else if (brokerCorrection < -1800) brokerCorrection = brokerCorrection + 3600;
      //Alert("brokerCorrection seconds: ", brokerCorrection);
   }
   //else GMT = localTime + gmt_shift * 60;
   
   datetime GMT = TimeLocal()+gmt_shift+brokerCorrection+(TZInfoArray[0]+TZInfoArray[42])*60;
Reply With Quote
  #8  
Old Sep 25, 2008 9:06pm
NuckingFuts's Avatar
Nudist
 
Member Since May 2008
Default

I have added Sydney market to the clock for us Aussies

Sydney timezone is GMT +10
Market hours are 7am-4pm Sydney time
Attached Files
File Type: mq4 P4L Clock.mq4 (18.5 KB, 407 views)
Reply With Quote
  #9  
Old Sep 27, 2008 3:38am
Member
 
Member Since Apr 2007
3 Vouchers  275 Posts
Default Post #1 has new "P4L Clock.mq4" (v2_1) to fix timezone/ST/DST problems... plus Sydney

Hi all,

In the older version v1_3 to which I made display modifications, I assumed the timezone/ST/DST code was working but obviously given the reports of problems it wasn't. I appreciate NuckingFuts posting an update -- however, there were problems with that version as well. (That was 3600 MINUTES you coded, not seconds Kinda lucky it almost worked though...)

I dug into the code which I did not previously understand, and researched alternative Windows functions which provide a far more robust and accurate method of calculating the local times in each of the market zones, plus it works from whatever is your own timezone -- including Jakarta, Tokyo, Sydney, ... all over the world. I set my own CPU clock to various timezones and it worked on every one I tried.

The ST/DST changeovers are now unique for each of the market timezones. For example, when the US changes ST/DST, only the NewYork market time is affected. Similar for London and Sydney. (Tokyo, at present, does not observe DST).

This version v2_1 has only one drawback I know of, and that is that you have to get an annual update of it with the new world market ST/DST changeover dates for 2009 (and each year therafter). FYI, the method to make updates is documented in the code by use of an external variable set to TRUE (on just ONE chart!) early in the new year. However, an update will likely be posted in January 2009. Just maybe, a better permanent and automatic method will be discovered and put into a future version, but my knowledge of Windows functions is extremely limited.

Please go to Post #1 and download the new P4L Clock.mq4 file. Expect the times to be correct when the market opens and the ticks start coming in once again.

Kent (Pips4life)
Reply With Quote
  #10  
Old Sep 27, 2008 11:47pm
Member
 
Member Since Apr 2007
3 Vouchers  275 Posts
Default

Quote:
Originally Posted by pips4life View Post
... This version v2_1 has only one drawback I know of, and that is that you have to get an annual update of it with the new world market ST/DST changeover dates for 2009 (and each year therafter).
It turns out the above statement was wrong, and in fact, you should NOT need annual updates at all! Version v2_2 of "P4L Clock.mq4" was just posted, but the changes are mostly cosmetic to remove the references to "annual" updates required, which is not true. I didn't really understand the bitwise syntax and had to figure it out only to learn that the ST/DST changeover date information was already correct for future years.

Of course, if any market zone legislatively changes their ST/DST changeover dates, an update will be necessary. (For example, Tokyo is rumoured to be considering DST). FYI, an update will NOT be required if your local timezone changes ST/DST dates; only if a *market* zone changes (NewYork, London, Tokyo, Sydney).

Please go to Post #1 and download the new v2_2 P4L Clock.mq4 file. Expect the times to be correct when the market opens and the ticks start coming in once again. (Or temporarily set Weekend_Test_Mode=true and simulate ticks with "Refresh". You should see the correct world times which you can verify against http://www.worldtimezone.com/index24.php )


(I hope I'm done with changes, but of course if someone reports any problems their could be more. It seems, though, that I addressed the main issues with v2_1 and now v2_2).

Kent (Pips4life)
Reply With Quote
  #11  
Old Sep 28, 2008 8:47am
Multiple Usernames
 
Member Since May 2007
Default P4LClock

Hi Kent (P4L),
After several hours got headache with this Cute Clock, slowly I understand it all about and tried to modify a bit, but as your references, I still confused regarding the ST/DST.
So, as simple as I can, will you check it through whether I put something wrong on the Clock attached.
Thanks Kent, I appreciated well your effort.
PS: I add it up Auckland, Jakarta as editable local base, Moscow, Berlin, Seatle, so everyone else here can utilize it.
Attached Files
File Type: mq4 P4LClock.mq4 (8.9 KB, 323 views)
Reply With Quote
  #12  
Old Sep 28, 2008 12:11pm
Member
 
Member Since Apr 2007
3 Vouchers  275 Posts
Default P4L Clock.mq4 v2_3 released. Added Auckland, Moscow, Berlin, and Seattle.

Quote:
Originally Posted by jhp2025 View Post
Hi Kent (P4L),
After several hours got headache with this Cute Clock, slowly I understand it all about and tried to modify a bit, but as your references, I still confused regarding the ST/DST.
So, as simple as I can, will you check it through whether I put something wrong on the Clock attached.
Thanks Kent, I appreciated well your effort.
PS: I add it up Auckland, Jakarta as editable local base, Moscow, Berlin, Seatle, so everyone else here can utilize it.
Hi Jodie,

Sorry you spent time to understand that old version. I too was confused about the old ST/DST code (which I did not write), but I dug into it and when I understood that it could not work properly from different world timezones nor could it handle different ST/DST changeover dates, I replaced it entirely.

I made it easy for you to not go through the new version and add all those new markets again. A new "P4L Clock.mq4" v2_3 is now available in Post #1. I added market zones for Auckland, Moscow, Berlin, and Seattle. I also reworked and changed the default topOffsetPixels to 10 (It still looks the same).

Enjoy!

Kent

P.S. This version v2_3 should display correct world times whether you run it from Jakarta, Tokyo, Sydney, Europe, the U.S. ... almost anywhere (Even the 30 minute-offset-timezones like Caracus appear to work if you set Broker_MMSS_Is_Gold_Standard=false. All other timezones can use true or false per your preference).

Last edited by pips4life, Sep 29, 2008 12:19am
Reply With Quote
  #13  
Old Sep 29, 2008 4:09am
Multiple Usernames
 
Member Since May 2007
Default

Quote:
Originally Posted by pips4life View Post
Hi Jodie,

Kent

P.S. This version v2_3 should display correct world times whether you run it from Jakarta, Tokyo, Sydney, Europe, the U.S. ... almost anywhere (Even the 30 minute-offset-timezones like Caracus appear to work if you set Broker_MMSS_Is_Gold_Standard=false. All other timezones can use true or false per your preference).
Well, thanks Kent, let me try it again, brilliantly we work together to make our P4LClock perfectly done. Once I've got any idea I'll share it here again.
Reply With Quote
  #14  
Old Sep 30, 2008 5:28am
Pipsqueak4x's Avatar
Quietly strolling in the jungle
 
Member Since May 2005
5 Vouchers  60 Posts
Default alternate solution to one keystroke refresh

Pips4life,

If you have a mouse with extra buttons (I have a MS mouse that has a magnify button and a clickable wheel which I can program both with keystroke combinations) do one click refreshes using the extra buttons. Just a thought...
Reply With Quote
  #15  
Old Oct 2, 2008 4:22am
Member
 
Member Since Apr 2007
3 Vouchers  275 Posts
Default Updated P4L CandleTime v1_1 is in Post #1

Hi all,

I guess with my late Friday and weekend testing, I missed the most obvious problem with my P4L CandleTime, which was the number of hours remaining was never reported. The old CandleTime reported #minutes:SS, even if #minutes was well over 60. My new formating style in v1_0 limited the output to MM:SS where MM was always <=59, but the hours remaining were not reported. I have remedied this problem.

In Post #1, I just uploaded a new "P4L CandleTime.mq4" (v1_1) which for H4 and above will display the bar remaining time as: #hours:MM:SS

Please note that for W1 and MN charts, the bar-remaining time may not be accurate, depending on the time your broker finishes the bars, and because the Period() function is an estimated time for W1 and MN charts, rather than a precise and accurate number. Some weekend time may be included. While the #hours remaining may not be accurate (for W1 and MN), the MM:SS portion, however, should be correct.

Kent
Reply With Quote
Reply

1 Trader Viewing This Thread (0 are members)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing and viewing indicators from other time frames on one chart (time frame). fredarzani Platform Tech 3 Mar 4, 2009 4:12am
World News and a World Clock to keep time BurgerKing Trading Discussion 29 Nov 11, 2008 7:37pm
Cool Time And Date Zone Website and Time Zone Converter. :) Forex Star Platform Tech 3 Feb 20, 2008 2:52pm
Question on Lower Time Frame Indicators Vs. Longer Time Frame marcf Trading Discussion 7 Apr 27, 2007 3:25pm
Forex Clock: Live Feed Session Times. Bemac Trading Discussion 12 Jan 24, 2006 9:04pm