Ticaret robotlarını ücretsiz olarak nasıl indirebileceğinizi izleyin
Bizi Facebook üzerinde bulun!
Fan sayfamıza katılın
Komut dosyasını ilginç mi buldunuz?
Öyleyse bir link gönderin -
başkalarının da faydalanmasını sağlayın
Komut dosyasını beğendiniz mi? MetaTrader 5 terminalinde deneyin
Kütüphaneler

Check if there are any new bar - MetaTrader 5 için kütüphane

Görüntülemeler:
3189
Derecelendirme:
(11)
Yayınlandı:
2023.05.27 09:45
\MQL5\Include\
Bu koda dayalı bir robota veya göstergeye mi ihtiyacınız var? Freelance üzerinden sipariş edin Freelance'e git

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!