MT5平台开盘价指标-汇有钱途

MT5平台开盘价指标

XM十周年100万美元奖励活动

之前我们给出了使用人工智能AI来编写MT5指标的详细教程,如果你上手有现成的MT5指标源代码,但无法实现你想要的效果,可以把源代码提供给AI,详细给出你的要求,AI基本可以快速实现。同理,如果你有现成的MT5指标源代码,也可以使用AI转变为MT4指标。

我在网上找了很多MT5平台的开盘价指标,结果都不理想。于是我使用Deepseek来修改指标
黄金的多面性

MT5平台开盘价指标源代码如下,编译方法详见:使用人工智能AI来编写MT4/MT5指标

//------------------------------------------------------------------
#property copyright "© mladen, 2017, mladenfx@gmail.com"
#property link "www.fxful.com"
//------------------------------------------------------------------

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "Daily open line"
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_color1 clrGold
#property indicator_width1 1

input int TimeShift = 0; // Time shift (in hours)
double openLine[];
datetime currentDay = 0;
double currentOpen = 0;
//
//
//
//
//

int OnInit()
{
SetIndexBuffer(0, openLine, INDICATOR_DATA);
PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);
PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);

// 设置空值显示方式,确保不同交易日之间的线不连接
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);

return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime& time[],
const double& open[],
const double& high[],
const double& low[],
const double& close[],
const long& tick_volume[],
const long& volume[],
const int& spread[])
{
if (Bars(_Symbol, _Period) < rates_total)
return(-1);

// 从0开始或重新计算所有
int start = (prev_calculated <= 1) ? 0 : prev_calculated - 1;

for (int i = start; i < rates_total && !IsStopped(); i++)
{
datetime barTime = time[i] + TimeShift * 3600;
MqlDateTime dt;
TimeToStruct(barTime, dt);

// 获取当前K线的日期(不考虑时间部分)
datetime barDate = StructToTime(dt.year, dt.mon, dt.day, 0, 0, 0);

if (i == 0 || barDate != currentDay)
{
// 新的一天开始
currentDay = barDate;
currentOpen = open[i];
openLine[i] = currentOpen;
}
else
{
// 同一天内,保持开盘价
openLine[i] = currentOpen;
}
}

// 确保不同交易日之间的线不连接
// 在交易日结束时设置空值
for (int i = 1; i < rates_total; i++)
{
datetime time1 = time[i-1] + TimeShift * 3600;
datetime time2 = time[i] + TimeShift * 3600;

MqlDateTime dt1, dt2;
TimeToStruct(time1, dt1);
TimeToStruct(time2, dt2);

datetime date1 = StructToTime(dt1.year, dt1.mon, dt1.day, 0, 0, 0);
datetime date2 = StructToTime(dt2.year, dt2.mon, dt2.day, 0, 0, 0);

if (date1 != date2)
{
// 交易日变化,在前一根K线后设置空值
openLine[i-1] = EMPTY_VALUE;
}
}

return(rates_total);
}

// 辅助函数:从日期组件创建时间
datetime StructToTime(int year, int month, int day, int hour=0, int minute=0, int second=0)
{
MqlDateTime dt;
dt.year = year;
dt.mon = month;
dt.day = day;
dt.hour = hour;
dt.min = minute;
dt.sec = second;
return StructToTime(dt);
}

本文由 汇有钱途 作者:admin 发表,其版权均为 汇有钱途 所有,文章内容系作者个人观点,不代表 汇有钱途 对观点赞同或支持。如需转载,请注明文章来源。

发表评论