供需指标(Supply and Demand ),供给与需求,寻找支撑压力位神器 MT4免费公式!
指标名称:自动交易时段
版本:MT4 ver. 6.02
自动交易时段是一款用于自动标记和管理不同金融市场交易时段的软件工具。它能够帮助交易者识别各大市场(如纽约、伦敦、东京和悉尼)的开盘和收盘时间,从而更好地规划交易策略和时间。
功能特点:
-
多市场识别:自动识别并显示最多五个不同的交易市场时段。
-
高亮显示:交易时段将以不同颜色高亮显示,便于用户快速识别当前活跃市场。
-
时间校准:根据用户的地理位置调整市场开闭市时间,确保时间显示的准确性。
-
用户自定义:用户可以自定义要显示的市场、颜色及其他显示设置。
-
实时更新:软件将根据市场变动实时更新交易时段的开始和结束时间。
参数说明:
sinput ENUM_TimeMethod TimeMethod = Broker_Eastern_Offset
默认使用经纪商东部时间偏移方式来确定交易时段的开始和结束时间。
sinput int BrokerEasternOffset 设置经纪商的东部时间偏移量,默认为7。
Manual_SessionBegins 手动设置每个交易时段的开始时间。
Manual_SessionEnds 手动设置每个交易时段的结束时间。
sinput string SessionNames = SESS_NAMES_DEFAULT
可以自定义设置显示的交易时段名称。
sinput color Color1 = clrBlue
第一个交易时段的显示颜色为蓝色。
sinput ENUM_SessionStyle Style1 = Rectangle_Fill
第一个交易时段的显示风格为填充矩形。
sinput bool PipsRounded = true
是否对显示的点数进行四舍五入。
sinput bool PipsWord = false
是否在点数后添加“pips”文字说明。
用户可以通过修改参数来自定义指标的显示风格和行为,如调整时间偏移、选择显示的交易时段、改变颜色和风格等。
所有设置都可以在MetaTrader平台的指标设置界面中进行调整。
该指标非常适合需要关注多个交易时段开闭市时间的交易者,帮助他们更好地把握交易机会。
// +--------------------------------------------------------------------+
// | 自动交易时段 |
//|
//+------------------------------------------------------------------+
#property version "6.02"
#property description "---------------------------------------------"
#property description "EA、指标公式分享"
#property description "EA、
#property description "---------------------------------------------"
#property description "---------------------------------------------"
#property indicator_chart_window
#property indicator_buffers 0
//#property indicator_color1 clrNONE //CornflowerBlue
#define PROPERTY_DESCRIPTION_1 "高亮显示交易时段"
#define PROPERTY_DESCRIPTION_2 " "
#define PROPERTY_DESCRIPTION_3 "最多显示5个不同的交易时段"
#ifdef __MQL4__
#define MQL4(x) x
#else
#define MQL4(x)
#endif
//#ifdef __MQL5__
//#define MQL5(x) x
//#else
//#define MQL5(x)
//#endif
#define DEBUG 0 // #define DEBUG 1 // Print useful info in the Experts tab.
#define DbugInfo(x) x // define as x for informational debugging 4
#define INPUTVARDELIMITER "================================"
#define ONEHOURsecs 3600 // 1 hour in seconds
#define ONEDAYsecs 86400 // 1 day in seconds
#define ONEDAYmins 1440 // 1 day in minutes
#define NAMEPIPDELIMITER " " // String between Session Name and Session Pips
#define NAMEPIPMARGIN " " // Pad the Session Text with this string
#define REASON_USER_INIT 2021 // Custom OnDeinit() reason
#define WINMAXVAL 1.5 //100.0 // Sufficiently large Window Minimum/Maximum that will ever be visible during whole Timeseries scroll
// June 2021 MT5 version didn't display objects when 10000.0 and above
#define MAX_SESSIONS 5 // This should be equal to the number of input colors and >= the number of sessions in $SESS_NAMES_DFAULT
#define SESS_NAMES_DEFAULT "Sydney/Tokyo/Frankfurt/London/NY" // These should all be unique.
// enum eTimeMethod {Broker_Eastern_offset, Broker_GMT_offset, Manual};
enum ENUM_TimeMethod { Broker_Eastern_Offset, // Broker Eastern Time Zone Offset
Manual // Manual Input of Start and End Times
};
enum ENUM_SessionStyle { Rectangle_Fill, // Filled Rectangle
Rectangle_Line, // Line Bordered Rectangle
Vertical_Fill, // Filled Vertical
Vertical_Lines, // Vertical Lines, Begin and End
Vertical_Line_Begin, // Vertical Line, Begin
Vertical_Line_End, // Vertical Line, End
Vertical_Fill_All, // Filled Vertical in all Sub-Windows
Vertical_Lines_All, // Vertical Lines in all Sub-Windows, Begin and End
Vertical_Lines_All_Begin, // Vertical Lines in all Sub-Windows, Begin
Vertical_Lines_All_End, // Vertical Lines in all Sub-Windows, End
Horizontal_Lines, // Horizontal Lines, High and Low
Horizontal_Line_High, // Horizontal Line, High
Horizontal_Line_Low // Horizontal Line, Low
};
enum ENUM_LineType { VLine_Begin, VLine_End, HLine_High, HLine_Low };
enum ENUM_YESNO
{
YES,
NO,
};
sinput string SessionNames = SESS_NAMES_DEFAULT; // Session Names
sinput string ShowSessions = "1/0/0/1/1"; // Show Sessions
sinput string ShowNames = "1/0/0/1/1"; // Show Session Names
sinput string ShowPips = "1/0/0/1/1"; // Show Session Pips
sinput ENUM_TimeMethod TimeMethod = Broker_Eastern_Offset; // Time Method
sinput string __OffsetNote = "..exactly *5* sessions above."; // Note: If Using Eastern Time Zone Offset...
sinput int BrokerEasternOffset = 7; // Broker Eastern Time Zone Offset
// sinput int BrokerGMTOffset = 3;
sinput string Manual_SessionBegins = "00:00:00/02:00:00/09:00:00/10:00:00/14:00:00"; // Manual Session Begin Times
sinput string Manual_SessionEnds = "08:59:59/10:59:59/17:59:59/18:59:59/23:59:59"; // Manual Session End Times
// Sessions
sinput string Note_SessionSelections = INPUTVARDELIMITER; // Individual Session Options
sinput color Color1 = clrBlue; // Session 1 Color
sinput ENUM_SessionStyle Style1 = Rectangle_Fill; // Session 1 Style
sinput color Color2 = clrRed; // Session 2 Color
sinput ENUM_SessionStyle Style2 = Rectangle_Fill; // Session 2 Style
sinput color Color3 = clrOrange; // Session 3 Color
sinput ENUM_SessionStyle Style3 = Rectangle_Fill; // Session 3 Style
sinput color Color4 = clrGreen; // Session 4 Color
sinput ENUM_SessionStyle Style4 = Rectangle_Fill; // Session 4 Style
sinput color Color5 = clrGray; // Session 5 Color
sinput ENUM_SessionStyle Style5 = Rectangle_Fill; // Session 5 Style
// Common Session Variables
sinput string Note_CommonSessionSelections = INPUTVARDELIMITER; // Common Session Options
//sinput ENUM_SessionStyle SessionStyle = Rectangle_Fill; // Session Style
sinput int LineWidth = 1; // Line Width
sinput ENUM_LINE_STYLE LineStyle = STYLE_SOLID; // Line Style
sinput color SessionTextColor = clrGoldenrod; // Session Name/Pip Text Colot
sinput string SessionTextFont = "Arial Bold"; // Session Name/Pip Text Font
sinput int SessionTextFontSize = 9; // Session Name/Pip Text Font Size
sinput ENUM_BASE_CORNER SessionTextBaseCorner = CORNER_LEFT_UPPER; // Session Name/Pip Text Base Corner
sinput ENUM_ANCHOR_POINT SessionTextAnchorPoint = ANCHOR_LEFT_UPPER; // Session Name/Pip Text Anchor Point
sinput bool PipsRounded = true; // Round Off Pip Values?
// ^ Round to nearest pip? If not, display to as many points as the broker gives.
sinput bool PipsWord = false; // Display " pips" After Pip Value?
// Common Session Variables
sinput string Note_IndicatorSelections = INPUTVARDELIMITER; // Indicator Options
sinput ENUM_TIMEFRAMES MinTimeframe = PERIOD_M1; // Minimum Timeframe to Display Sessions
sinput ENUM_TIMEFRAMES MaxTimeframe = PERIOD_H1; // Maximum Timeframe to Display Sessions
sinput int MaxBars = 1440; // Max Bars to Use
// Session Open Price lines
sinput string Note_OpenLinesSelections = INPUTVARDELIMITER; // Open Lines Options
sinput ENUM_YESNO Plot_Open_Lines = YES; // Plot Opem levels?
sinput color SessLineColor = clrDarkOrange; // Open lines color
sinput ENUM_LINE_STYLE SessLineStyle = STYLE_SOLID; // Open lines style
sinput int SessLineLineWidth = 4; // Open lines width
sinput ENUM_YESNO LinesInForeground = YES; // Lines on foreground?
sinput ENUM_YESNO SessNameOnLine = YES; // Session name on Open Line?
const string asEASTERN_BEGINS[MAX_SESSIONS] = {"17:00:00", "19:00:00", "02:00:00", "03:00:00", "08:00:00"};
const string asEASTERN_ENDS [MAX_SESSIONS] = {"01:59:59", "03:59:59", "10:59:59", "11:59:59", "16:59:59"};
// const string asGMT_BEGINS[MAX_SESSIONS] = {"21:00", "23:00", "06:00", "07:00", "12:00"};
// const string asGMT_ENDS [MAX_SESSIONS] = {"06:00", "08:00", "15:00", "16:00", "21:00"};
string gsObjectPrefix; // For unique Object Names with multiple indicators
int giNSessions; // Number of Sessions to Display
string gasNames [MAX_SESSIONS]; // Session Name
bool gabShowSess [MAX_SESSIONS], // Show Session?
gabShowName [MAX_SESSIONS], // Show Session Text with Session Name
gabShowPips [MAX_SESSIONS]; // Show Session Text with Session Pips range value
color gaoColors [MAX_SESSIONS]; // Session Color
ENUM_SessionStyle gaeStyles [MAX_SESSIONS]; // Session Style
datetime galTimeBeginSecs [MAX_SESSIONS], // Session Begin in seconds, Date portion is 0000.00.00
galTimeEndSecs [MAX_SESSIONS]; // Session End in seconds, Date portion is 0000.00.00
//
int OnInit(void)
{
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " { "); )
long lChartWinHandl;
string sExeName;
IndicatorDigits(Digits-Digits%2);
sExeName = MQLInfoString(MQL_PROGRAM_NAME);
ChartGetInteger(0, CHART_WINDOW_HANDLE, 0, lChartWinHandl);
gsObjectPrefix = StringConcatenate("AutoSess22,145[",(string)TimeMethod,">",(string)BrokerEasternOffset,">",(string)MaxBars,"]"); //StringFormat("%s %lld", sExeName, lChartWinHandl); //Comment( gsObjectPrefix );
//---
IndicatorShortName(gsObjectPrefix);
// Check to display on this timframe. Return SUCCEEDED now, can be switched to an allowed range later
if((PeriodSeconds(PERIOD_CURRENT) < PeriodSeconds(MinTimeframe)) || (PeriodSeconds(PERIOD_CURRENT) > PeriodSeconds(MaxTimeframe)))
{
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " return(INIT_PARAMETERS_INCORRECT) "); )
return(INIT_SUCCEEDED); // Return SUCCEEDED now, can be switched to an allowed range later
}
giNSessions = StringSplitMax(SessionNames, '/', gasNames, MAX_SESSIONS); // Get sessions info.
if(!StringsUnique(gasNames, giNSessions)) // Ensure no duplicate session names, for the object names, otherwise use defaults
giNSessions = StringSplitMax(SESS_NAMES_DEFAULT, '/', gasNames, MAX_SESSIONS);
if(DEBUG)
Print("giNSessions=", giNSessions);
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " giNSessions= ", giNSessions); )
ArrayInitialize(gabShowSess, true);
StringSplitMaxBool(ShowSessions, '/', gabShowSess, giNSessions);
ArrayInitialize(gabShowName, true);
StringSplitMaxBool(ShowNames, '/', gabShowName, giNSessions);
ArrayInitialize(gabShowPips, true);
StringSplitMaxBool(ShowPips, '/', gabShowPips, giNSessions);
BuildSessionTimes();
gaoColors[0] = Color1;
gaoColors[1] = Color2;
gaoColors[2] = Color3;
gaoColors[3] = Color4;
gaoColors[4] = Color5;
gaeStyles[0] = Style1;
gaeStyles[1] = Style2;
gaeStyles[2] = Style3;
gaeStyles[3] = Style4;
gaeStyles[4] = Style5;
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " } "); )
return(INIT_SUCCEEDED);
} // OnInit()
//
int OnCalculate(const int rates_total, // size of input time series
const int prev_calculated, // bars handled in previous call
const datetime& time[], // Time
const double& open[], // Open
const double& high[], // High
const double& low[], // Low
const double& close[], // Close
const long& tick_volume[], // Tick Volume
const long& volume[], // Real Volume
const int& spread[]) // Spread
{
bool bResult;
int giS, iBr, iStartCalcAt, iLimit, iBarSessionBegin, iBarSessionEnd;
datetime dtOldest = 0, dtNewest = 0, dtCalled = TimeLocal(), dtExit, dtSessionBegin, dtSessionEnd;
double dHighest, dLowest, dOpen;
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ", TimeToString(dtCalled, TIME_SECONDS),
// ", rates_total=", rate s_total, ", prev_calculated=", prev_calculated); )
if((PeriodSeconds(PERIOD_CURRENT) < PeriodSeconds(MinTimeframe)) || (PeriodSeconds(PERIOD_CURRENT) > PeriodSeconds(MaxTimeframe)))
return(rates_total); // Inactive Timeframe now (Can be switched to an allowed Timeframe later)
bResult = ArraySetAsSeries(time, true);
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ArraySetAsSeries(time) ", bResult); )
bResult = ArraySetAsSeries(high, true);
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ArraySetAsSeries(high) ", bResult); )
bResult = ArraySetAsSeries(low, true);
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ArraySetAsSeries(low) ", bResult); )
/* int iSize = ArraySize(time);
DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ArraySize(time) = ", iSize, " vs ", rates_total); )
iSize = ArraySize(high);
DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ArraySize(high) = ", iSize, " vs ", rates_total); )
iSize = ArraySize(low);
DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ArraySize(low) = ", iSize, " vs ", rates_total); ) */
if(rates_total > 0)
{
dtOldest = time[(rates_total > 0) ? (rates_total - 1) : 0];
dtNewest = time[0];
}
// Set iStartCalcAt to the first (oldest) spot of the bars available, while respecting the MaxBars setting
iStartCalcAt = rates_total - prev_calculated;
if(iStartCalcAt > MaxBars)
iStartCalcAt = MaxBars;
if(iStartCalcAt > 0) // Subtract one as array index, but process at least the [0] bar otherwise
iStartCalcAt--;
for(giS = 0; giS < giNSessions; giS++)
{
if(! gabShowSess[giS]) // Skip unselected Sessions
continue;
// Set iLimit to the first (oldest) spot of the bars available, or picking up at the last spot processed for the Session.
iLimit = iStartCalcAt;
// DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ", gasNames[giS], " Session ",
// TimeToString(galTimeBeginSecs[giS], TIME_MINUTES), " - ",
// TimeToString(galTimeEndSecs [giS], TIME_MINUTES) ); )
for(iBr = 0; iBr <= iLimit; iBr++) // Process newest to oldest, assuming most recent bars are most likely visible
{
if(((dtSessionBegin = GetSessionBegin(galTimeBeginSecs[giS], galTimeEndSecs[giS], time[iBr])) < 0) ||
((dtSessionEnd = GetSessionEnd(galTimeBeginSecs[giS], galTimeEndSecs[giS], time[iBr])) < 0))
{
/* DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ", gasNames[giS], " Skip (", iBr, ") ",
TimeToString(time[iBr], TIME_DATE|TIME_MINUTES), " ! ",
TimeToString(galTimeBeginSecs[giS], TIME_SECONDS), " - ",
TimeToString(galTimeEndSecs [giS], TIME_SECONDS)); ) */
continue;
}
iBarSessionBegin = GetBeginBar(dtSessionBegin, dtSessionEnd, iBr, time, (rates_total > 0) ? (rates_total - 1) : 0);
iBarSessionEnd = GetEndBar(dtSessionBegin, dtSessionEnd, iBr, time, 0);
dHighest = HighestPrice(high, iBarSessionBegin, iBarSessionEnd);
dLowest = LowestPrice(low, iBarSessionBegin, iBarSessionEnd);
dOpen = iOpen(_Symbol,_Period,iBarSessionBegin);
/* DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__, " ", gasNames[giS],
" Draw (", iBr, ",", iBarSessionBegin, ",", iBarSessionEnd, ") ",
TimeToString(time[iBr], TIME_DATE|TIME_MINUTES), ", (",
time[iBarSessionBegin], " - ", time[iBarSessionEnd], ", highest= ",
DoubleToString(dHighest, _Digits), ", lowest= ", DoubleToString(dLowest, _Digits), ")"); ) */
DrawSession(gasNames[giS], gaoColors[giS], gaeStyles[giS], gabShowName[giS], gabShowPips[giS],
time[iBarSessionBegin], time[iBarSessionEnd], dHighest, dLowest, dOpen);
if(Plot_Open_Lines==YES)
HLINE(gsObjectPrefix+gasNames[giS]+" Open level"+iBr,dOpen,dOpen,time[iBarSessionBegin],time[iBarSessionEnd],SessLineColor,SessLineStyle,SessLineLineWidth);
iBr = iBarSessionBegin;
}
}
ChartRedraw(); // Per ChartRedraw() documentation, Usually it is used after changing the object properties.
dtExit = TimeLocal();
/* DbugInfo( Print(__FILE__, " ", __FUNCTION__, "@", __LINE__,
" rates_total= ", rates_total, " (", TimeToString(dtOldest, TIME_DATE|TIME_SECONDS), ")",
", prev_calculated= " , prev_calculated, " (", TimeToString(dtNewest, TIME_DATE|TIME_SECONDS), ") <",
TimeToString(dtCalled, TIME_SECONDS), "-", TimeToString(dtExit, TIME_SECONDS), "> Elapsed= ",
TimeToString(dtExit - dtCalled, TIME_SECONDS)); ) */
return(rates_total);
} // OnCalculate()