You are selecting historical deals related to a specific position:
HistorySelectByPosition(trans.position);
Then you read ticket of the first deal which is always ENTRY_IN:
ulong ticket = HistoryDealGetTicket(0);
How do you expect this condition to be true?
if(deal_entry == DEAL_ENTRY_OUT) { ....}
bro where you coding in mt4 platform or mt5?
Yashar Seyyedin #:
You are selecting historical deals related to a specific position:
Then you read ticket of the first deal which is always ENTRY_IN:
How do you expect this condition to be true?
Sorry, i posted the wrong code after lot of tries
ulong current_ticket = trans.deal; HistorySelectByPosition(trans.position); int num_in_history = HistoryOrdersTotal(); ulong ticket = HistoryDealGetTicket(0); ENUM_DEAL_TYPE deal_type = trans.deal_type; double deal_size = trans.volume; string label = HistoryDealGetString(ticket,DEAL_COMMENT); ulong deal_entry = HistoryDealGetInteger(trans.deal,DEAL_ENTRY); if(deal_entry == DEAL_ENTRY_OUT) { ...}
I use the historyDealGetTicket to effectively get the entry in label (variable ticket), but for the deal entry i use the trans.deal ticket (variable current ticket).
In real time scenario it works, the problem is only in backtest.
Thanks for your help
This is how I do this:
#include <Trade\DealInfo.mqh> void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result) { if(trans.type!=TRADE_TRANSACTION_DEAL_ADD) return; if(!HistoryDealSelect(trans.deal)) return; CDealInfo m_deal; m_deal.Ticket(trans.deal); long deal_type=-1; m_deal.InfoInteger(DEAL_ENTRY,deal_type); if(deal_type == DEAL_ENTRY_OUT) {...} }
This one executes faster:
void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result) { if(!HistoryDealSelect(trans.deal)) return; int deal_entry = HistoryDealGetInteger(trans.deal, DEAL_ENTRY); if(deal_entry == DEAL_ENTRY_OUT) {...} }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hello everybody,
I'm struggling on a problem with backtesting my code, when the function OnTradeTransaction is called the DEAL_ENTRY is never a DEAL_ENTRY_OUT (also when a trade is closed).
When launching the same EA in real time scenario it works and i get a DEAL_ENTRY_OUT when a trade is closed. Can anyone help me understand why this happens?
I appreciate any ideas.
Thanks