我正在尝试在 MQL5 EA 交易中创建/使用 Keltner 通道指标,但由于某种原因它不起作用。我知道目前 MQL5 没有内置指标,因此我尝试使用以下代码手动创建一个指标,任何人都可以协助解决该问题吗:
In the OnInit() function:
int bars = iBars(NULL, TimeFrame);
ArrayResize(upperKeltner, bars);
ArrayResize(lowerKeltner, bars);
double atr = iATR(_Symbol, _Period, 14);
for(int i = 0; i < count; i++)
{
double typical_price = (iOpen(_Symbol, _Period, i) + iHigh(_Symbol, _Period, i) + iLow(_Symbol, _Period, i)) / 3.0;
upperKeltner[i] = typical_price + atr * 1.5;
lowerKeltner[i] = typical_price - atr * 1.5;
}
In the OnTick() function:
ArrayResize(upperKeltner, 1);
ArrayResize(lowerKeltner, 1);
CopyBuffer(handleKeltner, 0, 0, 1, upperKeltner);
CopyBuffer(handleKeltner, 1, 0, 1, lowerKeltner);
要创建指标,您必须将代码放置在 OnCalculate 函数中。发生了什么错误? 代码库中已经有该指标。 https://www.mql5.com/pt/code/16740