Good afternoon, and once again I'm begging. Second day I can't understand why this piece of code doesn't work
//+------------------------------------------------------------------+//| TradeTransaction function |//+------------------------------------------------------------------+voidOnTradeTransaction(constMqlTradeTransaction& trans,
constMqlTradeRequest& request,
constMqlTradeResult& result)
{
//---if(trans.type == TRADE_TRANSACTION_DEAL_ADD)
{
Print("Зашла сделка ########## ",trans.position," ###########");
if(HistoryDealGetInteger(trans.deal, DEAL_ENTRY) == DEAL_ENTRY_IN)// Открылась позиция
{
if(PositionSelectByTicket(trans.position))
{
int SizeArrayPosition = ArraySize(ArrayPosition);
ArrayResize(ArrayPosition,SizeArrayPosition+1);
ArrayPosition[SizeArrayPosition].kod_clana = 0;
ArrayPosition[SizeArrayPosition].open_price = trans.price;
ArrayPosition[SizeArrayPosition].ticket_position = trans.position;
ArrayPosition[SizeArrayPosition].identi_position = PositionGetInteger(POSITION_IDENTIFIER);
ArrayPosition[SizeArrayPosition].open_tyme = (datetime)PositionGetInteger(POSITION_TIME);
ArrayPosition[SizeArrayPosition].type_position = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
ArrayPosition[SizeArrayPosition].StopLoss = trans.price_sl;
ArrayPosition[SizeArrayPosition].TakeProfit = trans.price_tp;
Print("Открыта позиция +++ ",trans.position," +++ записана в структуру ArrayPosition ++++++++++++++");
}
}
if(HistoryDealGetInteger(trans.deal, DEAL_ENTRY) != DEAL_ENTRY_IN)
{
Print("Закрыта позиция --- ",trans.position," --- записана в структуру ArrayDealOut ------------");
}
}
}
Print "Deal entered...." goes fine, then there should be a split, some deals"Open position ...." are printed, but all other deals (these are deals closing position on TakeProfit) are not printed.
I do not understand what is the problem. I will mark the lost trades in colour below.
2020.04.1211:27:33.103 Core 12018.01.0218:54:00 CTrade::OrderSend: market buy 0.01 EURUSD tp: 1.20621 [done at 1.20574]
2020.04.1211:27:33.103 Core 12018.01.0218:54:00 Зашла сделка ##########1042###########
2020.04.1211:27:33.103 Core 12018.01.0218:54:00Открыта позиция +++ 1042 +++ записана в структуру ArrayPosition ++++++++++++++
2020.04.1211:27:33.103 Core 12018.01.0218:54:00 Зашла сделка ########## 1043###########
2020.04.1211:27:33.103 Core 12018.01.0218:54:00Открыта позиция +++ 1043 +++ записана в структуру ArrayPosition ++++++++++++++
2020.04.1211:27:33.103 Core 12018.01.0218:55:43take profit triggered #1039 sell 0.01 EURUSD 1.20579 tp: 1.20532 [#1044 buy 0.01 EURUSD at 1.20532]
2020.04.1211:27:33.103 Core 12018.01.0218:55:43 deal #1044 buy 0.01 EURUSD at 1.20527 done (based on order #1044)
2020.04.1211:27:33.103 Core 12018.01.0218:55:43 deal performed [#1044 buy 0.01 EURUSD at 1.20527]
2020.04.1211:27:33.103 Core 12018.01.0218:55:43 order performed buy 0.01 at 1.20527 [#1044 buy 0.01 EURUSD at 1.20532]
2020.04.1211:27:33.103 Core 12018.01.0218:55:43 Зашла сделка ########## 1039###########
2020.04.1211:27:33.103 Core 12018.01.0218:56:30take profit triggered #1042 sell 0.01 EURUSD 1.20571 tp: 1.20523 [#1045 buy 0.01 EURUSD at 1.20523]
2020.04.1211:27:33.103 Core 12018.01.0218:56:30 deal #1045 buy 0.01 EURUSD at 1.20523 done (based on order #1045)
2020.04.1211:27:33.103 Core 12018.01.0218:56:30 deal performed [#1045 buy 0.01 EURUSD at 1.20523]
2020.04.1211:27:33.103 Core 12018.01.0218:56:30 order performed buy 0.01 at 1.20523 [#1045 buy 0.01 EURUSD at 1.20523]
2020.04.1211:27:33.103 Core 12018.01.0218:56:30 Зашла сделка ##########1042###########
2020.04.1211:27:33.103 Core 12018.01.0218:57:00 На символе EURUSD открылся новый бар в 2018.01.0218:572020.04.1211:27:33.103 Core 12018.01.0218:57:00 market sell 0.01 EURUSD tp: 1.20458 (1.20507 / 1.20509 / 1.20507)
An event has occurred, a trade that closes a position has been executed. The position is already gone at this moment. You can confirm it by selecting a list of orders and deals (there is no such a list in the code) and reading
And note that we are talking about a hadge account where the position usually has only two orders and two trades.
Good afternoon, if it's not too much trouble for you, you have accurately described everything in this post. My two posts above, I am trying to get the result I need - to commit to close a position. I still cannot do it.
Please advise me, where I have a mistake or defect ?????
It seems to me that some changes were made to OnTradeTransaction event handling.
Try to replace TRADE_TRANSACTION_DEAL_ADD with TRADE_TRANSACTION_HISTORY_ADD
Transactions opening positions are printed, i.e. this selection works. But it is not clear how to select trades - closing positions, even though they are visible in the list of terminal transactions (a couple/three lines higher always).
Transactions opening positions are printed, i.e. this selection works. But how to select transactions - closing positions - is not clear, even though they are visible in the list of transactions of the terminal (a couple / three lines higher always).
Try to pass in the debugger by pressing the blue button.
pre-set breakpoints and check where the values are and what values are expected. OK, I don't seem to see any errors, so I have to check, hence write open positions, adjust stops so that I don't have to wait long to close...
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.
I'm putting it out there for the public to judge. Although I haven't attached any checks yet, but I think they should work.
And somewhere in OnTick:DelitClosePositionFromArrayPosition();
Good afternoon, and once again I'm begging. Second day I can't understand why this piece of code doesn't work
Print "Deal entered...." goes fine, then there should be a split, some deals"Open position ...." are printed, but all other deals (these are deals closing position on TakeProfit) are not printed.
I do not understand what is the problem. I will mark the lost trades in colour below.
So it's like SOS !!!
Alexey, it all refers only to OnTradeTransaction event handling
An event has occurred, a trade that closes a position has been executed. The position is already gone at this moment. You can confirm it by selecting a list of orders and deals (there is no such a list in the code) and reading
And note that we are talking about a hadge account where the position usually has only two orders and two trades.Good afternoon, if it's not too much trouble for you, you have accurately described everything in this post. My two posts above, I am trying to get the result I need - to commit to close a position. I still cannot do it.
Please advise me, where I have a mistake or defect ?????
And this way there is no separation at all, it turns out that closing of a position at TakeProfit also fits under DEAL_ENTRY_IN?
It seems to me that some changes have been made to the handling of the OnTradeTransaction event.
Try to replace TRADE_TRANSACTION_DEAL_ADD with TRADE_TRANSACTION_HISTORY_ADD
It seems to me that some changes have been made to OnTradeTransaction event handling.
Try replacing TRADE_TRANSACTION_DEAL_ADD with TRADE_TRANSACTION_HISTORY_ADD
Doesn't help. Thank you for your feedback.
It seems to me that some changes were made to OnTradeTransaction event handling.
Try to replace TRADE_TRANSACTION_DEAL_ADD with TRADE_TRANSACTION_HISTORY_ADD
Transactions opening positions are printed, i.e. this selection works. But it is not clear how to select trades - closing positions, even though they are visible in the list of terminal transactions (a couple/three lines higher always).
I'll try it from the beginning, because my head is already a mess. As the movie classic said - "Who builds like this.....????".
There isa trade transaction, but there is no trade ticket yet. Am I getting this right?
Transactions opening positions are printed, i.e. this selection works. But how to select transactions - closing positions - is not clear, even though they are visible in the list of transactions of the terminal (a couple / three lines higher always).
Try to pass in the debugger by pressing the blue button.
pre-set breakpoints and check where the values are and what values are expected. OK, I don't seem to see any errors, so I have to check, hence write open positions, adjust stops so that I don't have to wait long to close...
I'll try it from the beginning, because my head is already in a mess. As the movie classic said - "Who builds like this.....????".
There is a trade transaction, but there is no trade ticket yet. Am I reading this right?
I don't understand anything at all. Here's a piece of code from my running EA
And it never stopped on DebugBreak(); so everything works out without any problems.
Apparently you have an order being added to history and you're waiting for a trade ticket.