求编写:双组双线变色MACD叠加指标。谢谢!
本指标根据标准双线MACD稍加修改,效果见附图:(图中是将2个单组MACD叠加在一个指标窗口中,左右移动K线的话,2组线的相对位置会变化不定,故想设计在同一个指标中,让相对位置能够固定下来。)指标参数:1)线型:EMA、SMA、LWMA(以便与主图相配合,能反应主图中采用不同类型均线时的真实均线差值)2)Short1:253)Short2: 994)LONG:1815)MID:9
将macd(Short1, LONG)及macd(Short2, LONG)两个参数组的DIF、DEA叠加在一个指标窗口中,为避免图形混乱,柱状线只保留其中一组即可。另外:1. 两条均线差值采用乖离率百分比计算(参见如下公式),这样不同货币对的强弱标准统一,具有可比性;2. DIF、DEA上升下降均会变色。
我只会写通达信股票公式,见下(供参考):
M1:=MA(CLOSE,SHORT1)*(M=0)+EMA(CLOSE,SHORT1)*(M=1)+WMA(CLOSE,SHORT1)*(M=2);M2:=MA(CLOSE,SHORT2)*(M=0)+EMA(CLOSE,SHORT2)*(M=1)+WMA(CLOSE,SHORT2)*(M=2);L1:=MA(CLOSE,LONG)*(M=0)+EMA(CLOSE,LONG)*(M=1)+WMA(CLOSE,LONG)*(M=2);
DIF1:M1*100/L1-100,COLORYELLOW;DEA1:EMA(DIF1,MID),COLORWHITE;MACD:(DIF1-DEA1)*2,COLORSTICK;
DIF2:M2*100/L1-100,COLORYELLOW;DEA2:EMA(DIF2,MID),COLORWHITE;
0,DOTLINE,COLORYELLOW;
IF(DIF1<REF(DIF1,1),DIF1,DRAWNULL),COLORRED;IF(DEA1<REF(DEA1,1),DEA1,DRAWNULL),COLORRED;IF(DIF2<REF(DIF2,1),DIF2,DRAWNULL),COLORRED;IF(DEA2<REF(DEA2,1),DEA2,DRAWNULL),COLORRED;
多谢老师及各位网友相助!
看到了,已经安排排期了,最近比较忙,vip用户优先,您这个得排他们后面。 谢谢老师相助,静候佳音! 我看了一下,是通达信的代码啊,对这个不是很熟。
你懂通达信公式的话,你能不能直接告诉我上面的代码是什么意思? //这是用M1、M2、L1三均线操盘.其中三根均线的周期参数short1<short2<long。
M1:=MA(CLOSE,SHORT1)*(M=0)+EMA(CLOSE,SHORT1)*(M=1)+WMA(CLOSE,SHORT1)*(M=2);
M2:=MA(CLOSE,SHORT2)*(M=0)+EMA(CLOSE,SHORT2)*(M=1)+WMA(CLOSE,SHORT2)*(M=2);
L1:=MA(CLOSE,LONG)*(M=0)+EMA(CLOSE,LONG)*(M=1)+WMA(CLOSE,LONG)*(M=2);
//以上参数m是选择线型:m=0时为SMA; m=1时为EMA; m=2时为LWMA。
DIF1:M1*100/L1-100,COLORYELLOW;
DEA1:EMA(DIF1,MID),COLORWHITE;
MACD=(DIF1-DEA1)*2,COLORSTICK;
//计算第1组均线的DIF、DEA及MACD;
DIF2:M2*100/L1-100,COLORYELLOW;
DEA2:EMA(DIF2,MID),COLORWHITE
//计算第2组均线的DIF、DEA;
0,DOTLINE,COLORYELLOW;
//设置0位水平线颜色;
F(DIF1<REF(DIF1,1),DIF1,DRAWNULL),COLORRED;
IF(DEA1<REF(DEA1,1),DEA1,DRAWNULL),COLORRED;
IF(DIF2<REF(DIF2,1),DIF2,DRAWNULL),COLORRED;
IF(DEA2<REF(DEA2,1),DEA2,DRAWNULL),COLORRED;
//两组DIF、DEA线下降时设为红色。
谢谢老师回复! //+------------------------------------------------------------------+
//| MACD双线.mq4 |
//+------------------------------------------------------------------+
#property copyright "我在跑数据"
#property link "rundata.taobao.com"
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Green
#property indicator_color5 Lime
#property indicator_color6 Lime
extern int Short=12;
extern int Long=26;
extern int Mid=9;
double c;
double x1[];
double x2[];
double x3[];
double x4;
double x5;
double x6[];
double x7[];
double x8[];
double xa2;
double xaa1;
double xaa2;
double xaa3;
int init()
{
SetIndexBuffer(0,x1);
SetIndexStyle(0,DRAW_LINE);
SetIndexDrawBegin(0,0);
SetIndexBuffer(1,x2);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,0);
SetIndexBuffer(2,x3);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexDrawBegin(2,0);
SetIndexBuffer(3,x6);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexDrawBegin(3,0);
SetIndexBuffer(4,x7);
SetIndexStyle(4,DRAW_LINE);
SetIndexDrawBegin(4,0);
SetIndexBuffer(5,x8);
SetIndexStyle(5,DRAW_LINE);
SetIndexDrawBegin(5,0);
IndicatorDigits(Digits+1);
SetLevelValue(0,0);
return(0);
}
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=limit+500; i>=0; i--)
{
x4=iMA(NULL,0,Short,0,MODE_EMA,PRICE_CLOSE,i);
x5=iMA(NULL,0,Long,0,MODE_EMA,PRICE_CLOSE,i);
x1=x4-x5;
ArrayCopy(xa2,x1,0,i,100);
ArraySetAsSeries(xa2,true);
x2=iMAOnArray(xa2,0,Mid,0,MODE_EMA,0);
if(x1>x1)
x7=x1;
else x7=EMPTY_VALUE;
if(x2>x2)
x8=x2;
else x8=EMPTY_VALUE;
if(x1-x2>=0)
{
x3=2*(x1-x2);
x4=EMPTY_VALUE;
}
else
{
x6=2*(x1-x2);
x3=EMPTY_VALUE;
}
}
return(0);
}
以上是MT4的单组双线变色MACD源码,dif与dea之间是用差值计算的,我想把差值改为乖离百分比计算。然后变为双组dif、dea显示。谢谢!
页:
[1]