for ii = 1:(L-1)
if x(ii+1) > x(ii)
tf= true ;
Look at this portion of the code. For each ii in 1:(L-1), this portion of code gets called. This means that the value of tf is being updated 'L' number of times (i.e., when checking every pair of elements).
For example, the last two elements in [ -3 -4 1 2 4] are 2 and 4, which are monotonically increasing. Therefore, on the last iteration the value of tf is set to true and is not affected by the rest of the input.
You should try rewriting your code in a way where the value of tf is only updated to false when an issue is found.