MT5里:
任何能画在图表上的东西,最终都必须绑定到 Indicator Buffer
这个Buffer本质上就是 double[]
int只是“句柄(handle)”,不是数据
你只需要:把你的double[]绑定成Indicator Buffer
① 声明指标 + buffer
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_width1 2
double MyBuffer[];
② 绑定 buffer(这是核心)
int OnInit()
{
SetIndexBuffer(0, MyBuffer, INDICATOR_DATA);
PlotIndexSetString(0, PLOT_LABEL, "My Custom Line");
return(INIT_SUCCEEDED);
}
③ 在 OnCalculate 里填你的数组
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[]
)
{
int start = prev_calculated > 0 ? prev_calculated - 1 : 0;
for(int i = start; i < rates_total; i++)
{
// 假设这是你自己算出来的价格
MyBuffer[i] = (high[i] + low[i]) / 2.0;
}
return(rates_total);
}
|