下载MetaTrader 5

Dxdcn 如何实现若干个数值求和 我这个指标始终无法实现,请看看。

要添加评论,请登录注册
liuxiaodong
282
liuxiaodong  

//+------------------------------------------------------------------+
//| Lius-easy1.0- |
//| Copyright ?2007, MetaQuotes Software Corp. |
//| https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 DarkGreen
#property indicator_color3 Black
//---- buffers
double sum1[];
double sum2[];
double sum3[];
double ExtMapBuffer1[]; // 多方力量的指标
double ExtMapBuffer2[]; // 空方力量的指标
double ExtMapBuffer3[]; // 多空力量的差值
extern int n=30; // 计算多个指标值相加的周期参数 共Periodma个指标值相加
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
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-");
//----
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;
for(int i=limit; i>=0; i--)
{
a0=Open[i];
b0=Close[i];
c0=High[i];
d0=Low[i];
a1=Open[i+1];
b1=Close[i+1];
c1=High[i+1];
d1=Low[i+1];
if(b0>=a0)
//yangzhu
{
if(a0-b1>0)
{
ExtMapBuffer1[i]=MathRound(((a0-b1)+(c0-d0))/Point);
ExtMapBuffer2[i]=MathRound(((b0-c0)+(d0-a0))/Point);
ExtMapBuffer3[i]=MathRound((b0-b1)/Point);
}
if (a0-b1<=0)
{
ExtMapBuffer1[i]=MathRound((c0-d0)/Point);
ExtMapBuffer2[i]=MathRound(((b0-c0)+(d0-a0)+(a0-b1))/Point);
ExtMapBuffer3[i]=MathRound((b0-b1)/Point);
}
}
//yinzhu
if(b0<a0)
{
if(a0-b1>0)
{
ExtMapBuffer1[i]=MathRound(((c0-a0)+(b0-d0)+(a0-b1))/Point);
ExtMapBuffer2[i]=MathRound((d0-c0)/Point);
ExtMapBuffer3[i]=MathRound((b0-b1)/Point);
}
if (a0-b1<=0)
{
ExtMapBuffer1[i]=MathRound(((c0-a0)+(b0-d0))/Point);
ExtMapBuffer2[i]=MathRound(((d0-c0)+(a0-b1))/Point);
ExtMapBuffer3[i]=MathRound((b0-b1)/Point);
}
}
//
}
//
//
for(i=limit;i>=0;i--)
{
double SUM1=0;
int j;
for (j=0;j<n;j++)
{
SUM1=SUM1+ExtMapBuffer1[i+j];
}
sum1[i]=SUM1;
}

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

okwh
1635
okwh  

加上“

IndicatorBuffers(6);

.....
SetIndexBuffer(3,sum1);
SetIndexBuffer(4,sum2);
SetIndexBuffer(5,sum3);

liuxiaodong
282
liuxiaodong  

谢谢

要添加评论,请登录注册