tradepechti:
hello,
if one function offers me values like 1,1,2,2,1,1,4,4,3 how i can bring them to 1,2,1,4,3.... plz help :)
Forum on trading, automated trading systems and testing trading strategies
Icham Aidibe, 2018.03.05 18:56
I would have do it so, it's not as nerdy as the above snippet, but it works well :
#include <Arrays\ArrayInt.mqh> // Include lib // int MyArray[]={5,7,5,3,3,4,7,7,3,4,4,3}; // int CountItem(int &Array[]) { CArrayInt *TempArray=new CArrayInt(); CArrayInt *ItemsFound=new CArrayInt(); int value = 0; TempArray.AssignArray(MyArray); TempArray.Sort(); for(int x=0;x<TempArray.Total();x++) { if(ItemsFound.Search(TempArray.At(x))<0) { ItemsFound.Add(TempArray.At(x)); ItemsFound.Sort(); } else { continue; } } printf("*** Items found in array : %g",ItemsFound.Total()); value = ItemsFound.Total(); delete(TempArray); delete(ItemsFound); return(value); } // DifArrayNbr = CountItem(MyArray); // Function call //+------------------------------------------------------------------+
if one function offers me values like 1,1,2,2,1,1,4,4,3 how i can bring them to 1,2,1,4,3.... plz help :)
I'm assuming from you example you want to suppress sequential duplicates. To do that, just use a hold value.
int value = 0; int holdvalue = -1; while ( true ) { // The function gives the values in succession, e.g. // 1,1,2,2,1,1,4,4,3, . . . value = one_function(); // Always have a way to get out of an infinite loop if ( value == -1 ) { break; } // suppress inline duplicates if ( value != holdvalue ) { Print(StringFormat("one_function returned [%d]", value)); holdvalue = value; } }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hello,
if one function offers me values like 1,1,2,2,1,1,4,4,3 how i can bring them to 1,2,1,4,3.... plz help :)