Merge two arrays

 

I got a code to get the economic calendar of the base currency and quote currency below

void OnStart(){
   string   currencybase      = StringSubstr(_Symbol,0,3) ;
   string   currencyquote      = StringSubstr(_Symbol,3,3) ;
   datetime curdatetime       = TimeTradeServer();
   datetime before            = curdatetime - PeriodSeconds(PERIOD_D1);
   datetime end               = curdatetime + PeriodSeconds(PERIOD_D1);
     
   MqlCalendarValue  value[];
   MqlCalendarEvent  ev1[];


   int x  = CalendarValueHistory(value,before,end,NULL,currencyquote);
   int y = CalendarValueHistory(value,before,end,NULL,currencybase);
   int z =x+y;
   
   ArrayPrint(value);
   Print(x);
   Print(y);
   Print(z);
   

I  want to merge the array of the base and the quote, how can i modify my code 

 
Chrispine Oburu: I got a code to get the economic calendar of the base currency and quote currency below. I  want to merge the array of the base and the quote, how can i modify my code 

Have a look at the ArrayInsert or the ArrayCopy functions.

 
Chrispine Oburu:

I got a code to get the economic calendar of the base currency and quote currency below

Fernando Carreiro #:

Have a look at the ArrayInsert or the ArrayCopy functions.

I  want to merge the array of the base and the quote, how can i modify my code 

they just insert new values  instead of appending

 
Chrispine Oburu #: they just insert new values  instead of appending

So, why would that be a problem? You should think outside the box.

For ArrayInsert, you can insert at the beginning of an array, and for both ArrayInsert and ArrayCopy you can extend the array size and copy to the end of the original size.

Choose the method that will be most efficient for your needs.

EDIT: Depending on how you use them, you may not even need to resize the array as it automatically expands it.

EDIT2: Have a look at the example code in the documentation for both and experiment with the two functions.

 

Simple appending example ...

void OnStart()
{
   string
      sBaseSymbols[]  = { "AUD", "NZD", "EUR", "XAU" },
      sQuoteSymbols[] = { "SGD", "USD", "GBP" },
      sAllSymbols[];
      
   PrintFormat( "Size: %d", ArraySize( sAllSymbols ) );

   ArrayCopy( sAllSymbols, sBaseSymbols, ArraySize( sAllSymbols ) );
   PrintFormat( "Size: %d", ArraySize( sAllSymbols ) );

   ArrayCopy( sAllSymbols, sQuoteSymbols, ArraySize( sAllSymbols ) );
   PrintFormat( "Size: %d", ArraySize( sAllSymbols ) );
};
Size: 0
Size: 4
Size: 7
 
Fernando Carreiro #:

Simple appending example ...

thanks big time

 
Chrispine Oburu #: thanks big time
You are welcome!