Search code examples
mql5metatrader5

Print CArray in series instead of new line


I am trying to print the CArrayDouble type of array in series. But instead it is printing line by line. This is not the case with normal array. See below:

double KArray[];
ArrayPrint(KArray);
43.95604 13.97849  9.67742 10.71429 23.07692

But when I did the same with the CArrayDouble type variable array thenit print on newline each output not in series.

CArrayDouble KArray;
for (int i = 0; i< KArray.Total(); i++){PrintFormat("Element: %f", KArray[i]);}
Element: 43.95604 
Element: 13.97849  
Element: 9.67742 
Element: 10.71429 
Element: 23.07692

I want to print them as:

Element: 43.95604 13.97849  9.67742 10.71429 23.07692  

Solution

  • Print or PrintFormat are kind of println in other languages. Unfortunately there is no way (to the best of my belief) to use something like print in other languages. So you have to declare string, add values and then printf at the end.

    string line="";
    for(int i=0;i<Array.Total();i++)line+=" "+KArray.At(i);
    printf("Elements : %s",line);