Data mismatch confusion

 

Hi everyone,

 As I was trying to create an array that will assign a unique name to each arrow on the graph ("Down 1", "Down 2", etc.) I got "data mismatch" error.

 

string highArrows[];

...

for (j=0; j<=highPicksCounter-1; j++)

   {

   ArrayResize(highArrows,highPicksCounter);

   ArrayFill(highArrows,j,1,(string)StringConcatenate("Down"," ",(string)IntegerToString(j+1,0,' ')));

   DrawArrowDown(highArrows[j],iTime(NULL,timeFrame,highPicks[j]),High[highPicks[j]]+25*Point,Black);

   } 

 

The error disappear once highArrows type changed from string to bool... Can anyone please help me figure out why string array is a mismatch with what looks to me as a string value that I'm trying to assign to it?

Thank u in advance! 

 
  1. Please EDIT your post and use the SRC button to include your code
  2. As for the Error, where is it occurring? For what line is the error being given?
  3. ArrayFill() cannot be used for string arrays, and this is probably where you are getting your error for "Data Mismatch".
  4. Simplify your Array assignment (see below) and the problem will hopefully resolve itself.
  5. Simplify your Loop (see below)!
  6. Resize the Array before and outside the Loop, not inside it on every iteration (see below).
  7. Also, both "StringConcatenate()" and "IntegerToString()" already return a string, so there is no need to typecast it again ( i.e. no need to use "(string)" ).
  8. As for the rest, since we do not know which line is causing the error and you have not supplied the full code, we are unable to compile and test it ourselves.

The following code is untested!

string highArrows[];
 
ArrayResize( highArrows, highPicksCounter );
for( j = 0; j < highPicksCounter; j++ )
{
   highArrows[ j ] = StringConcatenate( "Down ", j + 1 );
   DrawArrowDown( highArrows[ j ], iTime( NULL, timeFrame, highPicks[ j ] ), High[ highPicks[ j ] ] + 25 * Point, Black );
}
Reason: