I think it's somewhere else on this forum, but I'm pasting solution here.
//declare in global scope static datetime time = Time[0]; //use in OnTick/Timer/Event function if (Time[0] > time) { time = Time[0]; //do your trading here }
Of course if you run EA on 1 hour chart, it'll detect hourly openings etc.
You can also check for a new bar/candlestick to appear.
See this code for an example:
// Rates structure array for last two bars MqlRates mrate[2]; CopyRates(Symbol(), Period(), 0, 2, mrate); // NEW BAR CHECK. //--------------- static double dBar_Open; static double dBar_High; static double dBar_Low; static double dBar_Close; static long lBar_Volume; static datetime nBar_Time; // Boolean for new BAR confirmation. bool bStart_NewBar = false; // Check if the price data has changed tov the previous bar. if(mrate[0].open != dBar_Open || mrate[0].high != dBar_High || mrate[0].low != dBar_Low || mrate[0].close != dBar_Close || mrate[0].tick_volume != lBar_Volume || mrate[0].time != nBar_Time) { bStart_NewBar = true; // A new BAR has appeared! // Update the new BAR data. dBar_Open = mrate[0].open; dBar_High = mrate[0].high; dBar_Low = mrate[0].low; dBar_Close = mrate[0].close; lBar_Volume = mrate[0].tick_volume; nBar_Time = mrate[0].time; } // Check if a new bar has formed. if(bStart_NewBar == true) { // your code for opening a new trade: if() { } }
if(Time[0]==TimeCurrent()) { //Do something }
Ahmed Soliman:
another way... you use like below
if (Volume[0] < 3) { //do something here }
if (Volume[0]==1) { //Do stuff }
Easy and work most of the time but its unreliable.
Thank you, my friends have been successfully command
i need just another command
if ( timenow>= 10:00 && timenow<=10:29) { closeall(); }
Mahfoud Allali:
Thank you, my friends have been successfully command
i need just another command
if(Hour()==10 && Minute()==00)
{
closeall();
}
:D

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
if (market open new candlstick)
{
openbuy();
}