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

New Bar Event - MetaTrader 5용 라이브러리

조회수:
5384
평가:
(38)
게시됨:
2022.07.05 09:34
업데이트됨:
2022.07.05 09:38
\MQL5\Include\
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Allows you to determine the occurrence of a new bar event in a multicurrency Expert Advisor.

In a multicurrency Expert Advisor, the event of a new bar formation can occur at different times for different instruments. But since the EA always works on the chart of one instrument, it becomes necessary to correctly determine in the OnTick() event handler whether a new bar has already formed for the required period on another instrument.

This library implements such functionality. To determine the onset of a new bar on the desired period, information about the time of the first tick of the bar for each instrument of interest is stored at each tick. On the tick when a new bar starts, the start time of the new bar changes. Then, until a new bar, this time always remains constant. In this library, all the rough work is done to create the necessary variables to store times for different instruments and periods. The user only needs to apply the IsNewBar() and UpdateNewBar() functions in the right places.

To use it, you need to include the NewBarEvent.mqh library and then:

  1. Necessarily   call the UpdateNewBar() function   at the beginning of OnTick()
  2. Use the function IsNewBar(symbol, timeframe)   to check the occurrence of an event in OnTick()

An example of usage is given below and in the NewBarEventExample.mq5 file.

void OnTick() {
//--- 1. IMPORTANT! Call UpdateNewBar() function at begin of OnTick()
   UpdateNewBar();

//--- 2.1 Check events
   if(IsNewBar(Symbol(), Period()))   { Print("New Bar at " + EnumToString(Period()) + " for " + Symbol()); }
   
   if(IsNewBar("EURGBP", PERIOD_M15)) { Print("New Bar at PERIOD_M15 for EURGBP"); }
   if(IsNewBar("USDCAD", PERIOD_M15)) { Print("New Bar at PERIOD_M15 for USDCAD"); }
   if(IsNewBar("USDCHF", PERIOD_M15)) { Print("New Bar at PERIOD_M15 for USDCHF"); }
   
   if(IsNewBar("EURGBP", PERIOD_H1))  { Print("New Bar at PERIOD_H1  for EURGBP"); }
   if(IsNewBar("USDCAD", PERIOD_H1))  { Print("New Bar at PERIOD_H1  for USDCAD"); }
   if(IsNewBar("USDCHF", PERIOD_H1))  { Print("New Bar at PERIOD_H1  for USDCHF"); }

//--- Perform some actions...
   Sleep(1500);

//--- 2.2 Check events again if needed
   if(IsNewBar(Symbol(), Period()))   { Print("New Bar at " + EnumToString(Period()) + " for " + Symbol() + " second time at the same tick"); }
   
   if(IsNewBar("EURGBP", PERIOD_M15)) { Print("New Bar at PERIOD_M15 for EURGBP second time at the same tick"); }
   if(IsNewBar("USDCAD", PERIOD_M15)) { Print("New Bar at PERIOD_M15 for USDCAD second time at the same tick"); }
   if(IsNewBar("USDCHF", PERIOD_M15)) { Print("New Bar at PERIOD_M15 for USDCHF second time at the same tick"); }
   
   if(IsNewBar("EURGBP", PERIOD_H1))  { Print("New Bar at PERIOD_H1  for EURGBP second time at the same tick"); }
   if(IsNewBar("USDCAD", PERIOD_H1))  { Print("New Bar at PERIOD_H1  for USDCAD second time at the same tick"); }
   if(IsNewBar("USDCHF", PERIOD_H1))  { Print("New Bar at PERIOD_H1  for USDCHF second time at the same tick"); }
}

When running on GBPAUD M30, you can see something like this output

2022.04.01 22:30:00   New Bar at PERIOD_M30 for GBPAUD
2022.04.01 22:30:00   New Bar at PERIOD_M15 for EURGBP
2022.04.01 22:30:00   New Bar at PERIOD_M15 for USDCAD
2022.04.01 22:30:00   New Bar at PERIOD_M15 for USDCHF
2022.04.01 22:30:02   New Bar at PERIOD_M30 for GBPAUD second time at the same tick
2022.04.01 22:30:02   New Bar at PERIOD_M15 for EURGBP second time at the same tick
2022.04.01 22:30:02   New Bar at PERIOD_M15 for USDCAD second time at the same tick
2022.04.01 22:30:02   New Bar at PERIOD_M15 for USDCHF second time at the same tick
2022.04.01 22:45:01   New Bar at PERIOD_M15 for EURGBP
2022.04.01 22:45:01   New Bar at PERIOD_M15 for USDCAD
2022.04.01 22:45:01   New Bar at PERIOD_M15 for USDCHF
2022.04.01 22:45:02   New Bar at PERIOD_M15 for EURGBP second time at the same tick
2022.04.01 22:45:02   New Bar at PERIOD_M15 for USDCAD second time at the same tick
2022.04.01 22:45:02   New Bar at PERIOD_M15 for USDCHF second time at the same tick





Two pending orders 2 Two pending orders 2

Two pending orders at the beginning of the day

At random Full At random Full

The Expert Advisor is a joke: the position is opened randomly. Now there is a Stop Loss, Take Profit and much more

Trailing Stop by Fixed Parabolic SAR Trailing Stop by Fixed Parabolic SAR

Modify to allow direct specification of the starting point of the Parabolic SAR.

Symbol Trade Made Simple With Functions Symbol Trade Made Simple With Functions

This library shows useful informations and do a lot of functions to a symbol.