Send Notification to Phone only after Price hits the sell stop

 
Hello everyone, I'm trying to send a notification to my phone every time the price reaches the Sell Stop order and a trade is opened. I stumbled across OnTrade() and OnTradeTransaction() but apparently they're executed right after a Sell Stop order is placed and not when then trade is opened. How do I proceed with this please?
 
  • 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.
 
Fernando Carreiro #:
  • 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.

 
Aymane Maizi #: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. 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.

 
Fernando Carreiro #:

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 :)

Documentation on MQL5: Trade Functions / OrderSend
Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
OrderSend - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Aymane Maizi #: That's the thing, I don't know how I can detect if a position is opened, I thought inserting it within the: or the: would do the trick but they didn't. Also, thanks for your fast replies :)

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 ...

Articles

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.
 
Fernando Carreiro #:

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!