Help, I don't know how to open trade based on minute.

 
Hi, I'm newbie in making program. I try to make simple EA wich will open trade in time that we set before, for e.q I want to open trade at 21:00, but the problem with my EA is if I set the time at 21:00 and there is no tick at that time so it won't open the trade and I don't know how to make the EA check the minutes, so I want my EA to open the trade at first tick after 21:00 if the tick at that time is not available but is must not more than 21:05 or 5 minutes, so the trade can only be executed only once between 21:00 - 21:05. Is anyone can help me with this? Thank you :)
 

A strang problem!

if "there is no tick at that time",

then, open position at 21:00 - 21:05, or open position at there is new stick after 21:00,

What are there different between them?

why do you address the time?

in ther words. if there are no stick, open position at any time during that period is same.

 
You can use the following structure
static bool traded = false;
if( TimeHour(TimeCurrent()) == 21 ) {
    int minute = TimeMinute(TimeCurrent());
    if( !traded && minute >= 0 && minute <= 5 ) {
        // Open trade as you've planned
        traded = true;
    }
}
else {
    traded = false;
}
 
DxdCn:

A strang problem!

if "there is no tick at that time",

then, open position at 21:00 - 21:05, or open position at there is new stick after 21:00,

What are there different between them?

why do you address the time?

in ther words. if there are no stick, open position at any time during that period is same.


I tested it before and sometimes there is no tick at 21:00 and first tick after that is 21:01 so it won't trigger the ea to open position. I give 5 minutes spare just in case if first tick after 21:00 is 21:06 and I think its to long to open the position so it better not to open position at all. Actually this is my first EA and I'm still learning to make indicators and ea, I found some ea samples wich is used indicators like crossing MA and bars to open the trade but I'm not found ea wich is trigger by time yet so I try to make one and I found this problem and as a rookie I don't know how to handle it, thank you :) 
 
fireflies:
You can use the following structure
static bool traded = false;
if( TimeHour(TimeCurrent()) == 21 ) {
    int minute = TimeMinute(TimeCurrent());
    if( !traded && minute >= 0 && minute <= 5 ) {
        // Open trade as you've planned
        traded = true;
    }
}
else {
    traded = false;
}


Thank you fireflies, I will test it in my EA, thanks again! :)