我想创建一个行数和列数可变的二维数组。当然,行数和列数是在 EA 交易开始时确定的。我写的一部分代码如下,这样就报错了
'[' - 无效的索引值 Ae_1320_test.mq4 85 13
注:需要注意的是第85行第13列指的是矩阵A的第二个索引。A[](第13列:[)]
非常感谢指导我的亲爱的朋友们
//+------------------------------------------------------------------+
//|
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
double pt;
int OnInit()
{
//---
//double pt;
//void init()
{
pt = Point;
if (Digits == 3 || Digits == 5)
{
pt= 10*pt;
}
}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
//----------------------------------------------------------------------
//------------------ Check Starting Of New Candle-----------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//These are very frequent tasks that usually should be performed once
per candle when a new bar starts.
//Coding such types of behavior is not difficult and only requires a few
lines of code. You can see the actual code example below.
// Creating a variable to store the time when a new candle start.
// Populating the variable with the current server time.
datetime NewCandleTime = TimeCurrent();
// Creating a boolean function that returns:
// True, if this is a new candle;
// False if this candle isn't new.
// Remember that the function returns true every time you initialize the
script.
// For example, when you load the indicator or EA to the chart or when
you switch timeframes.
bool IsNewCandle()
{
// If the time of the candle when the function ran last
// is the same as the time this candle started,
// return false, because it is not a new candle.
if (NewCandleTime == iTime(Symbol(), 0, 0)) return false;
// Otherwise, it is a new candle and we need to return true.
else
{
// If it is a new candle, then we store the new value.
NewCandleTime = iTime(Symbol(), 0, 0);
return true;
}
}
extern int m=30;
extern int n=5;
int i,j;
double b[];
double A[][];
double PivotColumn[];
int Base_Idx[];
void OnTick()
{
for (int i=0; m-1; i++)
{
for (int j=0; n;j++)
{
A[i][j]=0;
}
}
//-------------- Matrix A ----------------------
for (int i=0;m-1;i++)
{
A[i][0]= i+2;
A[i][1]= i+4;
A[i][2]= i+6;
A[i][3]= i+8;
A[i][4]= i+10;
b[i]= Close[i+1];
}
double tab[][];
for (int i=0; m; i++)
{
for (int j=0; 2*m+n;j++)
{
tab[i][j]=0;
}
}
for (int i=0; m-1; i++)
{
for (int j=0; 2*m+n-1;j++)
{
tab[i][j]=A[i][j];
}
}
for(int i=0;m-1;i++)
{
tab[i][2*m+n]=b[i];
}
for(int j=0;2*m+n-1;j++)
{
tab[m][j]=2;
}
//+----------------------- Phase One Of SIMPLEX Method ----------------------------+
for (int i=0; m-1; i++)
{
for (int j=0; 2*m+n;j++)
{
tab[m][j]=tab[m][j]-tab[i][j];
}
}
}