//+------------------------------------------------------------------+ //| CheckArrayCopy.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| https://www.metaquotes.net/ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "https://www.metaquotes.net/ru" //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- int a[10][2]; int b[10][2]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; for (int i=0;i<10;i++) Print("i=",i," b[i,0]=",b[i,0]," b[i,1]=",b[i,1]); ArrayCopy(a, b, 0, 2); Print("ArrayCopy(a, b, 0, 2)"); for (i=0;i<10;i++) Print("i=",i," a[i,0]=",a[i,0]," a[i,1]=",a[i,1]); //---- return(0); } //+------------------------------------------------------------------+Results:
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: removed
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=9 a[i,0]=0 a[i, 1]=0
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=8 a[i,0]=19 a[i, 1]=20
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=7 a[i,0]=17 a[i, 1]=18
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=6 a[i,0]=15 a[i, 1]=16
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=5 a[i,0]=13 a[i, 1]=14
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=4 a[i,0]=11 a[i, 1]=12
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=3 a[i,0]=9 a[i, 1]=10
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=2 a[i,0]=7 a[i, 1]=8
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=1 a[i,0]=5 a[i, 1]=6
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=0 a[i,0]=3 a[i, 1]=4
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: ArrayCopy(a, b, 0, 2)
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=9 b[i,0]=19 b[i, 1]=20
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=8 b[i,0]=17 b[i, 1]=18
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=7 b[i,0]=15 b[i, 1]=16
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=6 b[i,0]=13 b[i, 1]=14
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=5 b[i,0]=11 b[i, 1]=12
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=4 b[i,0]=9 b[i, 1]=10
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=3 b[i,0]=7 b[i, 1]=8
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=2 b[i,0]=5 b[i, 1]=6
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=1 b[i,0]=3 b[i, 1]=4
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: i=0 b[i,0]=1 b[i, 1]=2
2007.01.24 10:56:03 CheckArrayCopy EURUSD,H1: loaded successfully
and modified code
//+------------------------------------------------------------------+ //| CheckArrayCopy2.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| https://www.metaquotes.net/ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "https://www.metaquotes.net/ru" //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- int a[10][2]; int b[10][2]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; for (int i=0;i<10;i++) Print("i=",i," b[i,0]=",b[i,0]," b[i,1]=",b[i,1]); ArrayCopy(a, b, 0, 2,4); Print("ArrayCopy(a, b, 0, 2, 4)"); for (i=0;i<10;i++) Print("i=",i," a[i,0]=",a[i,0]," a[i,1]=",a[i,1]); //---- return(0); } //+------------------------------------------------------------------+
Results
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: removed
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=9 a[i,0]=0 a[i, 1]=0
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=8 a[i,0]=0 a[i, 1]=0
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=7 a[i,0]=0 a[i, 1]=0
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=6 a[i,0]=0 a[i, 1]=0
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=5 a[i,0]=0 a[i, 1]=0
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=4 a[i,0]=0 a[i, 1]=0
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=3 a[i,0]=0 a[i, 1]=0
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=2 a[i,0]=0 a[i, 1]=0
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=1 a[i,0]=5 a[i, 1]=6
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=0 a[i,0]=3 a[i, 1]=4
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: ArrayCopy(a, b, 0, 2, 4)
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=9 b[i,0]=19 b[i,1]=20
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=8 b[i,0]=17 b[i,1]=18
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=7 b[i,0]=15 b[i,1]=16
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=6 b[i,0]=13 b[i,1]=14
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=5 b[i,0]=11 b[i,1]=12
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=4 b[i,0]=9 b[i, 1]=10
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=3 b[i,0]=7 b[i, 1]=8
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=2 b[i,0]=5 b[i, 1]=6
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=1 b[i,0]=3 b[i, 1]=4
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: i=0 b[i,0]=1 b[i, 1]=2
2007.01.24 11:01:19 CheckArrayCopy2 EURUSD,H1: loaded successfully
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
int b[10][2];
ArrayCopy(a, b, 0, 2);
What does the start index of 2 (or the zero) mean in this context? Is it the 2nd index on rank 0, or the 2nd absolute element?
How does one copy arrays as above if say I only wanted the last 2 elements using rank 0.
e.g. a = [1,2][3,4][5,6][7,8] -> b = [5,6][7,8]