Watch how to download trading robots for free
Find us on Twitter!
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

NyTime - broker server time to New York time with US and EU daylight saving - library for MetaTrader 5

Augusto Martin D'anna
Augusto Martin D'anna
MQL5 & Pine Script developer | Trader since 2019 | Strategy validation
As a trader, I know a bot is only as good as the logic behind it. I bridge
trading concepts and clean code: I don't just follow instructions, I make
sure your EA behaves exactly the way your strategy intends.
Views:
25
Published:
cb_nytime.png (31.08 KB)
\MQL5\Include\
NyTime.mqh (4.3 KB) view
\MQL5\Scripts\
NyTimeDemo.mq5 (2.09 KB) view
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

NyTime.mqh converts broker server time to UTC and to New York time, with the US and European daylight saving rules. Session filters like "trade 09:30-11:00 New York" usually rely on TimeGMT(), but in the Strategy Tester TimeGMT() returns the server time, so the filter is shifted in backtests. Here you declare the server clock once and every conversion is computed from the calendar, live and in the tester.

Functions

  • ServerToUtc(srv, clock) , UtcToServer(utc, clock)
  • UtcToNy(utc) , NyToUtc(ny)
  • NyTimeFromServer(srv, clock) , ServerTimeFromNy(ny, clock)
  • IsUsSummer(utc) , IsEuSummer(utc)
  • NyMinute(ny) (minutes after 00:00 New York), NyMinuteNow(clock) , NyDayNumber(ny) , NyIsWeekday(ny)

Server clocks

  • CLOCK_NY7: New York + 7 (00:00 server = 17:00 New York), the most common one
  • CLOCK_EU: Central Europe (UTC+1, summer UTC+2)
  • CLOCK_EET: Eastern Europe (UTC+2, summer UTC+3, European dates)
  • CLOCK_UTC, and CLOCK_AUTO from TimeGMT() (live only)

Example

#include <NyTime.mqh> if(NyMinuteNow(CLOCK_NY7) >= 9 * 60 + 30) // after 09:30 New York ...

NyTimeDemo.mq5 prints the New York time of the current server time and runs self-checks, including the March week when US summer time has started and European summer time has not (the case that breaks fixed-offset filters). All checks pass live and in the Strategy Tester.

News Day Blocker - no new trades on US CPI and FOMC days News Day Blocker - no new trades on US CPI and FOMC days

Blocks new trades on US CPI and FOMC days (New York date). Built-in calendar 2015-2027, works in the Strategy Tester. Never opens trades.

No Hedge Guard - close the newer side when a buy and a sell are open on one symbol No Hedge Guard - close the newer side when a buy and a sell are open on one symbol

Closes the newer side when a buy and a sell are open on the same symbol (manual trades or any EA). For prop firm accounts that forbid hedging. Never opens trades.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.