- Errors, bugs, questions
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- Using OnTradeTransaction to manage position replacement
- Usually people who cannot code do not receive free help on this forum.
- If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
- To learn MQL programming, you can research the many available Articles on the subject, as well as reference the online Documentation. You can also have a look at examples in the Codebase.
- Finally, you also have the option to hire a programmer in the Freelance section.
- Usually people who cannot code do not receive free help on this forum.
- If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
- To learn MQL programming, you can research the many available Articles on the subject, as well as reference the online Documentation. You can also have a look at examples in the Codebase.
- Finally, you also have the option to hire a programmer in the Freelance section.
Thank you for your reply Fernando, I've indeed tried both functions below but as I said they trigger right after a Sell Stop is placed and not when the position is opened which is what I want. Below is the functions I tried and my Sell Stop code.
//Funtions tried void OnTrade(); void OnTradeTransaction(); //My sell stop code trade.SellStop(lots,entry,_Symbol,sl,tp,ORDER_TIME_SPECIFIED,expiration);
I do know how to send a notification to my phone, all I need is my condition to be met before sending a notification.
Where in your code are you "attempting" to detect a position opening and sending a push notification?
All I see are empty function declarations.
Where in your code are you "attempting" to detect a position opening and sending a push notification?
All I see are empty function declarations.
That's the thing, I don't know how I can detect if a position is opened, I thought inserting it within the:
void OnTrade();
or the:
void OnTradeTransaction();
would do the trick but they didn't. Also, thanks for your fast replies :)
- www.mql5.com
You can't just declare an empty event handler. You have to write out it's functionality.
Please read the documentation about both event handlers and have a look at the example code, so you can understand how they work and how you can use them.
In this case "OnTradeTransaction" will be the most appropriate for your needs. A pending order generates a position, when a new deal occurs for it, and that deal will have the DEAL_ORDER property with the same order ticket number.
Please also read the following ...
Orders, Positions and Deals in MetaTrader 5
MetaQuotes, 2011.02.01 16:13
Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.
You can't just declare an empty event handler. You have to write out it's functionality.
Please read the documentation about both event handlers and have a look at the example code, so you can understand how they work and how you can use them.
In this case "OnTradeTransaction" will be the most appropriate for your needs. A pending order generates a position, when a new deal occurs for it, and that deal will have the DEAL_ORDER property with the same order ticket number.
Please also read the following ...
I'll look further into it, thank you Fernando!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use