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

 
Vasiliy Pushkaryov:
Do you have a picture of how it would look like? It's not quite clear, I haven't usedOBJ_CHART yet

There is no picture. But you can build it by hand. Select Insert -> Objects -> Graphic Objects -> Graphic and after inserting OBJ_CHART like this, select "Draw object as background" in object properties, disabling scales.

 
fxsaber:

There is no picture. But you can build it by hand. Choose Insert -> Objects -> Graphic Objects -> Graphic and after inserting OBJ_CHART like this, select "Draw object as background" in the object properties, disabling scales.


Thanks, looks cool

 

In debug mode, you cannot know the value returned by a function or expression.

For example

void OnStart()
{
  double Angle = 1;
  double d = MathSin(Angle / 2) * MathSin(Angle * 2);
}

For example, what the selected functions returned.


I use (not only in debug mode) this way

template <typename T>
T MyPrint( const T Value, const string Str )
{
  static const bool IsDebug = MQLInfoInteger(MQL_DEBUG);

//  if (IsDebug)
  {
//    DebugBreak(); // если хочется посмотреть средствами дебага

    Print(Str + " = " + (string)Value);
  }
  
  return(Value);
}

#define _P(A) MyPrint(A, __FUNCSIG__ ", Line = " + (string)__LINE__ + ": " + #A)

void OnStart()
{
  double Angle = 1;
  double d = _P(MathSin(Angle / 2)) * _P(MathSin(Angle * 2));
}


Result

void OnStart(), Line = 21: MathSin(Angle/2) = 0.479425538604203
void OnStart(), Line = 21: MathSin(Angle*2) = 0.9092974268256817
 

Structure of Trade Request Check Result (MqlTradeCheckResult)

Fields description

Field

Description

balance

Balance value that will be after the trade operation execution

equity

Value of equity, which will be after the trade operation

margin

Margin required for the required trade operation

margin_free

The amount of equity that will remain after the required trade operation is executed

margin_level

The margin level that will be set after the execution of the required trade operation

These fields correspond to the line in the Trade tab


Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура результата проверки торгового запроса
Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура результата проверки торгового запроса
  • www.mql5.com
Прежде чем отправить торговому серверу запрос на торговую операцию, рекомендуется провести его проверку. Проверка осуществляется функцией OrderCheck(), которой передается сам проверяемый запрос и переменная типа структуры MqlTradeCheckResult. В эту переменную и будет записан результат проверки.
 
fxsaber:

These fields correspond to the line in the Trade tab


The same values show the current state, and isn't the structure returning the calculated values that will be after the trade is executed?

 
Artyom Trishkin:

The same values show the current state, but isn't the structure returning the calculated values that will be there after the trade is executed?

Shows the calculated values that would be in this line if the trade order were executed.

 

Forum on trading, automated trading systems and trading strategies testing

Generic classes library - errors, description, questions, peculiarities of use and suggestions

Renat Fatkhullin, 2017.12.08 23:34

We have no MqlDeal structure, as trade record formats are floating and periodically expanding. Without this, it is impossible to expand the functionality of the platform.

Therefore, the only option is to access them through the Get function. And access to other fields of the previously affected record is many times faster than the first access, because the record is cached.

In the test above, the trade numbers are new every time, which constantly throws off the cache of the previously selected trade.

 

Forum on trading, automated trading systems and trading strategies testing

MT5 vs MT4. The speed of filling the arrays.

Renat Fatkhullin, 2017.12.12 12:19

1) The idea is wrong, local arrays do not fill faster (roughly, without dropping to the micro level)

2) Arrays should be filled quickly via regular initialization functions

3) To maximize speed, it's better to keep the array as a vector (one-dimensional), so that you have more chances to optimize access. Because multidimensionality strictly limits you to mandatory frames and forces the compiler to do extra constant calculations of multidimensional indices.

4) Arrays for quick access should be kept static, which dramatically reduces the amount of checks for out-of-bounds

 

Forum on trading, automated trading systems and testing trading strategies

Opening sell position in mql5

fxsaber, 2017.12.12 21:56

// true - not for trade by market-orders
bool IsBadFilling( const string Symb )
{
  return(!(SymbolInfoInteger(_Symbol, SYMBOL_FILLING_MODE) & (SYMBOL_FILLING_IOC | SYMBOL_FILLING_FOK)));
}

void OnTick()
{
  if (IsBadFilling(_Symbol))
  {
    Print("Change symbol " + _Symbol + " or server " + AccountInfoString(ACCOUNT_SERVER) + " for trade by market!");
    
    ExpertRemove();    
  }
}


Result

2017.12.05 00:00:00   Change symbol EURUSD or server AMPGlobalClearing-Demo-CQG for trade by market!

Allows you to quickly figure out why markets are not opening in the tester. Maybe it's the tester's wrong behavior when market orders are banned like this and pending orders are not.


I suggest that if SYMBOL_FILLING_MODE is zero, the tester should replace this value with(SYMBOL_FILLING_IOC | SYMBOL_FILLING_FOK). I.e., it allowed full trade at invalid setting of the corresponding symbol field by the broker.

 
// Опознает кривые COPY_TICKS_INFO-тики
// Отсутствие цены (высохшая сторона стакана - нулевая цена) не признается валидной ситуацией
bool IsTickInfoBad( const MqlTick &Tick )
{
  return(!Tick.ask || !Tick.bid || Tick.last || Tick.volume || ((Tick.flags & (0x7F ^ (TICK_FLAG_ASK | TICK_FLAG_BID))) != 0));
}

#define  DEFINE_FIELD(A)             \
  if (!Ticks[i].##A)                \
    Ticks[i].##A = Ticks[i - 1].##A

// Корректирует ошибочные COPY_TICKS_INFO-тики
void CorrectTicksInfo( MqlTick &Ticks[] )
{
  const int Size = ArraySize(Ticks);
  
  for (int i = 1; i < Size; i++)
    if (IsTickInfoBad(Ticks[i]))
    {
      DEFINE_FIELD(bid);
      DEFINE_FIELD(ask);      
      
      Ticks[i].last = 0;
      Ticks[i].volume = 0;
      Ticks[i].flags = TICK_FLAG_ASK | TICK_FLAG_BID;
    }
}
I recommend to do something like this every time after CopyTicks(COPY_TICKS_INFO), so that the TS does not accidentally drain the account.