CopyBuffer(buli,3,0,rates_total,mdBuffer);
布林带有3个数据吗,那也应该从0开始,0.1.2
同意楼上的意见。是数据读取问题。
iBands 的缓冲区只有3个数,
|
是的布林带buffer从0到2而已
求助,想计算一下均线和布林的值。但发现分配了4个数组,只有3个数组有数据。求指点!!刚学MQL5
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 4
//--- plot ma
#property indicator_label1 "ma"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrFuchsia
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot up
#property indicator_label2 "up"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot low
#property indicator_label3 "low"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrRed
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- plot md
#property indicator_label4 "md"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrRed
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//--- input parameters
input int ma=26;
input int boll=20;
//--- indicator buffers
double maBuffer[];
double upBuffer[];
double lowBuffer[];
double mdBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,maBuffer,INDICATOR_DATA);
SetIndexBuffer(1,upBuffer,INDICATOR_DATA);
SetIndexBuffer(2,lowBuffer,INDICATOR_DATA);
SetIndexBuffer(3,mdBuffer,INDICATOR_DATA);
//变数组序列为时间序列
ArraySetAsSeries(maBuffer,true);
ArraySetAsSeries(upBuffer,true);
ArraySetAsSeries(lowBuffer,true);
ArraySetAsSeries(mdBuffer,true);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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 ma_s = iMA(NULL,PERIOD_CURRENT,ma,0,MODE_SMA,PRICE_CLOSE);
CopyBuffer(ma_s,0,0,rates_total,maBuffer);
//布林上中下三轨数值
int buli = iBands(NULL,PERIOD_CURRENT,20,0,2,PRICE_CLOSE);
CopyBuffer(buli,1,0,rates_total,upBuffer);
CopyBuffer(buli,2,0,rates_total,lowBuffer);
CopyBuffer(buli,3,0,rates_total,mdBuffer);
printf("均线:%.6f,上轨:%.5f,下轨:%.5f,中轨:%.5f。",maBuffer[1],upBuffer[1],lowBuffer[1],mdBuffer[1]);
return(rates_total);
}