How do you create a new array from all NON empty values in another array?

447 views Asked by At
   for ( int i = limit; i >= 0; i-- )
   {     
         if (  Low[i-1] >  Low[i]
            && Low[i+1] >  Low[i]
               ) Dpivot[i]=Low[i];
   }

This stores the Low price at such bar, where this condition is met into the Dpivot[] array.

But obviously, on bars that it isn't true, the value is 0.

How can I go about creating an array that has all the 0's skipped out and consists of only the actual prices that show up in Dpivot[].

Sorry if this is a really trivial problem. I am very new to programming and MQL4 documentation just leaves me with head pains.

I am really trying to wrap my head around this whole array thing!

My main problem in a lot of instances is to find values when conditions are met, but not being able to reference them again when they are not met, if this makes any sense.

1

There are 1 answers

8
user3666197 On

Corpus details will depend a lot on whether you build a Custom Indicator or some other type of the MQL4 code-execution unit

The principal approach is to fill just non-zero cells into such a new array.

double aNewNonZeroPIVOTsARRAY[];

for ( int nPi = EMPTY,
          dPi = 0; dPi < ArraySize( Dpivot ); dPi++ ) {
      if  ( Dpivot[dPi] > 0. )  aNewNonZeroPIVOTsARRAY[++nPi] = Dpivot[dPi];
}