Hi,
I want to ask which one of the OnTick() vs OnTradeTransaction() function is called first?
On OnTick() function there's a trailing stop code that will return error if EA can't select the position ticket. On OnTradeTransaction() I will reset the position ticket to 0 if the position is closed. But when I print the result it came out that OnTick() function is called first and OnTradeTransaction() second resulting in printing error message that EA failed to select the closed position number. Here's the log of it:
and here's my code for OnTradeTransaction
Is there's a way for the OnTradeTransaction to be called first so that the error could be resolve?
And I also notice there's an error in OnTradeTransaction() documentation in this part. In the documentation index #3 is TRADE_TRANSACTION_DEAL_ADD while when I print it, it return TRADE_TRANSACTION_HISTORY_ADD. Is there a way to fix the documentation?
What error ? There is no index in the documentation.
These are events, your code should not rely on one being executed before the other, you can't never know that. Adjust your logic.
What error ? There is no index in the documentation.
These are 2 non-related events.
Which ever event is triggered first will be called.
So there's really nothing I could do about the error message that comes from OnTick being called first before then the OnTradeTransaction?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I want to ask which one of the OnTick() vs OnTradeTransaction() function is called first?
On OnTick() function there's a trailing stop code that will return error if EA can't select the position ticket. On OnTradeTransaction() I will reset the position ticket to 0 if the position is closed. But when I print the result it came out that OnTick() function is called first and OnTradeTransaction() second resulting in printing error message that EA failed to select the closed position number. Here's the log of it:
and here's my code for OnTradeTransaction
Is there's a way for the OnTradeTransaction to be called first so that the error could be resolve?
And I also notice there's an error in OnTradeTransaction() documentation in this part. In the documentation index #3 is TRADE_TRANSACTION_DEAL_ADD while when I print it, it return TRADE_TRANSACTION_HISTORY_ADD. Is there a way to fix the documentation?
Identifier
Description
TRADE_TRANSACTION_ORDER_ADD
Adding a new open order.
TRADE_TRANSACTION_ORDER_UPDATE
Updating an open order. The updates include not only evident changes from the client terminal or a trade server sides but also changes of an order state when setting it (for example, transition from ORDER_STATE_STARTED to ORDER_STATE_PLACED or from ORDER_STATE_PLACED to ORDER_STATE_PARTIAL, etc.).
TRADE_TRANSACTION_ORDER_DELETE
Removing an order from the list of the open ones. An order can be deleted from the open ones as a result of setting an appropriate request or execution (filling) and moving to the history.
TRADE_TRANSACTION_DEAL_ADD
Adding a deal to the history. The action is performed as a result of an order execution or performing operations with an account balance.
TRADE_TRANSACTION_DEAL_UPDATE
Updating a deal in the history. There may be cases when a previously executed deal is changed on a server. For example, a deal has been changed in an external trading system (exchange) where it was previously transferred by a broker.
TRADE_TRANSACTION_DEAL_DELETE
Deleting a deal from the history. There may be cases when a previously executed deal is deleted from a server. For example, a deal has been deleted in an external trading system (exchange) where it was previously transferred by a broker.
TRADE_TRANSACTION_HISTORY_ADD
Adding an order to the history as a result of execution or cancellation.
TRADE_TRANSACTION_HISTORY_UPDATE
Changing an order located in the orders history. This type is provided for enhancing functionality on a trade server side.
TRADE_TRANSACTION_HISTORY_DELETE
Deleting an order from the orders history. This type is provided for enhancing functionality on a trade server side.
TRADE_TRANSACTION_POSITION
Changing a position not related to a deal execution. This type of transaction shows that a position has been changed on a trade server side. Position volume, open price, Stop Loss and Take Profit levels can be changed. Data on changes are submitted in MqlTradeTransaction structure via OnTradeTransaction handler. Position change (adding, changing or closing), as a result of a deal execution, does not lead to the occurrence of TRADE_TRANSACTION_POSITION transaction.
TRADE_TRANSACTION_REQUEST
Notification of the fact that a trade request has been processed by a server and processing result has been received. Only type field (trade transaction type) must be analyzed for such transactions in MqlTradeTransaction structure. The second and third parameters of OnTradeTransaction (request and result) must be analyzed for additional data.