Detecting start of new candle? - page 2

 
Aaragorn:
would it mess up your strategy to start the new candle at minute = 59?

It could, in the event that it misses the important closing price. Eaglehawk's suggestions got me thinking, and it occurred to me that a solution may be to have my start() function go into a loop, but only when the first tick occurs in the 59th minute of the hour. Then it gets the number of seconds, subtracts that from 60, and goes to sleep for that number of seconds, the number of seconds remaining in the hour. When it "wakes up" at the top of the hour, iClose(NULL, 0, 0) may return the close price of the hourly candle, even if a tick occurred during the start() function's "nap." Or maybe iClose() cannot do that unless start() is called after the tick occurs. I intend to experiment to find that out.

double dbClose;

if(Minute() == 59) Sleep(1000 * (60 - Seconds()));

dbClose = iClose(NULL, 0, 0);

 
SteveBrown:
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.

Take a look at this Link: http://www.metatrader.info/node/151

 

Candle vs. tick

I'm writing an EA for the system I'm testing and I have a question that I'm hoping is pretty simple. I want to place 2 pending orders whenever a new candle opens (I'm using D1 charts). I've written a script that places the orders with my TP and SL and it works fine, I just want the EA to do this automatically (as well as figuring out lot size based on prior wins and losses). I also want to close one of the pending orders if the other hits. This would seem to need to be checked every tick vs. running once when the candle opens. My overall question is, how do you make the order entry happen each time a new candle starts while still checking to see if it hits each tick? I don't want to re-start the EA each day because I use it to keep track of my lot sizes each day.

Reason: