ArrayMinumun () returning last value - page 2

 
Pinto André: Noto que agora o valor para dllv é zero e antes obtinha o valor no momento da compra. Igualmente imprimindo o valor do array o retorno é zero. Entendo que o problema deve residir aqui. 

Incluí o valor do buffer que quero calcular (a verde) para indicar que o icustom funciona correctamente.

Please note that "madaily" and "dllv", are locallu created variable within the scope of the function ArrayCalcMin(), and as soon as you return, those variables are discarded (destroyed). You will no longer be able to access them from outside the function.

Even you create functions with the same names outside of the function, they will not be the same ones. The ones create in the function will only have a local scope and will not update the global ones and the contents lost.

Edit: This post of mine as generated a new page, but please note that their are two more of my posts before this, that you will have to read in response to yours.

 
Fernando Carreiro:

Since "minPos" is returning a value of 9, then it definitely is not returning the index of the last bar (or first array element) and therefore seems to be working correctly.

The "dllv" value however, is returning a value 0, so you will have print out the "madaily" contents, at least the first 30 elements or so, to see what the value at 9 and the surround values.

The best is to provide the full source of both Indicator and a small test Script, so that we can replicate it on our end, since we are currently at a point that I am unable to offer further advice without knowing more of the details on your side.

Thank you for the head's up. I've translated my previous post to english. 

So I think that i'm getting closed to find the issue. The minPos is returning the position 9 (the last one) since the value is zero (or not filled).

I've printed the arrays until the 11 position (just in case) an this are the following results:

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array1 = 49.0231

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array2 = 35.7426

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array3 = 28.8379

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array4 = 29.6111

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array5 = 31.6637

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array6 = 37.6187

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array7 = 47.0411

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array8 = 57.8398

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array9 = 0

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array10 = 0

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array11 = 0

I've tried to rest a position in the bars calc but i doesn't solved the issue. is the a way to skip the last position or not take into account the zero?

Please find the code for the iCustom and for the ArrayMin in attachment. 

Thank you Fernando.

AP

Files:
Scolor8.mq4  15 kb
 
Pinto André:

Thank you for the head's up. I've translated my previous post to english. 

So I think that i'm getting closed to find the issue. The minPos is returning the position 9 (the last one) since the value is zero (or not filled).

I've printed the arrays until the 11 position (just in case) an this are the following results:

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array1 = 49.0231

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array2 = 35.7426

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array3 = 28.8379

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array4 = 29.6111

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array5 = 31.6637

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array6 = 37.6187

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array7 = 47.0411

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array8 = 57.8398

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array9 = 0

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array10 = 0

0 23:26:40.598 2018.01.04 16:05:00  FalconTemplate2-5 EURUSD,H4:  array11 = 0

I've tried to rest a position in the bars calc but i doesn't solved the issue. is the a way to skip the last position or not take into account the zero?

please find the code of the icustom:

and this is the code to calculate the array min value with the proposed changes:

Thank you Fernando.

AP

Please don't paste the source code of the indicator as text. It's too long. Just attach it to the post as a file (or provide link to original)! Can your edit your post and do this so that it is not so long please?

Also, can you show the log with the print of the "malookback" value as well please?

EDIT: Please also provide your code in a form that will compile without errors. At the moment it cannot be compiled or used because it is dependent on the "LastOrderTime()" function.

 

Ok, I compile it using a fixed value of "malookback" of 20, so that it would compile.

After running it, the first thing I realised that I did not before, was that your are using the ArrayMinimum over the WHOLE array of 30000 elements, but only a few were actually set. In my case it was only 20.

So making the following change:

int minPos = ArrayMinimum(madaily,malookback,0); // Not "WHOLE_ARRAY"

Second thing I noticed is that since you are using the default inputs of the Indicator, then the Mode 0 you are using is for the "Signal", and not the "Stochastic", just in case that was not the intention.

I also changed the code for the print out as follows:

for(int i = 0; i < malookback; i++)
   Print(" array[",i,"] = ",madaily[i]);

And the log I obtained was as follows:

2021.04.18 23:10:26.601 testcustom EURUSD,H4: initialized
2021.04.18 23:10:26.601 testcustom EURUSD,H4:  malookback = 20
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[0] = 58.9416276828145
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[1] = 58.04457365635498
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[2] = 51.66896258663522
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[3] = 42.95522823834416
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[4] = 36.2070359059039
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[5] = 37.5491902224931
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[6] = 45.12543822630167
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[7] = 53.44397129294075
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[8] = 63.92493539112686
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[9] = 72.78562602691636
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[10] = 84.7393364762721
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[11] = 88.90675752339688
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[12] = 92.69767571727211
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[13] = 91.79352288029482
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[14] = 91.40351961456052
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[15] = 90.41566945789511
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[16] = 89.04791866519609
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[17] = 86.03335864416755
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[18] = 81.59241084760735
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  array[19] = 76.04178528549605
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  minPos = 4
2021.04.18 23:10:26.629 testcustom EURUSD,H4:  dllv = 36.2070359059039
2021.04.18 23:10:26.629 testcustom EURUSD,H4: uninit reason 0
2021.04.18 23:10:26.632 Script testcustom EURUSD,H4: removed
 

I also made the following changes to improve things a bit, including making the Array size adjust to the "malookback" count:

if(malookback < 1)
{
   Print("Something is Wrong with malookback!");
   return(false);
}
            
double dllv = WRONG_VALUE, madaily[];
if( ArrayResize(madaily,malookback) < malookback )
{
    Print("Something is Wrong with resizeing the array!");
    return(false);
}
      
for(int i = 0; i < malookback; i++)
   madaily[i] = iCustom(NULL,0,"Scolor8",0,i);

...

// malookback=0; Don't need this
return( ( dllv >= 0) && ( dllv < 50 ) );

 

I have taken the liberty to rewrite your code in my own way and style, that does not use the Array. Since you are already stepping through the values one by one to fill the array, you might as well just check for the minimum without the extra resources of array management and manipulation:

double GetIndiValue( int index )
{
   return( iCustom( NULL, 0, "Scolor8", 0, index ) );
};

bool CheckIndiMinimum()
{   
   datetime
      Timeorder = LastOrderTime(),
      Timeahora = TimeCurrent(),
      Times     = Timeahora - Timeorder;
                
   int
      m         = TimeMinute(Times),
      h         = TimeHour(  Times),
      d         = TimeDay(   Times),
      bars      = ( ( ( d - 1 ) * 24 * 60 ) + ( h * 60 ) + m ) / 240;
      
   double
      MinValue  = GetIndiValue( 0 );
      
   for( int i = 1; i < bars; i++ )
   {
      double CurrValue = GetIndiValue( i );
      if( CurrValue < MinValue ) MinValue = CurrValue;
   }

   return( ( bars > 0 ) && ( MinValue < 50 ) );
}

And yes, I'm starting the loop at "1", not "0", for a reason; so that it does not execute the for loop, should the number of bars be less than "1".

I also changed the Function name as it is checking ("bool") and not actually building or getting an array.

 
Fernando Carreiro:

I have taken the liberty to rewrite your code in my own way and style, that does not use the Array. Since you are already stepping through the values one by one to fill the array, you might as well just check for the minimum without the extra resources of array management and manipulation:

And yes, I'm starting the loop at "1", not "0", for a reason; so that it does not execute the for loop, should the number of bars be less than "1".

I also changed the Function name as it is checking ("bool") and not actually building or getting an array.

Dear Fernando,

Apologies for the late reply. Just until now that I was able to see your last posts.

Thank you again for your help and dedication, it truly help me understand how arrays work. I will check your last comments thoroughly, I have some doubts about some of them.

I will get back to you soon.

By the way, you code is pretty neat. :) 

Regards!

Andrés P.

 
  1.       Times     = Timeahora - Timeorder;
                    
       int
          m         = TimeMinute(Times),
          h         = TimeHour(  Times),
          d         = TimeDay(   Times),

    TimeXXX() requires a datetime. Times is a duration in seconds.

  2.       bars      = ( ( ( d - 1 ) * 24 * 60 ) + ( h * 60 ) + m ) / 240;
    This assumes every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
              "Free-of-Holes" Charts - MQL4 Articles 20 June 2006
              No candle if open = close ? - MQL4 programming forum
Reason: