iDeMarker 句柄当值用 副图一条水平线 改完右边还差一截
iDeMarker 官方说在 OnInit 建句柄就行,我把返回值直接给了个 double 变量去画副图,结果一条水平线换周期都不动。后来才明白给的是句柄不是值,得在 OnCalculate 里 CopyBuffer 往回取,取 0 才是没收盘那根。改完线出来了,右边总差一截,估计是 CopyBuffer 直接往 SetIndexBuffer 绑过的数组里灌,把数组长度改了。代码贴下面,懂的看下。
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "DeMarker"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDodgerBlue
double ExtDEM[];
int hDEM;
int OnInit()
{
SetIndexBuffer(0,ExtDEM,INDICATOR_DATA);
hDEM=iDeMarker(_Symbol,_Period,14);
if(hDEM==INVALID_HANDLE) return(INIT_FAILED);
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[])
{
int start=(prev_calculated<=0)?14:prev_calculated-1;
CopyBuffer(hDEM,0,0,rates_total-start,ExtDEM);
return(rates_total);
}全部回复(19)
发表回复
请先登录后再回复。
