Is there a command to set multi-field arrays?

 
Hi Guys,

I am looking for a way to handle an array with multiple fields.
Is there a command to establish an array like 'myArray [int field1, double filed2, string field3]




Also, what is the command to 'push' the array 'forward'?

i.e for an example if the array has 3 places.. then

myArray[2]==myArray[1]
myArray[1]==myArray[0]

..and a new value is set into myArray[0]

Is the one command to do that?


James
 
  1. JJF:
    I am looking for a way to handle an array with multiple fields.
    Is there a command to establish an array like 'myArray [int field1, double filed2, string field3]
    Does not exist is mql4. An array is a collection of only one type. Use the pattern int myArray.field1[]; double myArray.field2[]; string myarray.field3[];

  2. JJF:

    Also, what is the command to 'push' the array 'forward'?

    i.e for an example if the array has 3 places.. then

    myArray[2]==myArray[1]
    myArray[1]==myArray[0]

    ..and a new value is set into myArray[0]

    No command but can be done
    ResizeBuffer(mem, ArraySize(mem)+1);
    ...
    bool    ResizeBuffer(double& buffer[], int size){
        if (ArraySize(buffer) != size){
            ArraySetAsSeries(buffer, false);    // Shift values B[2]=B[1]; B[1]=B[0]
            if (ArrayResize(buffer, size) <= 0){
                trading.disabled    = "ArrayResize [1] failed: "+GetLastError()
                                    + " Trading disabled.";
                Alert(trading.disabled);    Print(trading.disabled);
                return(false);  }
            ArraySetAsSeries(buffer, true);
        }
        return(true);
    }
    
    See https://www.mql5.com/en/forum/130907
 
Hi WHRoeder,

Thank you for your answer.

The purpose of my routine was to limit the sound announcement when an event (BUY, SELL, SL, TP, Trigger and all kind of other 'graph events') happens.

My thought was to compare the PlaySound("file to play") to the previous sound played, but I found that the 'case' command won't accept string variables.

Well, eventually I did it in different way.


Here is the routine that I wrote. It uses two arrays defined as global:


string sound_stack[10]; //holds the recent played sounds
int time_stack[10]; //hold the time of the 'indexed' sound event

int start()
{
.
.
if (<SL event has happened..>) Sound ("o-o.wav", "SL has occurred", 30);

/*

Where:

field1 = 'file to play'

field2 = the 'alert window' line. it can be a blank string ("")

field3 = the minimum seconds interval that this particular sound can be played again

*/
.
.
return(0); // End of the Main routine !
}

 /*----------------+
  | sound Routine  |
  +----------------*/
void Sound (string file_to_play, string alert_string, int sec_2_pause)
  {
  int play_time=TimeCurrent(), index=-1;

  for( int i = 0; i <= 10; i ++)
     {
     if (sound_stack[i]==file_to_play) // match found !
        {
        index=i;
        break;
        }
     }

  if (index==-1||(time_stack[index]>0&&play_time-time_stack[index]>sec_2_pause)) //if never played or time_of_play > 'sec_2_pause'
     {
     if (alert_string!="")
        {
        alert_string=StringConcatenate(Symbol(),": ",alert_string);
        Alert(alert_string);
        Sleep (5);
        }
     PlaySound(file_to_play);
     play_time=TimeCurrent();

     for( i = 10; i > 0; i --) //storing the last new played event
        {
        sound_stack[i]=sound_stack[i-1];
        time_stack[i]=time_stack[i-1];
        sound_stack[0]=file_to_play;
        time_stack[0]=play_time;
        }
     }

  return;
  }


James