Features of the mql5 language, subtleties and tricks - page 39

 
Vasiliy Sokolov:
There was no mention of completely replacing the casting.
Yes, they cut off the possibilities.
 
Vasiliy Sokolov:

Arbitrary casting via writing/reading binary... Lights out. No need to read further...

Do you have a better suggestion?
 
Vasiliy Sokolov:

p.s. I looked at your code:

Arbitrary casting via write/read binary... Lights out. Don't read further.

There's arbitrary casting via union - any simple structures without custom constructors and copy operators. For all the articles on this site, this casting will work.

template <typename T>
class CASTING
{
public:
  template <typename T1>
  static const T Casting( const T1 &Value )
  {
    union CAST
    {
      T1 Value1;
      const T Value2;

      CAST( const T1 &Value)
      {
        this.Value1 = Value; // кастомный оператор может все испортить
      }
    };

    const CAST Union(Value);

    return(Union.Value2);
  }
};

#define _C(A, B) CASTING<A>::Casting(B)

void OnStart()
{
  MqlTick Tick = {0};
  
  Tick = _C(MqlTick, Tick); // Tick = (MqlTick)Tick;
}

But if you want to cover 100% of castings - via files. There is a choice.

 
Combinator:
Got a better suggestion?
Obviously don't use custom constructors in structures and assignment operators. Write simple code.
 
Vasiliy Sokolov:
Obviously do not use custom constructors in structures and assignment operators. Write simple code.
Then you need to abandon const fields of structures.
 

It's a popular test

if (ArrayResize(Array, NewSize) == NewSize)
// ....

Well, it's not the same as

if (ArrayResize(Array, NewSize) == ArraySize(Array))
// ....
 

Actually ArrayResize() returns

Return value

If successful, the function returns the number of all elements contained in the array after resizing; otherwise, it returns -1 and the array is not resized.


 
Roffild:

Actually, ArrayResize() returns

They changed the behavior a year ago. They clarified it in the Help this week.
 
CopyTicks asynchronous only in indicators

Now there is only one request for indicators and we switch off with those data which are there. Swap works for itself.

Expert Advisors and scripts are a bit different. There are several attempts to wait for the necessary data. As long as the data arrives, attempts are made. As soon as there are problems with the connection, we immediately pause.

 

Forum on trading, automated trading systems and trading strategies testing

Registration for the MetaQuotes-Demo Championship in May

Vladimir Karputov, 2017.05.05 11:54

Added. Yes, I need to cycle through the entire signal base in the terminal:

SignalBaseTotal

Returns the total number of signals available in the terminal


By the way, I recommend before this run (especially when switching from another server or right after the start) to click at least once on the "Signals" tab of the terminal - this should activate the paging of the actual database.