2楼
搞了两天了,都没能弄好,请哪位高手帮忙把macd指标的两个数据(value,signal)装到
double ind_buffer1;
double ind_buffer2;
进程:开户->理性分析师->理性投注师
发表于:2008-06-29 13:47只看该作者
3楼
ind_buffer1[t]=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,t);
ind_buffer2[t]=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,t);
ind_buffer3[t]=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,t)-iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,t);
[ 本帖最后由 秃鹫 于 2008-6-29 21:49 编辑 ]
4楼
高手就是高手,马上调试。谢
进程:开户->理性分析师->理性投注师
5楼
还是得不到想要的结果。
请看看代码有没有错。
code]
//+------------------------------------------------------------------+
//| Custom MACD.mq4 |
//| Copyright ?2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_buffers 4 //显示缓存最高8
/*
#property indicator_color1 Blue
#property indicator_color2 Black
#property indicator_color3 Red
#property indicator_color4 Green
*/
//int indicator_color3;
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double ind_buffer1;
double ind_buffer2;
double ind_buffer3;
double ind_buffer4;
double temp;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
/*
int counted_bars=IndicatorCounted(); //counted_bars 这里是-1。在自定义公式中是正常的
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i0) {ind_buffer3=temp;ind_buffer4=0;}
else {ind_buffer3=0;ind_buffer4=temp;}
}
*/
for(int t=0;t
进程:开户->理性分析师->理性投注师
6楼
上面运行的结果
2008.06.29 22:35:33 2008.05.19 00:00 MACD Sample_2 EURUSD,Daily: i=1016 *b=0 b2=0 b3=0 b4=0
.
.
.
进程:开户->理性分析师->理性投注师
发表于:2008-06-30 09:25只看该作者
7楼
for(int i=Bars; i>Bars-3; i--) //或 for(int i=0; i<3; i++)
{
Print("i=",i," *b=",ind_buffer1," b2=",ind_buffer2," b3=",ind_buffer3," b4=",ind_buffer4); // 这里得不到想要的
}
如果要贴出来,最好换成[t]或[x],最好不要有,因为是斜体字符号,不但把后面的字都搞斜了,而且自己还不显示
8楼
进程:开户->理性分析师->理性投注师
9楼
再试发一次
//+------------------------------------------------------------------+
//| Custom MACD.mq4 |
//| Copyright ?2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_buffers 4 //显示缓存最高8
/*
#property indicator_color1 Blue
#property indicator_color2 Black
#property indicator_color3 Red
#property indicator_color4 Green
*/
//int indicator_color3;
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double ind_buffer1;
double ind_buffer2;
double ind_buffer3;
double ind_buffer4;
double temp;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
/*
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i0) {ind_buffer3=temp;ind_buffer4=0;}
else {ind_buffer3=0;ind_buffer4=temp;}
}
*/
/*
for(int t=0;t
进程:开户->理性分析师->理性投注师
10楼
我的设想是需要用到历史均线和历史MACD的数值。算法近似波浪中背驰(我不会波浪)。
回想以前用Qbasic凭乾龙日线收盘价算MACD数值的痛苦难以表达。
进程:开户->理性分析师->理性投注师
11楼
嘿,终于找到了,原来自己的E文太次,Current 表示当前,Previous表示先前(这里上移一位,表示上一日)
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
再次多谢秃鹫的热心。
发表于:2008-06-30 14:14只看该作者
12楼
原来你想要一个不用MA的MACD
下面这个就是不用MA的
[CODE]
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Silver
#property indicator_color2 Yellow
#property indicator_color3 Red
#property indicator_color4 Green
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
double MacdBuffer1;
double MacdBuffer2;
double MacdBuffer3;
double MacdBuffer4;
int init() {
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexDrawBegin(0,SignalSMA);
SetIndexDrawBegin(1,SignalSMA);
SetIndexDrawBegin(2,SignalSMA);
SetIndexDrawBegin(3,SignalSMA);
IndicatorDigits(Digits+1);
SetIndexBuffer(0,MacdBuffer1);
SetIndexBuffer(1,MacdBuffer2);
SetIndexBuffer(2,MacdBuffer3);
SetIndexBuffer(3,MacdBuffer4);
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"DIF");
SetIndexLabel(1,"DEA");
SetIndexLabel(2,"MACD");
SetIndexLabel(3,"MACD");
return(0);
}
int start(){
double temp;
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int t=0; t=0) {MacdBuffer3[t]=temp*1.3; MacdBuffer4[t]=EMPTY_VALUE;}
if(temp<0) {MacdBuffer4[t]=temp*1.3; MacdBuffer3[t]=EMPTY_VALUE;}
}
return(0);
}
[/CODE]
13楼
我不会编窗口,可能先前修改rick的MACE例子不正确。
现在查看到MT4自带的例子可以得到前的MacdPrevious是真实数,而MacdCurren因为只有开盘价,数字不符。
在际实应用中,只想在每一次完成一个Bars才运算一次,可不可以?
[ 本帖最后由 望云 于 2008-6-30 22:53 编辑 ]
进程:开户->理性分析师->理性投注师