Selects an open position for further work with it according to the specified ticket.
but just note that the PositionSelect() and PositionSelectByTicket() functions have a peculiarity:
PositionSelect() и PositionSelectByTicket() копируют данные о позиции в программное окружение, и последующие вызовы PositionGetDouble(), PositionGetInteger() и
PositionGetString() возвращают ранее скопированные данные. Это означает, что самой позиции может уже и не быть (или же она изменилась по объему,
направлению и т.д.), а данные этой позиции можно еще получать.
Для гарантированного получения свежих данных о позиции рекомендуется вызывать функцию PositionSelect() и PositionSelectByTicket() непосредственно перед обращением за ними.
I use the code in the Expert Advisor literally from the help
//| Trade function | //+------------------------------------------------------------------+ voidOnTrade()
{
//--- получим тикет последней сделки из истории торговли за неделю ulong last_deal=GetLastDealTicket();
if(HistoryDealSelect(last_deal))
{
//--- время совершения сделки в миллисекундах от 01.01.1970 long deal_time_msc=HistoryDealGetInteger(last_deal,DEAL_TIME_MSC);
PrintFormat("Deal #%d DEAL_TIME_MSC=%i64 => %s",
last_deal,deal_time_msc,TimeToString(deal_time_msc/1000));
}
elsePrintFormat("HistoryDealSelect() failed for #%d. Eror code=%d",
last_deal,GetLastError());
//---
}
//+------------------------------------------------------------------+ //| Возвращает тикет последней сделки в истории или -1 | //+------------------------------------------------------------------+ ulong GetLastDealTicket()
{
//--- запросим историю за последние 7 дней if(!GetTradeHistory(7))
{
//--- сообщим о неудачном вызове и вернем -1 Print(__FUNCTION__," HistorySelect() вернул false");
return -1;
}
//--- ulong first_deal,last_deal,deals=HistoryOrdersTotal();
//--- если ордера есть, начинаем работать с ними if(deals>0)
{
Print("Deals = ",deals);
first_deal=HistoryDealGetTicket(0);
PrintFormat("first_deal = %d",first_deal);
if(deals>1)
{
last_deal=HistoryDealGetTicket((int)deals-1);
PrintFormat("last_deal = %d",last_deal);
return last_deal;
}
return first_deal;
}
//--- не нашли ни одной сделки, вернем -1 return -1;
}
//+------------------------------------------------------------------+ //| Запрашивает историю за последние дни и вернет false при неудаче | //+------------------------------------------------------------------+ bool GetTradeHistory(int days)
{
//--- зададим недельный период времени для запроса торговой истории datetime to=TimeCurrent();
datetime from=to-days*PeriodSeconds(PERIOD_D1);
ResetLastError();
//--- сделаем запрос и проверим результат if(!HistorySelect(from,to))
{
Print(__FUNCTION__," HistorySelect=false. Error code=",GetLastError());
returnfalse;
}
//--- история получена успешно returntrue;
}
At the beginning it works correctly in the tester, but then I get an error in the log. Why?
ulong first_deal,last_deal,deals=HistoryOrdersTotal();
//--- если ордера есть, начинаем работать с ними if(deals>0)
{
Print("Deals = ",deals);
first_deal=HistoryDealGetTicket(0);
PrintFormat("first_deal = %d",first_deal);
if(deals>1)
{
last_deal=HistoryDealGetTicket((int)deals-1);
PrintFormat("last_deal = %d",last_deal);
return last_deal;
}
return first_deal;
}
//--- не нашли ни одной сделки, вернем -1 return -1;
HistoryDealGetTicket
Orders, deals and positions should not be confused with each other. Each deal is the result of some order execution, each position is the final result of one or more deals.
Orders, deals and positions should not be confused with each other. Each deal is the result of the execution of an order, each position is the final result of one or more deals.
You copy the code I have given you for what purpose, what does it explain?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
First you need to select the position you are going to work with using one of the functions below:
PositionGetSymbol
Returns the symbol of the corresponding open position
PositionSelect
Selects an open position for further work with it.
PositionSelectByTicket
Selects an open position for further work with it according to the specified ticket.
but just note that the PositionSelect() and PositionSelectByTicket() functions have a peculiarity:
then you need to get its Magic:
and then you can use position_magic where you want.
Regards, Vladimir.
First select the position you are going to work with using one of the functions below:
PositionGetSymbol
Returns the symbol of the corresponding open position
PositionSelect
Selects the open position for further work with it.
PositionSelectByTicket
Selects an open position for further work with it by the specified ticket
but just note that the PositionSelect() and PositionSelectByTicket() functions have a peculiarity:
Then you need to get its Magic:
and then you can use position_magic wherever you want.
Regards, Vladimir.
I even wondered, then what was the question?
Regards, Vladimir.
I was wondering, what was the question then?
Regards, Vladimir.
Which magik is installed in the commercial facility. I'd answer, but I'm not at my computer yet.
Something seems to me from the object is not available. Magik is in the protected area:
Here's a question I have.
I use the code in the Expert Advisor literally from the help
At the beginning it works correctly in the tester, but then I get an error in the log. Why?
Here is an example that it works a little earlier
Here's a question I have.
I am using the code in the Expert Advisor literally from the help
At the beginning it works correctly in the tester, but then I get an error in the log. Why?
Here is an example that it works a little earlier
Because
last_deal = 0Because.
So that's the question, why zero?
So that's the question, why zero?
Orders, deals and positions should not be confused with each other. Each deal is the result of some order execution, each position is the final result of one or more deals.
HistoryDealGetTicket
Orders, deals and positions should not be confused with each other. Each deal is the result of the execution of an order, each position is the final result of one or more deals.
You copy the code I have given you for what purpose, what does it explain?