Questions from Beginners MQL5 MT5 MetaTrader 5 - page 975

 
Tango_X:

Здравствуйте! разложите конструкцию на операторы if... C= (i>0) ? (A>B) ? 1 : (A<B) ? 2 : C: 0;

читал по справке - но не справился)

if
(i>0)   {    if(A>B)      {       C=1;      }    else      {       if(A<B)         {          C=2;         }       else         {          C=C;         }      }   } else   {    C=0;   }

Artyom Trishkin:

This seems to be the case:

SZY. Help has nothing to do with it. It has nothing to do with logic.

Explain where the operation C=C is present

ZS. logic does not work for some reason)

 
Tango_X:

Explain where the operation C=C is present

ZS. The logic does not work for some reason)

Knowing Artyom, I have no doubt that he wrote it correctly, I just want to try to explain in a slightly different way.

C =   // присвоить переменной С значение
(i>0) // если первое условие выполнено
?     // то
(A>B) // если и второе условие выполнено
?     // то С
1     // будет равно 1
:     // иначе, (относится ко второму условию) если второе  условие НЕ выполнено
(A<B) // если третье условие выполнено
?     // то С
2     // будет равно 2
:     // иначе (относится к третьему условию) если третье  условие НЕ выполнено
 C     // то С будет равно предыдущему значению. То-есть изменено не будет
:     // иначе (относится первому условию) если первое условие НЕ выполнено
0     // С будет равно 0
;
 
Alexey Viktorov:

Knowing Artyom, I don't doubt he's got it right, I just want to try and explain it in a slightly different way.

Thank you!

 
Tango_X:

Explain where the operation C=C is present

ZS. logic doesn't work for some reason)

In this:

C = (i>0) ? (A>B) ? 1 : (A<B) ? 2 : C: 0;
ZS. It's working.
 
Artyom Trishkin:

In this one:

ZS. It's working.

Thank you!

 

How do I search in an object array?

Here's how I search through my object array CArrayObj. The task is to find an instance with a value returned by one of the methods, equal to the given one (offset). I do it with full brute force, which turns out to be very long, because of huge number of elements in the array. How to do it correctly?

CArrayObj m_bind_shifts;

CBindParams *CCheckRules::GetBindObjectByOffset(int offset)
  {
   for(int i=0;i<m_bind_shifts.Total();i++)
     {
      if(!CheckPointer(m_bind_shifts.At(i)))
         continue;
      CBindParams *value=m_bind_shifts.At(i);
      if(value==NULL)
         continue;
      //Print(__FUNCTION__+": offset from array: ",value.Shift());
      if(value.Shift()==offset)
        {
         return GetPointer(value);
        }
     }
   CBindParams *value=new CBindParams();
   value.GroupID(0);
   return value;
  }

In C#, this is easy:

Find (x=>x.method()==value)

And it doesn't even matter if the list is sorted or not. But how to do it here? I haven't found any ready-made methods in CList either.

 
Juer:

How do you search through an array of objects?

Here's how I search my array of CArrayObj objects. The task is to find an instance with value returned by one of methods, equal to the given one (offset). I'm doing this with full search, which turns out very long, because of the huge number of elements in the array. What should I do correctly?

In C# this is done simply:

Find (x=>x.method()==value)

And it doesn't even matter if the list is sorted or not. But how to do it here? I haven't found any ready-made methods in CList either.

offset I have here is unique. Would CHashMap help me? But it's so complicated... :(

But it's still not clear. My object has a bunch of methods. How do I get a pointer to the object?

 
Juer:

The offset I have here is unique. CHashMap will probably help me? But it's complicated... :(

But it's still not clear. My object has a lot of methods. How can I get a pointer to an object?

https://www.mql5.com/ru/articles/1334#summary I think that's it.
Рецепты MQL5 - Реализуем ассоциативный массив или словарь для быстрого доступа к данным
Рецепты MQL5 - Реализуем ассоциативный массив или словарь для быстрого доступа к данным
  • www.mql5.com
Эта статья описывает удобный класс для хранения информации - ассоциативный массив или словарь. Благодаря этому классу можно получать доступ к информации по ее ключу. Ассоциативный массив напоминает обычный массив, однако вместо индекса он использует некий уникальный ключ, например, перечисление ENUM_TIMEFRAMES или какой-либо текст. Что...
 
Juer:

... The task is to find an instance with a value returned by one of the methods equal to the given one (offset). I'm doing it with brute force, which takes a very long time, due to huge number of elements in the array. ...

It is easy to do this in C#:

Find (x=>x.method()==value)

And it doesn't even matter if the list is sorted or not.

And in C#, does this lambda-expression, with the help of some magic, work straightforwardly?

If method() returns the same value - search through the dictionary. If the value is different each time - only a full search each time.

 
Vasiliy Sokolov:

And in C#, does this lambda-expression, with the help of some magic, work straightforwardly?

If method() returns the same value - search through the dictionary. If the value is different each time - only a full search each time.

Well, yes, there is a Linq. Identical values. Yes, I'm catching a crash on one of my machines. Code is the same everywhere.

On adding m_dict.AddObject(str_array[0],field);

GN      2       18:25:19.855    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   Access violation at 0x00007FF7EA6B79CF read to 0x000001EA0000006E
IO      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7940 48895 C2408        mov        [rsp+0x8], rbx
JN      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7945 57                push       rdi
FQ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7946 4883 EC20          sub        rsp, 0x20
MK      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B794A 488 B4108          mov        rax, [rcx+0x8]
NG      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B794E 33 DB              xor        ebx, ebx
NF      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7950 488 BF9            mov        rdi, rcx
FF      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7953 4885 C0            test       rax, rax
OM      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7956 740 E              jz         0x7ff7ea6b7966
LS      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   
LF      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7958 48395808          cmp        [rax+0x8], rbx
GK      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B795C 7568              jnz        0x7ff7ea6b79c6
MQ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   
FK      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B795E 488 B00            mov        rax, [rax]
LF      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7961 4885 C0            test       rax, rax
MG      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7964 75 F2              jnz        0x7ff7ea6b7958
OQ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   
EH      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7966 488 D15932A1800    lea        rdx, [rip+0x182a93]
HE      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B796D B918000400        mov        ecx, 0x40018
HK      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7972 E8919CE8FF        call       0x7ff7ea541608  ; #12238 (metatester64.exe)
DQ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7977 4885 C0            test       rax, rax
RM      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B797A 750 B              jnz        0x7ff7ea6b7987
QE      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   
ML      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B797C 488 B5C2430        mov        rbx, [rsp+0x30]
NO      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7981 4883 C420          add        rsp, 0x20
OR      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7985 5 F                pop        rdi
OD      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7986 C3                ret        
GH      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   
OR      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7987 895810            mov        [rax+0x10], ebx
KN      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B798A 4 C8D4014          lea        r8, [rax+0x14]
GJ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B798E 488 B4F08          mov        rcx, [rdi+0x8]
KF      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7992 8 BD3              mov        edx, ebx
FD      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7994 488908            mov        [rax], rcx
NK      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B7997 48894708          mov        [rdi+0x8], rax
IO      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B799B 0 F1F440000        nop        [rax+rax+0x0]
DQ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79A0 498918            mov        [r8], rbx
DO      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79A3 4 D8D8000010000    lea        r8, [r8+0x100]
QO      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79AA 4863 CA            movsxd     rcx, edx
IF      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79AD 488 D5814          lea        rbx, [rax+0x14]
KJ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79B1 48 C1E108          shl        rcx, 0x8
KF      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79B5 FFC2              inc        edx
EH      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79B7 4803 D9            add        rbx, rcx
KS      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79BA 81 FA00040000      cmp        edx, 0x400
IM      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79C0 72 DE              jb         0x7ff7ea6b79a0
RM      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   
PE      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79C2 48895808          mov        [rax+0x8], rbx
GL      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79C6 488 B5008          mov        rdx, [rax+0x8]
OS      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79CA 488 B5C2430        mov        rbx, [rsp+0x30]
KS      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00      crash -->  00007 FF7EA6B79CF 488 B0A            mov        rcx, [rdx]
CL      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79D2 48894808          mov        [rax+0x8], rcx
JJ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79D6 488902            mov        [rdx], rax
ND      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79D9 FF4010            inc        dword [rax+0x10]
JK      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79DC 488 D4208          lea        rax, [rdx+0x8]
QQ      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79E0 4883 C420          add        rsp, 0x20
LL      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00                 00007 FF7EA6B79E4 5 F                pop        rdi
MR      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   
CK      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   00: 0x00007FF7EA6B79CF
FH      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   01: 0x000001EA99EB0478
KL      2       18:25:19.862    CandleTypeStrategy (GBPUSD,M30) 2016.01.01 00:00:00   02: 0x0000000000000001
Reason: