Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1948

 

Can you please tell me how to solve:

1) I have not loaded the history, in the chart window during the online process I had time to load 70 000 minute bars. I am loading my Expert Advisor in the Strategy Tester and just in case I have written the minimum number of bars for a certain pattern, it answered with "not enough bars for analysis". I print iBars and it says 1200 bars. I loaded history (8 000 000 bars). Restarted, settings show "9999999999" bars in window and history. Nova writes "not enough history". Print iBars, again 1200. what is this and how to solve it?

2) In the multicurrency analysis, how can I force the indicator not to miss new incoming ticks on other currency pairs, if the quotes are suddenly frozen on the current chart and OnTick does not call the check? I tried OnTimer but it does not work in the tester

 
In this script, I'm experimenting with resizing dynamic arrays that have different indexing directions - in order to understand which side new cells appear after increasing array size
void OnStart()
  {
   
   int a[], b[], size = 5, new_size = size + 5;
   
   if( ArraySize( a ) != size )
     ArrayResize( a, size, 0 );
   
   if( ArraySize( b ) != size )
     ArrayResize( b, size, 0 );
   
   if( ArrayGetAsSeries( a ) )
     ArraySetAsSeries( a, false );
   
   if( !ArrayGetAsSeries( b ) )
     ArraySetAsSeries( b, true );
   
   for( int i = 0; i < size; i++ )
     {
      a[i] = i;
      b[i] = i;
     };
   
   ArrayResize( a, new_size, 0 );
   ArrayResize( b, new_size, 0 );
   
   for( int i = 0; i < new_size; i++ )
     {
      Alert( "a", i, " ", a[i] );
      Alert( "b", i, " ", b[i] );
      Alert(" ");
     };
   
  }

And here is the result


It turns out that array b[] (which has reverse indexation) somehow duplicates its values after increasing the size

. Why? Am I missing something or have I made some mistake?
 
Alexandr Sokolov indexing directions - in order to understand which side new cells appear after increasing array size

And this is the result


It turns out that array b[] (which has reverse indexing) has somehow duplicated values after increasing size

Why? Am I missing something or have I made some mistake?

In any case, we cannot rely on any values in the new array cells - these are uninitialised variables that can contain any rubbish.

 
Alexandr Sokolov indexing directions - in order to understand which side new cells appear after increasing the array size

And this is the result


It turns out that array b[] (which has reverse indexing) has somehow duplicated values after increasing the size

Why? Am I missing something or have I made some mistake?

You have to flip the array after it has been filled.

 
JRandomTrader #:

In any case we can't rely on any values in the new array cells - these are uninitialized variables that can contain any rubbish.

True, but there are 2 buts
1) Mirroring is observed at any other size and not only, as in my example - 5
2) If an array has reverse indexing, then new cells should appear at the beginning of the array - which is not the case

 
Alexey Viktorov #:

You have to flip the array after filling it.

I also thought of that - at least I don't see any other solution at the moment

 
Alexandr Sokolov #:


2) If an array is reverse-indexed, then new cells should appear at the beginning of the array - which is not the case

Why should new cells appear at the beginning of an array? - If I'm not mistaken, it should be written in the help, that when you use ArraySetAsSeries(), the array will not be physically reallocated in memory, but reverse indexing will be applied when accessing array elements

SZZ: your example is complicated, I sketched it out:

#property strict
//+------------------------------------------------------------------+
void OnStart()
{
   int arr1[] = {1, 2, 3, 4, 5};
   int arr2[] = {1, 2, 3, 4, 5};
   ArraySetAsSeries(arr2, true);
   Print("Start size : ", ArraySize(arr1), " , ", ArraySize(arr2));
   Print("Resize : ", ArrayResize(arr1, 10), " , ", ArrayResize(arr2, 10));
   string s1 = "", s2 = "";
   for(int i = 0, j = 0; i < ArraySize(arr1) && j < ArraySize(arr2); i++, j++)
   {
      s1 += (string)arr1[i] + " , ";
      s2 += (string)arr2[j] + " , ";
   }
   Print("arr1 = ", s1);
   Print("arr2 = ", s2);
}

2022.04.18 21:31:59.223 tst EURUSD,H1: arr2 = 5 , 4 , 3 , 2 , 1 , 0 , 0 , 0 , 0 , 0 ,

2022.04.18 21:31:59.223 tst EURUSD,H1: arr1 = 1 , 2 , 3 , 4 , 5 , 0 , 0 , 0 , 0 , 0 ,

2022.04.18 21:31:59.223 tst EURUSD,H1: Resize : 10 , 10

2022.04.18 21:31:59.223 tst EURUSD,H1: Start size : 5 , 5

 
Please advise how it works in MT5
iClose(NULL,PERIOD_CURRENT,shift)

I get'iClose' error - ambiguous call to overloaded function.

In general, the goal is to select the TF.

I wanted to choose it with MT4 out of habit

if(iClose(NULL, TF(), 1) < iOpen(NULL, TF(), 1))

int TF()
  {
   int tf;
   switch(TF)
     {
      case 1 :
         tf = 1;
         break;
      case 2 :
         tf = 5;
         break;
      case 3 :
         tf = 15;
         break;
      case 4 :
         tf = 30;
         break;
      case 5 :
         tf = 60;
         break;
      case 6 :
         tf = 240;
         break;
      case 7 :
         tf = 1440;
         break;
      case 8 :
         tf = 10080;
         break;
      case 9 :
         tf = 43200;
         break;
      default:
         tf = 10;
         Print(tf);
     }
   return(tf);
  }

But I have failed.(

 
Александр 'iClose' error - ambiguous call to overloaded function.

In general, the goal is to select the TF.

I wanted to choose it with MT4 out of habit

But I failed.

periods in MT5

if(Period()==1) return "M1";

if(Period()==2) return "M2";

if(Period()==3) return "M3";

if(Period()==4) return "M4";

if(Period()==5) return "M5";

if(Period()==6) return "M6";

if(Period()==10) return "M10";

if(Period()==12) return "M12";

if(Period()==15) return "M15";

if(Period()==20) return "M20";

if(Period()==30) return "M30";

if(Period()==16385) return "H1";

if(Period()==16386) return "H2";

if(Period()==16387) return "H3";

if(Period()==16388) return "H4";

if(Period()==16390) return "H6";

if(Period()==16392) return "H8";

if(Period()==16396) return "H12";

if(Period()==16408) return "Daily";

if(Period()==32769) return "Weekly";

if(Period()==49153) return "Monthly";

 
Andrei Sokolov #:

periods in mt5

if(Period()==1) return "M1";

if(Period()==2) return "M2";

if(Period()==3) return "M3";

if(Period()==4) return "M4";

if(Period()==5) return "M5";

if(Period()==6) return "M6";

if(Period()==10) return "M10";

if(Period()==12) return "M12";

if(Period()==15) return "M15";

if(Period()==20) return "M20";

if(Period()==30) return "M30";

if(Period()==16385) return "H1";

if(Period()==16386) return "H2";

if(Period()==16387) return "H3";

if(Period()==16388) return "H4";

if(Period()==16390) return "H6";

if(Period()==16392) return "H8";

if(Period()==16396) return "H12";

if(Period()==16408) return "Daily";

if(Period()==32769) return "Weekly";

if(Period()==49153) return "Monthly";

Thank you!

Reason: