Learning and writing together in MQL5 - page 31

 
Urain:

Will Pushkin initialise the string?

Hmmm... I'm not very good at programming, but wouldn't the string be reset every time?

I am interested in its base value, for example, value of double is zero, bool is 1, but what?

Dabble example:

double Statys;

void OnTick()
{
if(Statys == 0)
{OpenBuy();}

}

And it seems to work))


(Exactly, it's not zeroed.)) I never initialized them there.)


 
AUser:

Hmm... I'm not good at programming, but wouldn't the string be reset every time?

I am interested in its base value, e.g. value of double is zero, bool is 1, but what is it?


Exactly, it's not zeroed.) And I never initialized them there)

In MQL5 help it is clearly stated in section Initialization of variables:

Any variable can be initialised when defined. If a variable is not explicitly initialized, the value stored in this variable can be whatever you want. Implicit initialization is not performed.

You are just lucky for a while, but some day you will be unlucky and it will take you an awfully long time to find an error in your code, unaware that the devil is hiding in details. You don't have to rely on the fact that 'I'll get lucky'.
 
Rosh:

The Initialisation of Variables section of the MQL5 help explicitly states:

You are just lucky for the time being, but one day you will be unlucky and you will be agonisingly long searching for a bug in your code, unaware that the devil is hiding in the minutiae. You don't have to rely on "I'll get lucky".
Yes, thank you)) I'll get it right)))
 

I'm writing a simple function to check the direction of indexing in an array. The arrays themselves are taken from OnCalculate(), i.e. have different types (double, datetime, etc.). There are examples of terminal functions in the reference that use header type f(void &array[]) when processing arrays of different types. But compiler swears on using void type in user function. Is there some universal way to tell the compiler that the type of array-parameter is not important for a user function?

 

I would like to clarify Structure of trade request result (MqlTradeResult)

double price; // Price in trade, confirmed by broker

It does not return the price of a pending order? The Expert Advisor has written the following code:

double Statys = 0;
void OnTick()
{
if (Statys == 0)
{OpenBuy();}
}

void OpenBuy()
{
MqlTradeRequest o; MqlTradeResult p;
double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);

o.action = TRADE_ACTION_PENDING;
o.symbol = _Symbol;
o.volume = 1;
o.price = 82,000;
o.sl = 81,800;
o.tp = 82.200;
o.type = ORDER_TYPE_BUY_STOP;
o.type_filling = ORDER_FILLING_AON;
o.type_time = ORDER_TIME_GTC;
OrderSend(o,p);
Statys = p.price;
}


Judging by the fact that we have a lot of open trades, I venture to guess that the answer is price = 0. It's kind of weird though.


Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура результата торгового запроса
Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура результата торгового запроса
  • www.mql5.com
Стандартные константы, перечисления и структуры / Структуры данных / Структура результата торгового запроса - Документация по MQL5
 
Yedelkin:

Is there any universal way to tell the compiler that the type of the array parameter is not important for a user function?

Do an overload function on different data types in the array.
Документация по MQL5: Основы языка / Функции / Перегрузка функций
Документация по MQL5: Основы языка / Функции / Перегрузка функций
  • www.mql5.com
Основы языка / Функции / Перегрузка функций - Документация по MQL5
 
AUser:

I would like to clarify Structure of trade request result (MqlTradeResult)

double price; // Price in trade, confirmed by broker

It does not return the price of a pending order? The Expert Advisor has written such a code:


Judging by the fact that there are a lot of open trades, I venture to guess that the answer is price = 0. This is kind of weird though.


A pending order does not imply making a deal. Take a look at MqlTradeResult structure help :

Field description

Field

Description

retcode

Return code of the trade server

deal

Deal ticket, if a deal has been performed. Reported in the TRADE_ACTION_DEAL trade operation

order

Order ticket, if a ticket has been placed. Notified during a TRADE_ACTION_PENDING trade operation

volume

Volume of the trade confirmed by the broker. It depends on the order filling type

price

Deal price, confirmed by broker. Depends on the deviationfield in the trade request and/or the type of trade

bid

Current market bid price (requote price)

ask

Current market bid price (requote prices)

comment

Broker's comment to the transaction (by default, filled with a decryption)

Also, please insert the code correctly.
 
OK, stop. Do we have to initialize strings too? It's not an atomic type.
 
Rosh:

A pending order does not constitute a trade. Look at the help for the MqlTradeResult structure:

Also, please insert the code correctly.
Got it)
 
TheXpert:
OK, stop. Do we have to initialize strings too? It's not an atomic type.
You should not rely on default initialization. Never.