Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

Check if there are any new bar - library for MetaTrader 5

Views:
3643
Rating:
(11)
Published:
2023.05.27 09:45
TestCCheck.mq5 (1.61 KB) view
\MQL5\Include\
Check.mqh (3.96 KB) view
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

1、There is only one class function without additional variables. Please declare class CCheck before use

class CCheck
  {
public:
   bool              isNewBar(const string symbol,const ENUM_TIMEFRAMES period);
   
  };


2、Program variables are used to store corresponding data, while historical bar variables need to be statically modified for data storage

//--- Static variables used to save history bar time
   static datetime time_OldBar = 0;   
   
//--- used to save the latest bar time
   datetime time_NewBar = 0;    //Latest bar time
   long     var = 0;            //Temporary variables

 

3、This is the function to obtain the latest bar time. Using this function, the system runs the fastest, so it is used. When it returns False, the function will not exit, and if necessary, check the error code.

//--- SeriesInfoInteger() this function runs the fastest, so use it
   if(!SeriesInfoInteger(symbol,period,SERIES_LASTBAR_DATE,var))
      {
      ResetLastError();
      Print("Error in obtaining the latest bar time. Code:",GetLastError());
      }
      else time_NewBar = datetime(var);


4、When used for the first time, initial values will be assigned to the storage location of historical data for subsequent comparison

//--- First function call, assign a value
   if(time_OldBar == 0)		//static datetime time_OldBar
     {
      time_OldBar = time_NewBar;
      return(false); 
     }


5、Comparing the old and new time columns, if there is a difference, it indicates that a new bar has been generated and returns true. If the time is the same, there are no new bar, return false

//--- The time of new and old bar is different, it means there is a new bar
   if(time_OldBar != time_NewBar)
     {
      time_OldBar = time_NewBar;
      return(true); 
     }
     else return(false);




    Equity-based Position Closure Equity-based Position Closure

    Explore the implementation of equity-based position closure in your trading bot, where positions are closed automatically when the equity reaches a certain percentage threshold.

    Moving Average-RMA Moving Average-RMA

    RMA Relative Moving Average is a variant of EMA

    AK-47 Scalper EA AK-47 Scalper EA

    The AK-47 Scalper EA is fully automated. It employs a strategy of continuously entering Sell Stop orders and will modify them when the price moves against the pending orders.

    Indicator PriceScale.mq5 - price scale for the visually impaired. Indicator PriceScale.mq5 - price scale for the visually impaired.

    Tortured small print in the terminal? This indicator makes price numbers visible!