请求高人帮忙看看。CCI-ZigZag indicator---建立在CCI数据基础上的ZigZag 技术指标。 新评论 zeeda 2017.06.14 17:27 我是MT4的初学者,而且以前没有学过电脑,更不要说编程了。所有关于电脑的知识都是自己摸索出来的,所有,很多地方概念很模糊。在此也恳请大家帮助!先谢谢大家! 我想写一个建立在CCI数据基础上的ZigZag 技术指标。我的思路是:把MT4平台自带的那个ZigZag indicator进行改动,用CCI的数据代替原有的价格数据从而得到一个自己的技术指标。具体做法是:设立一个ExtCCIBuffer[] 并用iCCI给它付值; 然后用ExtCCIBuffer的数据源所替代原ZigZag的价格数据。 可是报错:“’ExtCCIBuffer’ invalid array access”. 可是我自己不知道错在哪里?如何改?。 我把这个indicator发给大家帮我看看。如果这个方法不行的话,能否请人帮我写一个这个indicator? 在这个技术指标中,我需要提取最新的7个拐点的CCI数据,并要知道这7个拐点Bar的序号。 //+------------------------------------------------------------------+ //| ZD-CCI-ZigZag.mq4 | //| | //| | //+------------------------------------------------------------------+ #property copyright "" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 2 #property indicator_plots 2 //--- plot CCI #property indicator_label1 "CCI" #property indicator_type1 DRAW_LINE #property indicator_color1 clrDarkTurquoise #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Zigzag #property indicator_label2 "ExtZigZag" #property indicator_type2 DRAW_LINE #property indicator_color2 clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 1 #property indicator_level1 35.0 #property indicator_level2 65.0 #property indicator_level3 50.0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_DOT //--- indicator buffers double ExtCCIBuffer[]; double ExtZigzagBuffer[]; double ExtHighBuffer[]; double ExtLowBuffer[]; //--- Cci input parameters extern int CCI_Period = 14; extern int CCI_PRICE = PRICE_CLOSE; //---- ZigZag indicator parameters input int InpDepth=6; // Depth input int InpDeviation=5; // Deviation input int InpBackstep=2; // Backstep //---- indicator buffers //--- globals int ExtLevel=3; // recounting's depth of extremums //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { if(InpBackstep>=InpDepth) { Print("Backstep cannot be greater or equal to Depth"); return(INIT_FAILED); } //--- 2 additional buffers IndicatorBuffers(4); //---- indicator buffers SetIndexBuffer(0,ExtCCIBuffer); SetIndexBuffer(1,ExtZigzagBuffer); SetIndexBuffer(2,ExtHighBuffer); SetIndexBuffer(3,ExtLowBuffer); SetIndexEmptyValue(0,0.0); //---- drawing settings SetIndexStyle(0,DRAW_SECTION); SetIndexStyle(1,DRAW_SECTION); //---set close[] ArraySetAsSeries(Close,true); //---Vital Information //---- indicator short name IndicatorShortName("CCIZigZag("+string(InpDepth)+","+string(InpDeviation)+","+string(InpBackstep)+")"); //---- initialization done 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 i,limit,counterZ,Ccilimit,whatlookfor=0; int back,pos,lasthighpos=0,lastlowpos=0; double extremum; double curlow=0.0,curhigh=0.0,lasthigh=0.0,lastlow=0.0; //---set CCI buffers Ccilimit=rates_total-prev_calculated; if (Ccilimit>1) { for(i=0; i<rates_total; i++) { ExtCCIBuffer[i]=iCCI(NULL,0,CCI_Period,PRICE_CLOSE,i); } } else { for(i=0; i<Ccilimit+1; i++) { ExtCCIBuffer[i]=iCCI(NULL,0,CCI_Period,PRICE_CLOSE,i); } //--- check for history and inputs if(rates_total<InpDepth || InpBackstep>=InpDepth) return(0); //--- first calculations if(prev_calculated==0) limit=InitializeAll(); else { //--- find first extremum in the depth ExtLevel or 100 last bars i=counterZ=0; while(counterZ<ExtLevel && i<100) { if(ExtZigzagBuffer[i]!=0.0) counterZ++; i++; } //--- no extremum found - recounting all from begin if(counterZ==0) limit=InitializeAll(); else { //--- set start position to found extremum position limit=i-1; //--- what kind of extremum? if(ExtLowBuffer[i]!=0.0) { //--- low extremum curlow=ExtLowBuffer[i]; //--- will look for the next high extremum whatlookfor=1; } else { //--- high extremum curhigh=ExtHighBuffer[i]; //--- will look for the next low extremum whatlookfor=-1; } //--- clear the rest data for(i=limit-1; i>=0; i--) { ExtZigzagBuffer[i]=0.0; ExtLowBuffer[i]=0.0; ExtHighBuffer[i]=0.0; } } } //--- main loop for(i=limit; i>=0; i--) { //--- find lowest low in depth of bars extremum=Close[iLowest(ExtCCIBuffer,0,MODE_CLOSE,InpDepth,i)]; //--- this lowest has been found previously if(extremum==lastlow) extremum=0.0; else { //--- new last low lastlow=extremum; //--- discard extremum if current low is too high if(close[i]-extremum>InpDeviation*Point) extremum=0.0; else { //--- clear previous extremums in backstep bars for(back=1; back<=InpBackstep; back++) { pos=i+back; if(ExtLowBuffer[pos]!=0 && ExtLowBuffer[pos]>extremum) ExtLowBuffer[pos]=0.0; } } } //--- found extremum is current low if(close[i]==extremum) ExtLowBuffer[i]=extremum; else ExtLowBuffer[i]=0.0; //--- find highest high in depth of bars in ExtCCIBuffer extremum=Close[iHighest(ExtCCIBuffer,0,MODE_CLOSE,InpDepth,i)]; //--- this highest has been found previously if(extremum==lasthigh) extremum=0.0; else { //--- new last high lasthigh=extremum; //--- discard extremum if current high is too low if(extremum-Close[i]>InpDeviation*Point) extremum=0.0; else { //--- clear previous extremums in backstep bars for(back=1; back<=InpBackstep; back++) { pos=i+back; if(ExtHighBuffer[pos]!=0 && ExtHighBuffer[pos]<extremum) ExtHighBuffer[pos]=0.0; } } } //--- found extremum is current high if(Close[i]==extremum) ExtHighBuffer[i]=extremum; else ExtHighBuffer[i]=0.0; } //--- final cutting if(whatlookfor==0) { lastlow=0.0; lasthigh=0.0; } else { lastlow=curlow; lasthigh=curhigh; } for(i=limit; i>=0; i--) { switch(whatlookfor) { case 0: // look for peak or lawn if(lastlow==0.0 && lasthigh==0.0) { if(ExtHighBuffer[i]!=0.0) { lasthigh=Close[i]; lasthighpos=i; whatlookfor=-1; ExtZigzagBuffer[i]=lasthigh; } if(ExtLowBuffer[i]!=0.0) { lastlow=Close[i]; lastlowpos=i; whatlookfor=1; ExtZigzagBuffer[i]=lastlow; } } break; case 1: // look for peak if(ExtLowBuffer[i]!=0.0 && ExtLowBuffer[i]<lastlow && ExtHighBuffer[i]==0.0) { ExtZigzagBuffer[lastlowpos]=0.0; lastlowpos=i; lastlow=ExtLowBuffer[i]; ExtZigzagBuffer[i]=lastlow; } if(ExtHighBuffer[i]!=0.0 && ExtLowBuffer[i]==0.0) { lasthigh=ExtHighBuffer[i]; lasthighpos=i; ExtZigzagBuffer[i]=lasthigh; whatlookfor=-1; } break; case -1: // look for lawn if(ExtHighBuffer[i]!=0.0 && ExtHighBuffer[i]>lasthigh && ExtLowBuffer[i]==0.0) { ExtZigzagBuffer[lasthighpos]=0.0; lasthighpos=i; lasthigh=ExtHighBuffer[i]; ExtZigzagBuffer[i]=lasthigh; } if(ExtLowBuffer[i]!=0.0 && ExtHighBuffer[i]==0.0) { lastlow=ExtLowBuffer[i]; lastlowpos=i; ExtZigzagBuffer[i]=lastlow; whatlookfor=1; } break; } } } //--- done return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int InitializeAll() { ArrayInitialize(ExtZigzagBuffer,0.0); ArrayInitialize(ExtHighBuffer,0.0); ArrayInitialize(ExtLowBuffer,0.0); //--- first counting position return(Bars-InpDepth); } //+--------------------------------------------------------------- 附加的文件: ZD-CCI-ZigZag.mq4 10 kb Returning a Value from the Zig Zag Indicator Zigzag指标 问吧! Xiangdong Guo 2017.06.15 02:02 #1 你这段代码错误太多,而且 ZigZag 是著名的未来指标,参考意义不大,可能感兴趣的人不多。去 “自由职业者” 板块发个任务试试吧。 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
我是MT4的初学者,而且以前没有学过电脑,更不要说编程了。所有关于电脑的知识都是自己摸索出来的,所有,很多地方概念很模糊。在此也恳请大家帮助!先谢谢大家!
我想写一个建立在CCI数据基础上的ZigZag 技术指标。我的思路是:把MT4平台自带的那个ZigZag indicator进行改动,用CCI的数据代替原有的价格数据从而得到一个自己的技术指标。具体做法是:设立一个ExtCCIBuffer[] 并用iCCI给它付值; 然后用ExtCCIBuffer的数据源所替代原ZigZag的价格数据。
可是报错:“’ExtCCIBuffer’ invalid array access”. 可是我自己不知道错在哪里?如何改?。
我把这个indicator发给大家帮我看看。如果这个方法不行的话,能否请人帮我写一个这个indicator? 在这个技术指标中,我需要提取最新的7个拐点的CCI数据,并要知道这7个拐点Bar的序号。
//+------------------------------------------------------------------+
//| ZD-CCI-ZigZag.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property strict
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 2
#property indicator_plots 2
//--- plot CCI
#property indicator_label1 "CCI"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDarkTurquoise
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot Zigzag
#property indicator_label2 "ExtZigZag"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_level1 35.0
#property indicator_level2 65.0
#property indicator_level3 50.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT
//--- indicator buffers
double ExtCCIBuffer[];
double ExtZigzagBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
//--- Cci input parameters
extern int CCI_Period = 14;
extern int CCI_PRICE = PRICE_CLOSE;
//---- ZigZag indicator parameters
input int InpDepth=6; // Depth
input int InpDeviation=5; // Deviation
input int InpBackstep=2; // Backstep
//---- indicator buffers
//--- globals
int ExtLevel=3; // recounting's depth of extremums
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(InpBackstep>=InpDepth)
{
Print("Backstep cannot be greater or equal to Depth");
return(INIT_FAILED);
}
//--- 2 additional buffers
IndicatorBuffers(4);
//---- indicator buffers
SetIndexBuffer(0,ExtCCIBuffer);
SetIndexBuffer(1,ExtZigzagBuffer);
SetIndexBuffer(2,ExtHighBuffer);
SetIndexBuffer(3,ExtLowBuffer);
SetIndexEmptyValue(0,0.0);
//---- drawing settings
SetIndexStyle(0,DRAW_SECTION);
SetIndexStyle(1,DRAW_SECTION);
//---set close[]
ArraySetAsSeries(Close,true);
//---Vital Information
//---- indicator short name
IndicatorShortName("CCIZigZag("+string(InpDepth)+","+string(InpDeviation)+","+string(InpBackstep)+")");
//---- initialization done
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 i,limit,counterZ,Ccilimit,whatlookfor=0;
int back,pos,lasthighpos=0,lastlowpos=0;
double extremum;
double curlow=0.0,curhigh=0.0,lasthigh=0.0,lastlow=0.0;
//---set CCI buffers
Ccilimit=rates_total-prev_calculated;
if (Ccilimit>1)
{
for(i=0; i<rates_total; i++)
{
ExtCCIBuffer[i]=iCCI(NULL,0,CCI_Period,PRICE_CLOSE,i);
}
}
else
{
for(i=0; i<Ccilimit+1; i++)
{
ExtCCIBuffer[i]=iCCI(NULL,0,CCI_Period,PRICE_CLOSE,i);
}
//--- check for history and inputs
if(rates_total<InpDepth || InpBackstep>=InpDepth)
return(0);
//--- first calculations
if(prev_calculated==0)
limit=InitializeAll();
else
{
//--- find first extremum in the depth ExtLevel or 100 last bars
i=counterZ=0;
while(counterZ<ExtLevel && i<100)
{
if(ExtZigzagBuffer[i]!=0.0)
counterZ++;
i++;
}
//--- no extremum found - recounting all from begin
if(counterZ==0)
limit=InitializeAll();
else
{
//--- set start position to found extremum position
limit=i-1;
//--- what kind of extremum?
if(ExtLowBuffer[i]!=0.0)
{
//--- low extremum
curlow=ExtLowBuffer[i];
//--- will look for the next high extremum
whatlookfor=1;
}
else
{
//--- high extremum
curhigh=ExtHighBuffer[i];
//--- will look for the next low extremum
whatlookfor=-1;
}
//--- clear the rest data
for(i=limit-1; i>=0; i--)
{
ExtZigzagBuffer[i]=0.0;
ExtLowBuffer[i]=0.0;
ExtHighBuffer[i]=0.0;
}
}
}
//--- main loop
for(i=limit; i>=0; i--)
{
//--- find lowest low in depth of bars
extremum=Close[iLowest(ExtCCIBuffer,0,MODE_CLOSE,InpDepth,i)];
//--- this lowest has been found previously
if(extremum==lastlow)
extremum=0.0;
else
{
//--- new last low
lastlow=extremum;
//--- discard extremum if current low is too high
if(close[i]-extremum>InpDeviation*Point)
extremum=0.0;
else
{
//--- clear previous extremums in backstep bars
for(back=1; back<=InpBackstep; back++)
{
pos=i+back;
if(ExtLowBuffer[pos]!=0 && ExtLowBuffer[pos]>extremum)
ExtLowBuffer[pos]=0.0;
}
}
}
//--- found extremum is current low
if(close[i]==extremum)
ExtLowBuffer[i]=extremum;
else
ExtLowBuffer[i]=0.0;
//--- find highest high in depth of bars in ExtCCIBuffer
extremum=Close[iHighest(ExtCCIBuffer,0,MODE_CLOSE,InpDepth,i)];
//--- this highest has been found previously
if(extremum==lasthigh)
extremum=0.0;
else
{
//--- new last high
lasthigh=extremum;
//--- discard extremum if current high is too low
if(extremum-Close[i]>InpDeviation*Point)
extremum=0.0;
else
{
//--- clear previous extremums in backstep bars
for(back=1; back<=InpBackstep; back++)
{
pos=i+back;
if(ExtHighBuffer[pos]!=0 && ExtHighBuffer[pos]<extremum)
ExtHighBuffer[pos]=0.0;
}
}
}
//--- found extremum is current high
if(Close[i]==extremum)
ExtHighBuffer[i]=extremum;
else
ExtHighBuffer[i]=0.0;
}
//--- final cutting
if(whatlookfor==0)
{
lastlow=0.0;
lasthigh=0.0;
}
else
{
lastlow=curlow;
lasthigh=curhigh;
}
for(i=limit; i>=0; i--)
{
switch(whatlookfor)
{
case 0: // look for peak or lawn
if(lastlow==0.0 && lasthigh==0.0)
{
if(ExtHighBuffer[i]!=0.0)
{
lasthigh=Close[i];
lasthighpos=i;
whatlookfor=-1;
ExtZigzagBuffer[i]=lasthigh;
}
if(ExtLowBuffer[i]!=0.0)
{
lastlow=Close[i];
lastlowpos=i;
whatlookfor=1;
ExtZigzagBuffer[i]=lastlow;
}
}
break;
case 1: // look for peak
if(ExtLowBuffer[i]!=0.0 && ExtLowBuffer[i]<lastlow && ExtHighBuffer[i]==0.0)
{
ExtZigzagBuffer[lastlowpos]=0.0;
lastlowpos=i;
lastlow=ExtLowBuffer[i];
ExtZigzagBuffer[i]=lastlow;
}
if(ExtHighBuffer[i]!=0.0 && ExtLowBuffer[i]==0.0)
{
lasthigh=ExtHighBuffer[i];
lasthighpos=i;
ExtZigzagBuffer[i]=lasthigh;
whatlookfor=-1;
}
break;
case -1: // look for lawn
if(ExtHighBuffer[i]!=0.0 && ExtHighBuffer[i]>lasthigh && ExtLowBuffer[i]==0.0)
{
ExtZigzagBuffer[lasthighpos]=0.0;
lasthighpos=i;
lasthigh=ExtHighBuffer[i];
ExtZigzagBuffer[i]=lasthigh;
}
if(ExtLowBuffer[i]!=0.0 && ExtHighBuffer[i]==0.0)
{
lastlow=ExtLowBuffer[i];
lastlowpos=i;
ExtZigzagBuffer[i]=lastlow;
whatlookfor=1;
}
break;
}
}
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int InitializeAll()
{
ArrayInitialize(ExtZigzagBuffer,0.0);
ArrayInitialize(ExtHighBuffer,0.0);
ArrayInitialize(ExtLowBuffer,0.0);
//--- first counting position
return(Bars-InpDepth);
}
//+---------------------------------------------------------------