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.
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.
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 ?
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.
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
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() == 0 && /*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
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() == 0 && /*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.
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(NULL, 0, 1);
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
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(NULL, 0, 1);
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.
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.