下载MetaTrader 5
要添加评论,请登录注册
找出讨论最多的论坛主题。在看板部分查看
xr
16
xr 2009.08.10 15:34 

想得到如上图中macd最近三次交叉点的k线位置c, b, a ?自己写了一些代码可运行结果是错的。不知道哪里错了,请指教!谢谢

#include <stdlib.mqh>
#include <WinUser32.mqh>
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
int macd[];
double buffer1[];
double buffer2[];
double MacdCurrent,SignalCurrent,MacdPrevious,SignalPrevious;
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,3);
SetIndexArrow(0,233);
SetIndexBuffer(0,buffer1);

SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,3);
SetIndexArrow(1,234);
SetIndexBuffer(1,buffer2);
return(0);
}


int start()
{

int j=0;
int i=0;
MacdCurrent=0.0;
SignalCurrent=0.0;
MacdPrevious=0.0;
SignalPrevious=0.0;
while (j<3)
{
MacdCurrent=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_MAIN,i);
SignalCurrent=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_SIGNAL,i);
MacdPrevious=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_MAIN,i+1);
SignalPrevious=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_SIGNAL,i+1);

if((MacdCurrent > SignalCurrent &&MacdPrevious<SignalPrevious)
||(MacdCurrent < SignalCurrent &&MacdPrevious>SignalPrevious))
{
macd[j]=i;
j=j+1;
}
i++;
}

Comment(macd[0]," : ",macd[2]," : ",macd[3]);

return (0);
}

okwh
1630
okwh 2009.08.11 16:00  

用Print检查

chenkui
24
chenkui 2009.08.12 03:26  
至少这里有问题:while (j<3) ,还有就是整体代码结构所表现的功能不是你想要得到的“如上图中macd最近三次交叉点的k线位置c, b, a”
xr
16
xr 2009.08.15 02:45  


10

EA111111
35
EA111111 2009.08.15 08:50  
xrday 写道 >>

想得到如上图中macd最近三次交叉点的k线位置c, b, a ?自己写了一些代码可运行结果是错的。不知道哪里错了,请指教!谢谢

#include <stdlib.mqh>
#include <WinUser32.mqh>
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
int macd[];
double buffer1[];
double buffer2[];
double MacdCurrent,SignalCurrent,MacdPrevious,SignalPrevious;
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,3);
SetIndexArrow(0,233);
SetIndexBuffer(0,buffer1);

SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,3);
SetIndexArrow(1,234);
SetIndexBuffer(1,buffer2);
return(0);
}


int start()
{

int j=0;
int i=0;
MacdCurrent=0.0;
SignalCurrent=0.0;
MacdPrevious=0.0;
SignalPrevious=0.0;
while (j<3)
{
MacdCurrent=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_MAIN,i);
SignalCurrent=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_SIGNAL,i);
MacdPrevious=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_MAIN,i+1);
SignalPrevious=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_SIGNAL,i+1);

if((MacdCurrent > SignalCurrent &&MacdPrevious<SignalPrevious)
||(MacdCurrent < SignalCurrent &&MacdPrevious>SignalPrevious))
{
macd[j]=i;
j=j+1;
}
i++;
}

Comment(macd[0]," : ",macd[2]," : ",macd[3]);

return (0);
}

最后这个怎么改啦,完整代码贴一下呀

xr
16
xr 2009.08.16 16:53  

#include <stdlib.mqh>
#include <WinUser32.mqh>
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
int macd[4];////原来没有4这里加上指定原来数组宽度,这是原来码子不正确的主要原因
double buffer1[];
double buffer2[];
double MacdCurrent,SignalCurrent,MacdPrevious,SignalPrevious;
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,3);
SetIndexArrow(0,233);
SetIndexBuffer(0,buffer1);

SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,3);
SetIndexArrow(1,234);
SetIndexBuffer(1,buffer2);
return(0);
}


int start()
{

int j=0;
int i=0;
MacdCurrent=0.0;
SignalCurrent=0.0;
MacdPrevious=0.0;
SignalPrevious=0.0;
while (j<4)
{
MacdCurrent=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_MAIN,i);
SignalCurrent=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_SIGNAL,i);
MacdPrevious=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_MAIN,i+1);
SignalPrevious=iMACD(NULL,0,8,21,5,PRICE_CLOSE,MODE_SIGNAL,i+1);

if((MacdCurrent > SignalCurrent &&MacdPrevious<SignalPrevious)
||(MacdCurrent < SignalCurrent &&MacdPrevious>SignalPrevious))
{
macd[j]=i;
j=j+1;
}
i++;
}

Comment(macd[0]," : ",macd[2]," : ",macd[3]);

return (0);
}

////上面就是问题得到解决的完整代码。。。当然这个思路想再怎么用是你的自己的交易思路问题了

/
要添加评论,请登录注册