"array out of range"如何使用 iMAonArray



我想寻求一点帮助:我想将规则集成到我的ea中,但我无法正确制作一个数组。较高的TF在Blabla之上/之下..."

所以这是我的代码:

   double MA;  
   double RSIBuf[];
   double MaBuf[];
ArrayResize(RSIBuf,0);
int counted_bars=IndicatorCounted();
int limit = Bars-counted_bars-1;
for(int i=limit; i>=0; i--)
{
RSIBuf[i] = (iRSI(NULL,higherTF,RSIPeriod,0,i)); 
MaBuf[i] = iMAOnArray(RSIBuf,higherTF,RSI_SMA,0,0,i);
}
MA = MaBuf[0];

...

direction Trend=NEUTRAL;
if(MA>RSI_Up )        Trend=UP;

MT4说这是RSIBUF []行的错误

我在哪里做错了?感谢您的帮助..
wicha

您说的是EA,但是您正在使用指示代码。

在指示器中,您需要将缓冲区声明为缓冲区:

IndicatorBuffers(2);    //Allocate memory for buffers
double RSIBuf[];   //indicator buffers
double MaBuf[];
// Bind the array and allocated memory to an actual double-array dynamic buffer
SetIndexBuffer(0, RSIBuf);
SetIndexBuffer(1, MaBuf);
int counted_bars=IndicatorCounted();
int limit = Bars-counted_bars-1;
for(int i=limit; i>=0; i--)
{
   RSIBuf[i] = iRSI(NULL,higherTF,RSIPeriod,0,i); 
   MaBuf[i] = iMAOnArray(RSIBuf,higherTF,RSI_SMA,0,0,i);
}
MA = MaBuf[0];

如果是在EA中,则必须提前分配足够的内存,例如:

int maxBars = TerminalInfoInteger(TERMINAL_MAXBARS);
double RSIBuf[maxBars];
double MaBuf[maxBar];

然后您照常进行。

相关内容

最新更新