Check if there are any new MetaTrader 5 Bar Library | MT5 EA Downloads - MetaTrader 5 Resources
1. There is only one class function and no additional variables. Please declare class CCheck before use
class check { public : boolean is new column ( const string symbol, const ENUM_TIMEFRAMES periods); };
2. Program variables are used to store corresponding data, while historical column variables need to be statically modified to store data.
//--- Static variable used to save historical bar time static date and time time_OldBar = 0 ; //--- Used to save the latest bar time date time time_NewBar = 0 ; //Last bar time long variable = 0 ; //Temporary variable
3. This is a function to obtain the latest bar time. Using this function, the system runs the fastest, so use it. The function does not exit when it returns False, check the error code if necessary.
//--- SeriesInfoInteger() This function runs the fastest, so use it if (! SeriesInfoInteger (symbol, period, SERIES_LASTBAR_DATE , var)) { resetlasterror (); print ( "Get the latest bar time error. Code:" , Get the last error ()); } else time_NewBar = datetime (variable);
4. When used for the first time, the initial value will be assigned to the storage location of historical data for subsequent comparison.
//--- First function call, assignment if (time_OldBar == 0 ) //Static date time time_OldBar { time_OldBar = time_NewBar; return ( false ); }
5. Compare the old and new time columns. If there is a difference, it indicates that a new column has been generated and true is returned. If the time is the same and there is no new bar, return false
//--- The time of the old and new bars is different, which means there is a new bar if (time_OldBar != time_NewBar) { time_OldBar = time_NewBar; return ( true ); } elsereturn ( false ) ;
Attachment download
📎testcheck.mq5 (1.61 KB)
📎 check.mqh (3.96 KB)
Source: MQL5 #44620
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •