英文:
Can't Retrieve Upper & Lower Bands from iBand
问题
我正在尝试从iBand获取上下值...
void OnTick()
{
double upperBand[];
double lowerBand[];
double range;
int handle = iBands(_Symbol, _Period, 20, 2, 0, PRICE_CLOSE);
// 复制缓冲区(handle, 哪个波段, 周期, 值的数量, 存储位置)
CopyBuffer(handle, 1, 0, 1, upperBand);
CopyBuffer(handle, 2, 0, 1, lowerBand);
// 使用upper_band和lower_band变量
Print("上限带: ", upperBand[0]);
Print("下限带: ", lowerBand[0]);
range = upperBand[0] - lowerBand[0];
Print("范围: ", range);
}
然而,打印函数始终返回相同的值,实际上似乎是中间带的值。
当然,x = x,所以范围始终为0。
由于我没有收到错误代码,并且数据集完整,我甚至不确定如何进行故障排除?
英文:
I'm trying to get the upper and lower values from iBand...
void OnTick()
{
double upperBand[];
double lowerBand[];
double range;
int handle = iBands(_Symbol, _Period, 20, 2, 0, PRICE_CLOSE);
// CopyBuffer(handle, which band, period, no. values, where to store)
CopyBuffer(handle, 1, 0, 1, upperBand);
CopyBuffer(handle, 2, 0, 1, lowerBand);
// Use the upper_band and lower_band variables
Print("Upper Band: ", upperBand[0]);
Print("Lower Band: ", lowerBand[0]);
range = upperBand[0] - lowerBand[0];
Print("Range: ", range);
}
However the print functions reliably return an identical value, one that appears in fact to be the middle band value.
Of course, x = x, and so the range is always 0.
As I'm getting no error code and the data set is intact, I'm not even sure how to trouble shoot?
答案1
得分: 1
你初始化指标的方式不正确。请尝试以下代码:
int handle_iBands;
int OnInit()
{
handle_iBands = iBands(_Symbol, PERIOD_CURRENT, 20, 2, 0.0, PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
void OnTick()
{
double Upper[], Lower[], range;
CopyBuffer(handle_iBands, 1, 0, 10, Upper);
CopyBuffer(handle_iBands, 2, 0, 10, Lower);
Print("上轨: ", Upper[0]);
Print("下轨: ", Lower[0]);
range = Upper[0] - Lower[0];
Print("区间: ", range);
}
这是修正后的代码。
英文:
You are initializing the indicator incorrectly. Try the following
int handle_iBands;
int OnInit()
{
handle_iBands = iBands(_Symbol, PERIOD_CURRENT, 20, 2, 0.0, PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
void OnTick()
{
double Upper[], Lower[], range;
CopyBuffer(handle_iBands, 1, 0, 10, Upper);
CopyBuffer(handle_iBands, 2, 0, 10, Lower);
Print("Upper Band: ", Upper[0]);
Print("Lower Band: ", Lower[0]);
range = Upper[0] - Lower[0];
Print("Range: ", range);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论