MQL4 : Multi Dimensional Array issue.

 

Hello Fam, I am having an issue with a multi dimensional array that would not accept values. This is the logic: When a trade is made, values are stored in an array. If conditions change, I will modify the trade with only made by this EA specifically (EA number).

For some reason, I cannot input the value for  Storage[i,6]=1; or  Storage[i][6]=1; 


//-------------------------------------------------------// Arrey Def \\---------------------------------------------------------

//       0            1 - 1500           2                  3                  4                    5                    6

// Trade Ticket      EAnumber       iAO Value         iMFI Value        OrderOpentime()     Buy(1) or sell(2)     OrderModified() y/n

//----------------------------------------------------------------------------------------------------------------------------


This is the code:



Print("Awesome POP");                        

            for (int z=OrdersTotal() ; z>0 ; z--)

              {    Print(" For Orders Total ",z," we are looking at order ",z-1);        

                 bool OS = OrderSelect( z-1, SELECT_BY_POS, MODE_TRADES) ;

                 for (int i=0; i<rows; i++)

                        {  Print("Row check : ",i,". OrderTicket() :",OrderTicket(), ". Storage: ",Storage[i,0]);

                        if ( Storage[i,0] == OrderTicket() && Storage[i,6]==0 ) 

                           {  Print("Then, Storage[i,6] : ",Storage[i][6]);

                              Storage[i,6]=1; ///////////////////////////////////////////////////////////////this is the part that is messing up. 

                              Print("Now, Storage[i,6] : ",Storage[i][6]);

                              

                              

                              Alert(" Ticket Number: ",OrderTicket(), ", with EA number: ", Storage[i][1], ", was modified with AwesomePop." ) ;

                              bool OM = OrderModify(OrderTicket(),OrderOpenPrice(),Bid-0.001,OrderTakeProfit(),0,clrNONE) ; 

                              break;

                           }

                        }

               }

           

           }

 

Please edit your post and use the code button (Alt+S) when posting code.

In future please post in the correct section

I will move your topic to the MQL4 and Metatrader 4 section.


 
Keith Watford:

Please edit your post and use the code button (Alt+S) when posting code.

In future please post in the correct section

I will move your topic to the MQL4 and Metatrader 4 section.


cidand1:

Hello Fam, I am having an issue with a multi dimensional array that would not accept values. This is the logic: When a trade is made, values are stored in an array. If conditions change, I will modify the trade with only made by this EA specifically (EA number).

For some reason, I cannot input the value for  Storage[i,6]=1; or  Storage[i][6]=1; 

Use the Alt-S to post code...

What debugging have you done?

You don't say what the error is that you are getting? 

how do you know it is even getting to the assignment and not failing at the if?

you don't say what type of array it is.. show the declaration...

your code would be more readable if you stuck to a single syntax for arrays...

regards

 

Thanks

For debugging, I put a lot of Print (" ") to follow the process. It compiles with 0 errors and 0 warnings

if (   OrdersTotal()>0
            && fabs (iAO(Symbol(),0,3)) <.0001 
            && fabs (iAO(Symbol(),0,2)) <.0001 
            && fabs (iAO(Symbol(),0,1)) <.0001 )
            
            { 
            Print("Awesome POP");                        
            for (int z=OrdersTotal() ; z>0 ; z--)
              {    Print(" For Orders Total ",z," we are looking at order ",z-1);        
                 bool OS = OrderSelect( z-1, SELECT_BY_POS, MODE_TRADES) ;
                 for (int i=0; i<rows; i++)
                        {  Print("Row check : ",i,". OrderTicket() :",OrderTicket(), ". Storage: ",Storage[i,0]);
                        if ( Storage[i,0] == OrderTicket() && Storage[i,6]==0 ) 
                           {  Print("Then, Storage[i,6] : ",Storage[i,6]);
                              Storage[i,6]=1; ///////////////////////////////////////////////////////////////modified flag
                              Print("Now, Storage[i,6] : ",Storage[i,6]);
                              
                              
                              Alert(" Ticket Number: ",OrderTicket(), ", with EA number: ", Storage[i][1], ", was modified with AwesomePop." ) ;
                              bool OM = OrderModify(OrderTicket(),OrderOpenPrice(),Bid-0.001,OrderTakeProfit(),0,clrNONE) ; 
                              break;
                           }
                        }
               }
            AwesomeFlagUp=0; Alert(".........................................EJECT EJECT EJECT DUE TO iAO Exploxion"); 
           }

 in the journal i get 

2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Awesome POP
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15:  For Orders Total 2 we are looking at order 1
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Row check : 0. OrderTicket() :18. Storage: 17
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Row check : 1. OrderTicket() :18. Storage: 18
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Then, Storage[i,6] : 0
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Now, Storage[i,6] : 0
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Alert:  Ticket Number: 18, with EA number: 1500, was modified with AwesomePop.
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: modify #18 buy 0.15 EURUSD at 1.20840 sl: 1.20560 tp: 1.20876 ok
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15:  For Orders Total 1 we are looking at order 0
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Row check : 0. OrderTicket() :17. Storage: 17
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Then, Storage[i,6] : 0
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Now, Storage[i,6] : 0
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Alert:  Ticket Number: 17, with EA number: 1500, was modified with AwesomePop.
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: modify #17 buy 0.30 EURUSD at 1.20890 sl: 1.20560 tp: 1.20926 ok
2020.05.12 11:10:16.756 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Alert: .........................................EJECT EJECT EJECT DUE TO iAO Exploxion

This is repeated over and over and over and over and over again. 

This is the issue:  Storage[i,6]=1;      never  executes.

Is there a better way to assign a value in a multidimensional array?  I would like to reassign Storage[i,6] to 1.


Thanks for the help.

 
cidand1:

Thanks

For debugging, I put a lot of Print (" ") to follow the process. It compiles with 0 errors and 0 warnings

 in the journal i get 

This is repeated over and over and over and over and over again. 

This is the issue:  Storage[i,6]=1;      never executes.

Is there a better way to assign a value in a multidimensional array?  I would like to reassign Storage[i,6] to 1.


Thanks for the help.

you still have not given us the array declaration - what is it? 

are you sure that it is not an invalid array value? because it would still compile without error - have you check the log?

there is nothing more simple than  Storage[4][5] = 1;

 
Paul Anscombe:

you still have not given us the array declaration - what is it? 

are you sure that it is not an invalid array value? because it would still compile without error. 

there is nothing more simple than  Storage[4][5] = 1;

int ticket,x,y, rows=15, cols=7, Spike=0;          
datetime lastcandle = iTime(0,0,1);
double LotSize1,DD,MaxDD, Storage[14,6];
bool MA_Up5, MA_Down200, AwesomeFlagUp, AwesomeUp, MF, TradeTime,flag ,AwesomePop;

So the array is declared as "double Storage [14,6]" at the very beginning, with all my int, double, bool, and datetime variables.

15 rows

7 cols


The definition of the array cols are as follows:

//-------------------------------------------------------// Arrey Def \\---------------------------------------------------------
//       0           	1            2                  3                 4                     5                    6
// Trade Ticket      EAnumber       iAO Value         iMFI Value        OrderOpentime()     Buy(1) or sell(2)     OrderModified()
//---------------------------------------------------------------------------------------------------------------

0: Ticket: Ticket number

1: EA Number : Number for this EA, so that I know this trade belongs to this EA......like a magic number.

.

.

6: Order Modified Status.

Every time I make a trade, all these values are stored in an array. 

Hence one row of the array should look like :  {Ticket, EA Number, iAO, iMFI, OrderOpenTime(), BUY/SELL, Modified?}

Where the last double is:  Modified? Yes(1)/No(0)


Before i execute the OrderModify function,

bool OM = OrderModify(OrderTicket(),OrderOpenPrice(),Bid-0.001,OrderTakeProfit(),0,clrNONE) ; 

I want to set the array Storage[i,6] to 1, where i is the row number in the loop. 

so if Storage[0,1] (row 0 EA number value) is what I want, then assign Storage[0,6](Modified? value) to 1. but it is not working. The value is not changed to 1.

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
cidand1:


So the array is declared as "double Storage [14,6]" at the very beginning, with all my int, double, bool, and datetime variables.

15 rows

7 cols


That because it is an invalid array request.....

Your array is [14,6]

So first dimension is 0-13

second dimension 0-5  NOT 6

If you had looked at the Expert log you would have seen the invalid array access message...

If you had simply run Debug in the editor you would have got the invalid array access message...

if you had shown me your array declaration before, I would have confirmed that it was an invalid array access...

next time you know what to do :) happy coding

regards

 
Paul Anscombe:

That because it is an invalid array request.....

Your array is [14,6]

So first dimension is 0-13

second dimension 0-5  NOT 6

If you had looked at the Expert log you would have seen the invalid array access message...

If you had simply run Debug in the editor you would have got the invalid array access message...

if you had shown me your array declaration before, I would have confirmed that it was an invalid array access...

happy coding

regards

Hold on , hold on,  Pardon my ignorance. 

Storage [14,6]  has been changed to Storage[15,7] and now i get this :

2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Awesome POP
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15:  For Orders Total 2 we are looking at order 1
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Row check : 0. OrderTicket() :18. Storage: 17
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Row check : 1. OrderTicket() :18. Storage: 18
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Then, Storage[i,6] : 0
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Now, Storage[i,6] : 1
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Alert:  Ticket Number: 18, with EA number: 1500, was modified with AwesomePop.
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: modify #18 buy 0.15 EURUSD at 1.20840 sl: 1.20560 tp: 1.20876 ok
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15:  For Orders Total 1 we are looking at order 0
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Row check : 0. OrderTicket() :17. Storage: 17
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Then, Storage[i,6] : 0
2020.05.12 12:35:32.148 2018.01.05 02:00:00  2020 IS AWESOME-GOING UP_MF_15Min EURUSD,M15: Now, Storage[i,6] : 1



THANK YOU!!

 
cidand1:

Hold on , hold on,  Pardon my ignorance. 

Storage [14,6]  has been changed to Storage[15,7] and now i get this :



THANK YOU!!

your welcome

 
//------------------------------------// Arrey Def \\------------------------------------------
//       0         1       2          3          4                 5                6
// Trade Ticket EAnumber iAO Value iMFI Value OrderOpentime() Buy(1) or sell(2) OrderModified()
//---------------------------------------------------------------------------------------------
  1. Array size exceeded. It wouldn't have taken 8 posts had you posted all relevant code, (i.e. the declaration.)
  2. You would have known that if you had used strict. Always use strict. Fixing the warnings will save you hours of debugging, and the debugging would have shown you the exact error.

  3. Now simplify your code and make it self-documenting.

    Instead of using a 2D array
    double Storage [15,7]
    ⋮
    if ( Storage[i,0] == OrderTicket() && Storage[i,6]==0 ){
       Storage[i,6]=1;
       ⋮
    use a 1D array of a struct.
    struct Def{
       int      ticket;
       int      magicNumber;
       double   AO;
       double   MFI;
       datetime OOT;
       int      op_code;   // OP_BUY or OP_SELL
       bool     modified;
    }
    Def Storage[15];
    ⋮
    if ( Storage[i].ticket == OrderTicket() && Storage[i].modified==false ) {
       Storage[i].modified=true;
       ⋮
    

Reason: