Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-02-2006, 07:56 PM
Member
 
Join Date: Nov 2006
Posts: 46
SteveBrown is on a distinguished road
Detecting end of hourly candle?

Programming my first EA, I face the problem of how best to detect the start of a new hourly candle. There appears to be only one method, and that is to wait for the first tick to come along which falls into the next time period. That is because there appears to be only one way the start() function is called in my EA, and that is when the server pumps out a new tick. So, if a tick occurs at 01:59, and the next tick comes at 02:02, the EA detects the end of the 01:00 candle and the start of the 02:00 candle at 02:02, two minutes after the top of the hour. My EA is designed to run on the H1 chart, and it makes trading decisions based upon the close prices of hourly candles. I would like my EA to make those decisions at the top of the hour, rather than wait for the first tick that occurs in the new hour. Is there any method by which the start() function in my EA can be called as soon as a new hour begins on the clock?

Last edited by SteveBrown; 11-03-2006 at 06:09 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 11-02-2006, 08:28 PM
Senior Member
 
Join Date: Feb 2006
Posts: 587
Michel is on a distinguished road
Quote:
Originally Posted by SteveBrown
Programming my first EA, I face the problem of how best to detect the start of a new hourly candle. There appears to be only one method, and that is to wait for the first tick to come along which falls into the next time period. That is because there appears to be only one way the start() function is called in my EA, and that is when the server pumps out a new tick. So, if a tick occurs at 01:59, and the next tick comes at 02:02, the EA detects the end of the 01:00 candle and the start of the 02:00 candle at 02:02, two minutes after the top of the hour. My EA is designed to run on the H1 chart, and it makes trading decisions based upon the close prices of hourly candles. I would like my EA to make those decisions at the top of the hour, rather than wait for the first tick that occurs in the new hour. Is there any method by which the start() function in my EA can be called as soon as a new hour begins on the clock?
No, you do not have any way to do that, but maybe you can write an endless script ...
But what should be the avantage to run the EA before the first tick ?

Last edited by Michel; 11-02-2006 at 08:30 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 11-02-2006, 09:00 PM
Member
 
Join Date: Nov 2006
Posts: 46
SteveBrown is on a distinguished road
Quote:
Originally Posted by Michel
No, you do not have any way to do that, but maybe you can write an endless script ...
But what should be the avantage to run the EA before the first tick ?
Thanks for your reply. Any advantage I could hope to gain would be minimal, but since my EA makes the decision to open a trade based on the closing price of the hourly candle, I would prefer it to place the order at the close of the candle, instead of waiting for the next candle to begin. Even if the new candle is not immediately displayed at the top of the hour, the close price has already been established by the end of the time period.

Having programmed applications for Windows, I am accustomed to the ability of a program to receive a message from the OS or another program and to act upon it immediately, so I find it restrictive that my EA can only act when my start() function is called when a new tick occurs.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 11-03-2006, 12:36 AM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
Quote:
Originally Posted by SteveBrown
Programming my first EA, I face the problem of how best to detect the start of a new hourly candle. There appears to be only one method, and that is to wait for the first tick to come along which falls into the next time period. That is because there appears to be only one way the start() function is called in my EA, and that is when the server pumps out a new tick. So, if a tick occurs at 01:59, and the next tick comes at 02:02, the EA detects the end of the 01:00 candle and the start of the 02:00 candle at 02:02, two minutes after the top of the hour. My EA is designed to run on the H1 chart, and it makes trading decisions based upon the close prices of hourly candles. I would like my EA to make those decisions at the top of the hour, rather than wait for the first tick that occurs in the new hour. Is there any method by which the start() function in my EA can be called as soon as a new hour begins on the clock?
do you mean to detect the price of the new cande, or the time it occurs? as both of theese methods ARE do-able, and fairly simple.
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 11-03-2006, 03:59 AM
Member
 
Join Date: Nov 2006
Posts: 46
SteveBrown is on a distinguished road
Quote:
Originally Posted by Eaglehawk
do you mean to detect the price of the new cande, or the time it occurs? as both of theese methods ARE do-able, and fairly simple.
Eaglehawk,

What I mean is, I want my start() function to be called at the exact top of the hour, even before the first tick comes in on the new candle.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 11-03-2006, 04:05 AM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
Quote:
Originally Posted by SteveBrown
Eaglehawk,

What I mean is, I want my start() function to be called at the exact top of the hour, even before the first tick comes in on the new candle.
ok, here's what i would do, i would use the Minute() variable as you are trading on the hourly chart, this will allow you to make your ea's desicions at the exact top of the hour.

example

PHP Code:
if (Minute() == && /*rest of how you determine your action*/); 
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 11-03-2006, 05:00 AM
Member
 
Join Date: Nov 2006
Posts: 46
SteveBrown is on a distinguished road
Quote:
Originally Posted by Eaglehawk
ok, here's what i would do, i would use the Minute() variable as you are trading on the hourly chart, this will allow you to make your ea's desicions at the exact top of the hour.

example

PHP Code:
if (Minute() == && /*rest of how you determine your action*/); 
What Minute() does is tell me the minute of the most recent tick. Are you saying that instead of returning after evaluating every tick, my start() function should go into a loop waiting for Minute()==0? If so, in that same loop it would have to continually check for a new price, but I don't think the price is actually updated until MT calls the start() function again with a new tick. As I understand from the documentation, the start() function cannot be called again until the previous call to the start() function returns.

I think what I really need is information as to what Windows message I can have a program send to MT4, to tell it to call the start() function in my EA. I can create a Windows program to monitor the time and send the message to MT4 at the top of the hour. In other words, I need to be able to simulate a tick at the top of the hour.

Last edited by SteveBrown; 11-03-2006 at 05:08 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 11-03-2006, 05:09 AM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
Quote:
Originally Posted by SteveBrown
What Minute() does is tell me the minute of the most recent tick. Are you saying that instead of returning after evaluating every tick, my start() function should go into a loop waiting for Minute()==0? If so, in that same loop I would have to continually check for a new price, but I don't think the price is actually updated until MT calls the start() function again with a new tick.

I think what I really need is information as to what Windows message I can have a program send to MT4, to tell it to call the start() function in my EA. I can create a Windows program to monitor the time and send the message to MT4 at the top of the hour. In other words, I need to be able to simulate a tick at the top of the hour.
no, no, no, not that confusing, minute of the hour, so if minute is equal to 0, it's not 10:01 or 9:59, it is 10:00, 0 minutes after the hour.

now if you want to recall the price of the market right as it opened, or opens, i would recommend using the variable "iOpen"

example

PHP Code:
double openperiod iOpen(NULL01); 
the "openperiod" is just a quick example name. you may want to change the last "1" to "0" considering you mention you want to look at the "now" top of the hour, 0 meaning current bar, 1 meaning last complete bar, and so forth.
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #9 (permalink)  
Old 11-03-2006, 05:37 AM
Member
 
Join Date: Nov 2006
Posts: 46
SteveBrown is on a distinguished road
Quote:
Originally Posted by Eaglehawk
no, no, no, not that confusing, minute of the hour, so if minute is equal to 0, it's not 10:01 or 9:59, it is 10:00, 0 minutes after the hour.

now if you want to recall the price of the market right as it opened, or opens, i would recommend using the variable "iOpen"

example

PHP Code:
double openperiod iOpen(NULL01); 
the "openperiod" is just a quick example name. you may want to change the last "1" to "0" considering you mention you want to look at the "now" top of the hour, 0 meaning current bar, 1 meaning last complete bar, and so forth.
Eaglehawk, thanks for trying to help, but I don't think you understand that the start() function is normally called for every new tick. It processes the tick and then returns. It can't wait for Minute() to equal zero without going into a loop, and if it does that, it can't process additional ticks.

I do understand that Minute() reports the minute of the hour of the most recent tick.

Last edited by SteveBrown; 11-03-2006 at 05:39 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #10 (permalink)  
Old 11-03-2006, 06:00 AM
Member
 
Join Date: Nov 2006
Posts: 46
SteveBrown is on a distinguished road
And even if I could have start() wait for Minute() to indicate the start of a new candle, that does not remove the delay if the first tick occurs a minute or two after the top of the hour.

I think I'm going to have to resign myself to detecting the end of the hourly candle in the conventional way, by waiting for the first tick of the next hourly candle, even though that may occur a minute or two after the top of the hour.

Last edited by SteveBrown; 11-03-2006 at 06:03 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions: to start with MetaTrader and forex Maji General Discussion 491 Today 10:05 AM
Detecting price trend independent of a specific time frame gee Metatrader 4 4 02-24-2007 05:53 PM
Detecting new bar (Indicator / EA?) Nightmasks Indicators - Metatrader 4 10 08-23-2006 07:05 PM
About start() The_N Indicators - Metatrader 4 1 05-21-2006 04:20 PM


All times are GMT. The time now is 08:26 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.