Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Libraries | Same H4 and D1 candles on every broker - NY close candles from H1 | MQL5 Code

Explore the latest free tools from the MQL5 community. Here's a new indicator, expert advisor, or script for MetaTrader.

A D1 or H4 candle starts at a different moment on a UTC+0 server than on a UTC+2 server. So a moving average or ATR on H4/D1 gives other values, and the same EA trades differently from broker to broker. Most gold and forex brokers run on New York close (UTC+2, UTC+3 while the US is on summer time), but not all of them.

This include builds the big candles itself from H1 bars, always on the New York close clock. On a NY close broker the candles are the same as the MT5 ones. On any other broker you get the candles you would see on a NY close broker.

LS_ClockInit(setting, fixedUtc) detects the server clock:

Trade the powerful Traders Dynamic Index strategy automatically with this dedicated TDI Expert Advisor. More details.

  • live from TimeTradeServer() - TimeGMT(), rounded to hours
  • in the strategy tester TimeGMT() is not usable, there you choose the clock (default NY close)
  • knows NY close, UTC+2/+3 with EU summer time, Central Europe UTC+1/+2 and any fixed offset
LS_NYBars bars;
bars.Init(_Symbol, PERIOD_D1);   // OnInit, loads the H1 history
if(bars.Update()) { ... }        // OnTick, true when a candle has just closed
bars.Close(1), bars.High(1) ...  // shift 1 = last closed candle
bars.TimeNY(1)                   // open time on the NY clock
bars.Closes(arr, 200)            // closes as array for your own indicator code

Works for H2, H3, H4, H6, H8, H12 and D1. Only H1 bars that really exist go into a candle, weekends and holidays are not filled. A candle counts as closed when the first H1 bar of the next one opens.

The demo EA opens no trades. It prints the detected clock, the last broker candles next to the NY close candles, and one line every time a new one closes. The screenshot: the same XAUUSD tick data once on a NY close server and once on a CET server (tester). On the CET server the MT5 H4 candles are different, the candles from LS_NYBars match the NY close server (the small rest is the different spread of the two test symbols).

Image for Same H4 and D1 candles on every broker - NY close candles from H1

Level up your trading with professional RobotFX expert advisors and indicators. Visit robotfx.org for proven MT4/MT5 tools.

80234

Best MetaTrader Indicators + Profitable Expert Advisors