MT4のGMTオフセット値を自動判定するサンプルmq4

MT4のGMTオフセット値を自動判定するサンプルmq4

最近、「GMT OANDA」「MT4 サマータイム」などのキーワード検索履歴が多いです。

理由は、人気のあるEA「BandCross3 EURUSD」「Forex White Bear V3」が時間処理を採用している関係で
GMTのパラメーターに設定する値を知りたい!という人が多いのかなと思っています。

BandCross3 EURUSD

MT4は、FX会社毎に採用しているMT4のタイムゾーンが異なります。
ですので、日足が5本の会社もあれば、日足が6本の会社もあります。

詳しく知りたい方人は「MT4 日本時間(GMT+9)の残念なチャート」をご覧ください。


運用するMT4に合わせて、GMTを調べたり、米国・欧州サマータイムの日付を調べたり面倒ですよね?
じつは、このGMTのパラメーターに設定する値は、簡単な計算で自動判定することが可能なんです。

GMTオフセット値を自動判定するサンプル関数を作ってみましたのでご覧ください。説明は後述します。
//+------------------------------------------------------------------+
//| GetGMTOffset.mq4 |
//| Copyright 2014, BLT. |
//| http://mt4ordersenderror.blog.fc2.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, BLT."
#property link "http://mt4ordersenderror.blog.fc2.com/"
#property version "1.00"
#property strict
//--- input parameters
input int TestGMTOffset = 3;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
Alert( GetGMTOffset() );
}
//+------------------------------------------------------------------+
//| GetGMTOffset function |
//+------------------------------------------------------------------+
int GetGMTOffset()
{
// バックテストの場合はパラメーター指定の固定値を返却
if ( IsTesting() )
{
return( TestGMTOffset );
}

// 日付処理で使用
MqlDateTime current;
MqlDateTime gmt;

// 補正処理で使用
int offset = 0;

// MT4時刻を取得する
TimeCurrent( current );

// GMT時刻を取得する
TimeGMT( gmt );

// 日付が異なる場合の補正処理
if( ( current.day - gmt.day ) > 0 )
{
offset = 24;
}
if( ( current.day - gmt.day ) < 0 )
{
offset = -24;
}

// GMTOffset値を返却
return ( current.hour - gmt.hour + offset );
}
//+------------------------------------------------------------------+
Build 600 で TimeGMT の関数が追加され、GMT時刻が簡単に取得できるようになりました。
ですので、MT4の時刻とGMTの時刻を取得・比較して、GMTオフセット値を算出しています。

サマータイム時も、MT4側の時刻が自動で変わるため、パラメーターの再設定は不要です。

ただしバックテストをする際は、TimeGMT の挙動が運用時と異なるため
固定でパラメーター指定するなど、バックテスト用の対策が必要になりますのでご注意を。^^
written by BLT
■ Important Matters and Risk Warnings Regarding Investment Products 【Financial Instruments Business Operator】
GogoJungle Inc.
Registration: Director-General of the Kanto Local Finance Bureau (Financial Instruments Business) No. 1960
【Member Association】
Japan Investment Advisers Association
【Fees and Expenses】
The use of software, e-books, investment advisory services, etc., provided on our platform involves purchase prices determined for each product.
Additionally, when conducting actual financial instrument transactions (such as FX or CFD trading), costs such as transaction fees and spreads (the difference between the sell and buy price) may be incurred through the connected brokerage firms.
【Margin and Risk of Loss】
Transactions such as FX (Foreign Exchange Margin Trading) and CFD (Contract for Difference) allow for trading in amounts exceeding the deposited margin.
Therefore, due to sudden fluctuations in target indices (currency, commodity prices, etc.), there is a risk of incurring losses that exceed the deposited margin (loss exceeding principal).
Furthermore, financial instrument transactions involve risks such as price fluctuations, which may result in losses falling below or exceeding the initial investment principal.
【Nature of Services and Trading Entity】
The Company operates a platform (marketplace) providing investment software and information; we do not engage in the buying, selling, mediation, brokerage, or agency of financial instruments on behalf of customers.
The services and information provided are intended as reference for investment decisions and do not guarantee future profits or specific results.
While some services include investment advice, they do not constitute a mandate or solicitation to trade specific financial instruments.
Final investment decisions and the execution of trades must be made at the customer’s own risk and discretion.
GogoJungle Inc.
Registration: Director-General of the Kanto Local Finance Bureau (Financial Instruments Business) No. 1960
Member Association: Japan Investment Advisers Association
GogoJungle Inc.
Registration: Director-General of the Kanto Local Finance Bureau (Financial Instruments Business) No. 1960
Member Association: Japan Investment Advisers Association
Financial Services AgencyJapan Investment Advisers AssociationFinancial Instruments Mediation Assistance CenterSecurities and Exchange Surveillance Commission

Copyright © 2026 GogoJungle Inc. All Rights Reserved.