• 新添加量子混沌系统板块,欢迎大家访问!---“量子混沌系统”
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏我们吧

自动交易时段,不同交易时段自动标记+开盘价划线 MT4免费公式!

指标下载 qchaos.009 3个月前 (11-08) 6594 复制链接

指标名称:自动交易时段

版本:MT4 ver. 6.02

自动交易时段是一款用于自动标记和管理不同金融市场交易时段的软件工具。它能够帮助交易者识别各大市场(如纽约、伦敦、东京和悉尼)的开盘和收盘时间,从而更好地规划交易策略和时间。

自动交易时段,不同交易时段自动标记+开盘价划线 MT4免费公式!

功能特点:

  • 多市场识别:自动识别并显示最多五个不同的交易市场时段。
  • 高亮显示:交易时段将以不同颜色高亮显示,便于用户快速识别当前活跃市场。
  • 时间校准:根据用户的地理位置调整市场开闭市时间,确保时间显示的准确性。
  • 用户自定义:用户可以自定义要显示的市场、颜色及其他显示设置。
  • 实时更新:软件将根据市场变动实时更新交易时段的开始和结束时间。

自动交易时段,不同交易时段自动标记+开盘价划线 MT4免费公式!

参数说明:

自动交易时段,不同交易时段自动标记+开盘价划线 MT4免费公式!

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平台的指标设置界面中进行调整。

该指标非常适合需要关注多个交易时段开闭市时间的交易者,帮助他们更好地把握交易机会。

部分代码展示:

// +——————————————————————–+
// | 自动交易时段 |
//| Copyright © 2009-2024, http://www.QChaos.com |
//| https://www.qchaos.com/ |
//+——————————————————————+

property copyright "Copyright © 量化混沌, http://www.qchaos.com"

property link "https://www.qchaos.com"

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()


量子混沌 , 版权所有丨如未注明 , 均为原创
转载请注明原文链接:自动交易时段,不同交易时段自动标记+开盘价划线 MT4免费公式!