2D arrays in MQL4 not functioning as expected

2D arrays in MQL4 not functioning as expected

Manage alerts

Loading saved threads...

Arash · External communityPost link
External question — Stack Overflow Stack Exchange Author: Arash Original post: https://stackoverflow.com/questions/75550048 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I want to create a two-dimensional array with variable number of rows and columns. Of course, the number of rows and columns is determined at the beginning of the execution of the expert. A part of the code I wrote is as follows and an error was generated like this. '[' - invalid index value Ae_1320_test.mq4 85 13 Note: It should be noted that column 13 in row 85 refers to the second index of matrix A. A[](column 13:[)] //+------------------------------------------------------------------+ //| test.mq4 | //| Copyright 2021, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern int m=30; extern int n=5; int Base_Idx[]; double pt, b[], A[][], PivotColumn[]; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- pt = Point; if (Digits == 3 || Digits == 5) { pt*=10; } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ 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]; return; }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Arash Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/75550048 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I want to create a two-dimensional array with variable number of rows and columns. Of course, the number of rows and columns is determined at the beginning of the execution of the expert. A part of the code I wrote is as follows and an error was generated like this. '[' - invalid index value Ae_1320_test.mq4 85 13 Note: It should be noted that column 13 in row 85 refers to the second index of matrix A. A[](column 13:[)] //+------------------------------------------------------------------+ //| test.mq4 | //| Copyright 2021, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern int m=30; extern int n=5; int Base_Idx[]; double pt, b[], A[][], PivotColumn[]; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- pt = Point; if (Digits == 3 || Digits == 5) { pt*=10; } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ 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]; return; }

Cancel quote

Checking account access…