# How to Find an Array in Array?

7

Suppose we have a custom array of say 1's and 0's. Is it possible to lookup for an array of pattern inside that array? How do we translate that into a code?

e.g.
MyArray[] = {0,1,1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,1,1,1,0,0...} //customized array
PatternArray[5] = {1,0,1,0,1} //pattern to look for inside MyArray

TIA
Moderator
76320

arbteylim:

Suppose we have a custom array of say 1's and 0's. Is it possible to lookup for an array of pattern inside that array? How do we translate that into a code?

e.g.
MyArray[] = {0,1,1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,1,1,1,0,0...} //customized array
PatternArray[5] = {1,0,1,0,1} //pattern to look for inside MyArray

TIA

Need to compare two arrays using: ArrayCompare.

Code:

```//+------------------------------------------------------------------+
//|                                                 ArrayCompare.mq5 |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
int MyArray[]={0,1,1,0,0,1,0,0,1,0,1,0,1,0,0,0,1,1,1,1,0,0}; //customized array
int PatternArray[5]={1,0,1,0,1};          //pattern to look for inside MyArray
//---
for(int i=0;i<ArraySize(MyArray);i++)
{
if(ArrayCompare(MyArray,PatternArray,i,0,ArraySize(PatternArray))==0)
Print(IntegerToString(i));
}
}
//+------------------------------------------------------------------+
```
Files: