下载MetaTrader 5
要添加评论,请登录注册
您是真正的专家吗?与数以百万的交易者共享您的知识!
liuxiaodong
282
liuxiaodong 2008.03.19 11:20 

下面是1.0版本的代码(多方力量和空方力量分别累计若干周期,可以明显看到多空力量的此消彼长

和2.0版本的代码 (不会平滑 2.0版本用pp周期的平滑均线代替,效果也很好)

不会平滑,希望高手改进。

//+------------------------------------------------------------------+
//| Lius-easy1.0.mq4 |
//| Copyright ?2007, MetaQuotes Software Corp. |
//| AAA编写 ROSH 和 斜风细雨提供很大帮助 再次致谢 |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 DarkGreen
#property indicator_color3 Yellow
//---- buffers
double sum1[];
double sum2[];
double sum3[];
double ExtMapBuffer1[]; // 多方力量的指标
double ExtMapBuffer2[]; // 空方力量的指标
double ExtMapBuffer3[]; // 多空力量的差值
extern int n=30;
extern int k=3;
// 计算多个指标值相加的周期参数 共Periodma个指标值相加
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(6);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,sum1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,sum2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,sum3);
SetIndexDrawBegin(0,1);
IndicatorShortName("Lius-easy1.0-");
SetIndexBuffer(3,ExtMapBuffer1);
SetIndexBuffer(4,ExtMapBuffer2);
SetIndexBuffer(5,ExtMapBuffer3);


//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
double a0,b0,c0,d0,a1,b1,c1,d1;
double res1,res0;
for(int i=limit; i>=0; i--)
{
res0=(High[i]+Low[i]+2*Close[i])/4.0;
res1=(High[i+1]+Low[i+1]+2*Close[i+1])/4.0;

if(res0>=res1)
//yangzhu
{
ExtMapBuffer1[i]=MathRound((res0-res1)/Point);
ExtMapBuffer2[i]=0;
ExtMapBuffer3[i]=MathRound((res0-res1)/Point);
}
//yinzhu
if(res0<res1)
{
ExtMapBuffer1[i]=0;
ExtMapBuffer2[i]=MathRound((res0-res1)/Point);
ExtMapBuffer3[i]=MathRound((res0-res1)/Point);
}
//
}
//
//
for(i=limit;i>=0;i--)
{
double SUM1=0.0,SUM2=0.0,SUM3=0.0;
int j;
for (j=0;j<n;j++)
{
SUM1=SUM1+ExtMapBuffer1[i+j];
}
sum1[i]=SUM1;
for (j=0;j<n;j++)
{
SUM2=SUM2+ExtMapBuffer2[i+j];
}
sum2[i]=SUM2;
for (j=0;j<n;j++)
{
SUM3=SUM3+ExtMapBuffer3[i+j];
}
sum3[i]=k*SUM3;
//
}

//----
return(0);
}
//+------------------------------------------------------------------+




2.0般指标代码


//+------------------------------------------------------------------+
//| Lius-easy2.0.mq4 |
//| Copyright ?2007, MetaQuotes Software Corp. |
//| AAA编写 ROSH 和 斜风细雨提供很大帮助 再次致谢 |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 DarkGreen
#property indicator_color3 Yellow
//---- buffers
double sum1[];
double sum2[];
double sum3[];
double ExtMapBuffer1[]; // 多方力量的指标
double ExtMapBuffer2[]; // 空方力量的指标
double ExtMapBuffer3[]; // 多空力量的差值
extern int n=60;
extern int PP=10;
// 计算多个指标值相加的周期参数 共Periodma个指标值相加
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(6);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,sum1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,sum2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,sum3);
SetIndexDrawBegin(0,1);
IndicatorShortName("Lius-easy1.0-");
SetIndexBuffer(3,ExtMapBuffer1);
SetIndexBuffer(4,ExtMapBuffer2);
SetIndexBuffer(5,ExtMapBuffer3);


//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
double a0,b0,c0,d0,a1,b1,c1,d1;
double res1,res0;
for(int i=limit; i>=0; i--)
{
res0=iMA(NULL,0,PP,0,MODE_SMMA,PRICE_WEIGHTED,i);
res1=iMA(NULL,0,PP,0,MODE_SMMA,PRICE_WEIGHTED,i+1);
if(res0>=res1)
//yangzhu
{
ExtMapBuffer1[i]=MathRound((res0-res1)/Point);
ExtMapBuffer2[i]=0;
ExtMapBuffer3[i]=MathRound((res0-res1)/Point);
}
//yinzhu
if(res0<res1)
{
ExtMapBuffer1[i]=0;
ExtMapBuffer2[i]=MathRound((res0-res1)/Point);
ExtMapBuffer3[i]=MathRound((res0-res1)/Point);
}
//
}
//
//
for(i=limit;i>=0;i--)
{
double SUM1=0.0,SUM2=0.0,SUM3=0.0;
int j;
for (j=0;j<n;j++)
{
SUM1=SUM1+ExtMapBuffer1[i+j];
}
sum1[i]=SUM1;
for (j=0;j<n;j++)
{
SUM2=SUM2+ExtMapBuffer2[i+j];
}
sum2[i]=SUM2;
for (j=0;j<n;j++)
{
SUM3=SUM3+ExtMapBuffer3[i+j];
}
sum3[i]=SUM3;
//
}

//----
return(0);
}
//+------------------------------------------------------------------+

okwh
1630
okwh 2008.03.19 13:03  

平滑改进:

//+------------------------------------------------------------------+
//| Lius-easy1.0.mq4 |
//| Copyright ?2007, MetaQuotes Software Corp. |
//| AAA编写 ROSH 和 斜风细雨提供很大帮助 再次致谢 |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 DarkGreen
#property indicator_color3 Yellow
#property indicator_color4 Red
#property indicator_color5 DarkGreen
#property indicator_color6 Yellow//---- buffers
double sum1[];
double sum2[];
double sum3[];
double ExtMapBuffer1[]; // 多方力量的指标
double ExtMapBuffer2[]; // 空方力量的指标
double ExtMapBuffer3[]; // 多空力量的差值
extern int n=17;//9;//30;
extern int k=3;
extern int PP=5;//10;
extern int hlorma =0;//1;//0;
// 计算多个指标值相加的周期参数 共Periodma个指标值相加
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(6);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,sum1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,sum2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,sum3);
SetIndexDrawBegin(0,1);
IndicatorShortName("Lius-easy1.0-");
SetIndexBuffer(3,ExtMapBuffer1);
SetIndexBuffer(4,ExtMapBuffer2);
SetIndexBuffer(5,ExtMapBuffer3);


//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
double a0,b0,c0,d0,a1,b1,c1,d1;
double res1,res0;
int j;
for(int i=limit; i>=0; i--)
{
ExtMapBuffer1[i]=0;ExtMapBuffer2[i]=0;ExtMapBuffer3[i]=0;
for (j=0;j<n;j++)
{
if (hlorma ==0)
{
res0=(High[i+j]+Low[i]+2*Close[i])/4.0;
res1=(High[i+j+1]+Low[i+j+1]+2*Close[i+j+1])/4.0;
}
else
{
res0=iMA(NULL,0,PP,0,MODE_SMMA,PRICE_WEIGHTED,i+j);
res1=iMA(NULL,0,PP,0,MODE_SMMA,PRICE_WEIGHTED,i+j+1);
}

if(res0>=res1)
//yangzhu
{
ExtMapBuffer1[i]+=MathRound((res0-res1)/Point);
ExtMapBuffer2[i]+=0;
ExtMapBuffer3[i]+=MathRound((res0-res1)/Point);
}
//yinzhu
if(res0<res1)
{
ExtMapBuffer1[i]+=0;
ExtMapBuffer2[i]+=MathRound((res0-res1)/Point);
ExtMapBuffer3[i]+=MathRound((res0-res1)/Point);
}
}
//
}
//
//
for(i=limit;i>=0;i--)
{
sum1[i]=iMAOnArray(ExtMapBuffer1,0,n,0,MODE_SMMA,i);
sum2[i]=iMAOnArray(ExtMapBuffer2,0,n,0,MODE_SMMA,i);
sum3[i]=iMAOnArray(ExtMapBuffer3,0,n,0,MODE_SMMA,i);
}

//----
return(0);
}

okwh
1630
okwh 2008.03.19 13:36  

还可换为 ExtMapBuffer4[i] = 2*sum3[i]-sum2[i]-sum1[i];

liuxiaodong
282
liuxiaodong 2008.03.19 13:54  

非常感谢!

我试试.

liuxiaodong
282
liuxiaodong 2008.03.20 11:32  
DxdCn:

还可换为 


是否应该是 ExtMapBuffer4[i] = 2*sum3[i]+sum2[i]-sum1[i]; ???

因为 sum2[i]是负值。

Spark Ho
6
Spark Ho 2008.07.12 23:39  
请问:在哪里可以查到MODE_SMMA和MODE_SMA的具体算法?
张聪
3
张聪 2008.11.24 10:21  

不知LZ能否看到,有个问题,能否将这个2.0版本的改成变色的,类似变色均线的效果,比如说上涨是绿色,下跌是红色?谢谢

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