Download MetaTrader 5

How to Find an Array in Array?

To add comments, please log in or register
arbteylim
7
arbteylim  
Warning: Rookie alert.

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
Vladimir Karputov
Moderator
76320
Vladimir Karputov  
arbteylim:
Warning: Rookie alert.

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 |
//|                              Copyright © 2016, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "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:
To add comments, please log in or register