下载MetaTrader 5
要添加评论,请登录注册
通过代码库共享您的程序。获得访问数以百万的交易者们!
kong ling gang
9
kong ling gang 2014.03.15 04:07 

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 LightSeaGreen
#property indicator_color2 LightSeaGreen
#property indicator_color3 LightSeaGreen
#property indicator_color4 LightSeaGreen

//--- buffers

double ExtUpperBuffer5[];
double ExtLowerBuffer5[];
double ExtUpperBuffer15[];
double ExtLowerBuffer15[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- 1 additional buffer used for counting.
IndicatorBuffers(4);
IndicatorDigits(Digits);

//--- upper5 band
SetIndexStyle(0,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(0,ExtUpperBuffer5);
SetIndexShift(0,0);
SetIndexLabel(0,"Bands5 Upper");
//--- lower5 band
SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(1,ExtLowerBuffer5);
SetIndexShift(1,0);
SetIndexLabel(1,"Bands5 Lower");
//--- upper15 band
SetIndexStyle(2,DRAW_LINE,STYLE_DASH);
SetIndexBuffer(2,ExtUpperBuffer15);
SetIndexShift(2,0);
SetIndexLabel(2,"Bands15 Upper");
//--- lower15 band
SetIndexStyle(3,DRAW_LINE,STYLE_DASH);
SetIndexBuffer(3,ExtLowerBuffer15);
SetIndexShift(3,0);
SetIndexLabel(3,"Bands15 Lower");


//--- initialization done
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Bollinger Bands |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int i,j,r,m5,m15,M5,M15;
j=0;
r=0;
M5=TimeMinute(iTime(NULL,PERIOD_M5,0));
M15=TimeMinute(iTime(NULL,PERIOD_M15,0));

for(i=0; i<rates_total && !IsStopped(); i++)
{

m5=TimeMinute(Time[i]);
m15=TimeMinute(Time[i]);
if(m5==M5)
{
//--- upper line
ExtUpperBuffer5[j]=iBands(NULL,PERIOD_M5,20,2,0,PRICE_CLOSE,MODE_UPPER,j);
//--- lower line
ExtLowerBuffer5[j]=iBands(NULL,PERIOD_M5,20,2,0,PRICE_CLOSE,MODE_LOWER,j);
j++;
M5=TimeMinute(iTime(NULL,PERIOD_M5,j));
}
else
{
//--- upper line
ExtUpperBuffer5[j]=iBands(NULL,PERIOD_M5,20,2,0,PRICE_CLOSE,MODE_UPPER,j);
//--- lower line
ExtLowerBuffer5[j]=iBands(NULL,PERIOD_M5,20,2,0,PRICE_CLOSE,MODE_LOWER,j);

}
if(m15!=M15)
{
//--- upper line
ExtUpperBuffer15[r]=iBands(NULL,PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_UPPER,r);
//--- lower line
ExtLowerBuffer15[r]=iBands(NULL,PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_LOWER,r);
}
else
{
//--- upper line
ExtUpperBuffer15[r]=iBands(NULL,PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_UPPER,r);
//--- lower line
ExtLowerBuffer15[r]=iBands(NULL,PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_LOWER,r);
r++;
M15=TimeMinute(iTime(NULL,PERIOD_M15,r));
}

}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}

我的以上代码画图不正确,但是我找不到问题,请高手帮助。

kong ling gang
9
kong ling gang 2014.03.15 04:12  
画出的5分钟线和15分钟线数值都不对。
asdzzf001
6
asdzzf001 2016.08.17 15:26  
                                                               low = iBands(NULL,PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
                                                               midd = iBands(NULL,PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_MAIN,0);
                                                               upp = iBands(NULL,PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
                                                               ObjectCreate("15分钟均线",OBJ_HLINE,0,0,midd);
                                                               ObjectCreate("15分钟上轨",OBJ_HLINE,0,0,upp);

                                                               ObjectCreate("15分钟下轨",OBJ_HLINE,0,0,low);

 

 

大概这个方法 其他的你自己去研究 

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