为什么 iCustom() 会为我的指标返回默认的空值 (2147483647)?
Why is iCustom() returning default empty value (2147483647) for my indicator?
我构建了自己的自定义指标,使用之前的 X 条柱数计算图表的近似斜率和加速度。
当我将指标附加到图表时,它按预期工作,但当我尝试使用 iCustom() 检索 EA 中的最新值时,它仅 returns 2147483647。
我已经尝试对 iCustom()
shift 参数使用不同的值,但没有成功。
double SlopeBuffer[];
double AccelerationBuffer[];
extern int delta;
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,SlopeBuffer);
SetIndexBuffer(1,AccelerationBuffer);
//---
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 i, counted_bars;
counted_bars = IndicatorCounted();
i = Bars - counted_bars - delta; // Here I offset the initial bar by the delta(period)
// so that the first bar has delta previous bars on the chart.
while(i>=0){
double Ex = 0; //intermediate calculation variables...
double Ey = 0;
double Exy = 0;
double Exx = 0;
for(int n=0;n<delta;n++){ // This for loop iterates over the previous delta bars
Ex += n; // to calculate various sigma variables used to find the
Ey += Close[i+delta-n-1]; // slope.
Exy += n*Close[i+delta-n-1];
Exx += n*n;
}
double slope = 100*(delta*Exy - Ex*Ey)/(delta*Exx - Ex*Ex); // final slope calculation.
SlopeBuffer[i] = slope; // add to the buffer.
AccelerationBuffer[i] = (slope - SlopeBuffer[i+1]); // calculate acceleration
i--; // and adding to buffer.
}
//--- return value of prev_calculated for next call
return(rates_total);
}
我找到问题了。
这条线是罪魁祸首。
i = Bars - counted_bars - delta;
一旦指标 "caught up" 和图表上所有完整的柱形图,将使 i
等于 1 - delta
,这将是负值。结果是 while 循环永远不会 运行.
我构建了自己的自定义指标,使用之前的 X 条柱数计算图表的近似斜率和加速度。
当我将指标附加到图表时,它按预期工作,但当我尝试使用 iCustom() 检索 EA 中的最新值时,它仅 returns 2147483647。
我已经尝试对 iCustom()
shift 参数使用不同的值,但没有成功。
double SlopeBuffer[];
double AccelerationBuffer[];
extern int delta;
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,SlopeBuffer);
SetIndexBuffer(1,AccelerationBuffer);
//---
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 i, counted_bars;
counted_bars = IndicatorCounted();
i = Bars - counted_bars - delta; // Here I offset the initial bar by the delta(period)
// so that the first bar has delta previous bars on the chart.
while(i>=0){
double Ex = 0; //intermediate calculation variables...
double Ey = 0;
double Exy = 0;
double Exx = 0;
for(int n=0;n<delta;n++){ // This for loop iterates over the previous delta bars
Ex += n; // to calculate various sigma variables used to find the
Ey += Close[i+delta-n-1]; // slope.
Exy += n*Close[i+delta-n-1];
Exx += n*n;
}
double slope = 100*(delta*Exy - Ex*Ey)/(delta*Exx - Ex*Ex); // final slope calculation.
SlopeBuffer[i] = slope; // add to the buffer.
AccelerationBuffer[i] = (slope - SlopeBuffer[i+1]); // calculate acceleration
i--; // and adding to buffer.
}
//--- return value of prev_calculated for next call
return(rates_total);
}
我找到问题了。
这条线是罪魁祸首。
i = Bars - counted_bars - delta;
一旦指标 "caught up" 和图表上所有完整的柱形图,将使 i
等于 1 - delta
,这将是负值。结果是 while 循环永远不会 运行.