거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Twitter에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Check if there are any new bar - MetaTrader 5용 라이브러리

조회수:
3191
평가:
(11)
게시됨:
2023.05.27 09:45
\MQL5\Include\
Check.mqh (3.96 KB) 조회
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

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!