这是我第一次在 MQL4 中制作指标。我想要它做的是画出之字折线之类的线。当我在图表上运行指标时,我绘制了蓝色的线条:
这是我在
OnCalculate
函数中的代码:
int Counted_bars=IndicatorCounted(); // Number of counted bars
int i=Bars-Counted_bars-1;
// Setup
if(rates_total<=DATA_LIMIT)
return(0);
// Loop for uncounted bars & for the 0th bar
while(i >= 0)
{
int shift1 = i+1;
int shift2 = i+2;
double ao1 = iAO(_Symbol, 0, shift1);
double ao2 = iAO(_Symbol, 0, shift2);
// mark the start of a new range
if(ao1 > 0 && ao2 < 0)
{
positiveRangeBar = BarIndex(shift1);
highestHighVal = high[shift1];
}
if(ao1 < 0 && ao2 > 0)
{
negativeRangeBar = BarIndex(shift1);
lowestLowVal = low[shift1];
}
// update the highest high/lowest low
if(ao1 > 0)
{
double _high = high[shift1];
if(_high > highestHighVal)
{
highestHighVal = _high;
currHigh[shift1] = highestHighVal;
}
}
if(ao1 < 0)
{
double _low = low[shift1];
if(_low < lowestLowVal)
{
lowestLowVal = _low;
currLow[shift1] = lowestLowVal;
}
}
i--;
}
我不知道为什么会发生这种情况。
看起来指标正在使用线条样式,
DRAW_LINE
[MQL4 参考]。这是常见的线条样式。
假设一条线显示了 MetaTrader 中指标数据缓冲区中的一系列值,如果该线没有出现在图表上的某个位置,则该指标的数据缓冲区可能在该位置具有值
EMPTY_VALUE
。
如果我理解指标数据函数的逻辑,看起来当
_low >= lowestLowVal
或 _high <= highestHighVal
时它可能不会产生值
如果您对实现 Zig Zag 指标有任何兴趣,尽管使用的是 MQL4 以外的编程语言,但 jbn 开发了一个由 Python 开发的 zig Zag 实现([演示])。
对于反转检测中更复杂的应用,John F. Ehlers 撰写了有关 自相关(热图)(非常简短的描述,附有书籍参考)的文章。尽管如此,要为 MetaTrader 实施这些更复杂的方法,可能需要 MQL5 和 MT5 及其 OpenCL 支持。
也许 Python 示例可能更简洁?