【问题标题】:"array out of range"on using iMAonArray使用 iMAonArray 时出现“数组超出范围”
【发布时间】:2019-05-05 11:22:13
【问题描述】:

我想请教一点帮助:我想将一条规则集成到我的 EA 中,但我无法正确创建数组。规则将是“如果更高 TF 上的 RSI 的 SMA 高于/低于 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[] 行出错

我哪里做错了?感谢您的帮助..
哎呀

【问题讨论】:

  • 可能您可以显示指标的完整 MCVE 示例来帮助您。或者您可以检查使用iMAOnArray 函数的另一个实现的MACD 指标
  • 感谢您的提示,但我没有在 MACD 源代码中找到任何有用的东西。我想要整合的规则是一个简单的 SMA 放在更高 TF 的 RSI 线上。如果 SMA 显示的值高于 50,则向上,否则向下。就这些
  • JP给了你正确的答案。删除 ArrayResize(RSIBuf,0); 并确保您有两个使用 SetIndexBuffer 函数的动态缓冲区

标签: arrays mql4


【解决方案1】:

您说的是 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];

然后你照常进行。

【讨论】:

    猜你喜欢
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 2012-05-04
    • 2015-02-04
    • 2019-06-17
    相关资源
    最近更新 更多