I need an audio alert on MT5 when TP or SP reached

 
I am new to using MT5, after using Ninjatrader, and I can't believe that a trade's SP or TP can be reached and the trade ends and there is no alert noise to inform me. To me this is a basic requirement for a platform and I can't believe it is not on MT5. I can't find a solution. Do MT5 traders simply work in silence? Or am I missing something? I believe I saw an advert for a file you can use for Mt4 but I can find nothing for MT5. It is such a simple thing - am I the only person who wants such an alert ?  
 
Guy Hobbs:
I am new to using MT5, after using Ninjatrader, and I can't believe that a trade's SP or TP can be reached and the trade ends and there is no alert noise to inform me. To me this is a basic requirement for a platform and I can't believe it is not on MT5. I can't find a solution. Do MT5 traders simply work in silence? Or am I missing something? I believe I saw an advert for a file you can use for Mt4 but I can find nothing for MT5. It is such a simple thing - am I the only person who wants such an alert ?  

You can use the alerts tab on the Toolbox. Add your SL and TP and tell it what sort of alerts that you want.

Or, find an ea or script on codebase. I think that this is how the majority of us do it.
 
Michael Charles Schefe #:

You can use the alerts tab on the Toolbox. Add your SL and TP and tell it what sort of alerts that you want.

Or, find an ea or script on codebase. I think that this is how the majority of us do it.
Very strange that you simply can't set MT5 to have automatic sounds for the ST and TP being triggered. Setting the alerts manually with each trade seems very labour intensive. Anyone know of an EA or script that automates the job effectively? 
 
Guy Hobbs #: Very strange that you simply can't set MT5 to have automatic sounds
Very strange that you can't write the very few lines of code to make that indicator.
 
Guy Hobbs:
I am new to using MT5, after using Ninjatrader, and I can't believe that a trade's SP or TP can be reached and the trade ends and there is no alert noise to inform me. To me this is a basic requirement for a platform and I can't believe it is not on MT5. I can't find a solution. Do MT5 traders simply work in silence? Or am I missing something? I believe I saw an advert for a file you can use for Mt4 but I can find nothing for MT5. It is such a simple thing - am I the only person who wants such an alert ?  

Try this in the OnTick function



   // Check if any positions are open
   int total_positions = PositionsTotal();
   if (total_positions > 0)
     {
      // Loop through all positions
      for (int i = 0; i < total_positions; i++)
        {
         // Get the ticket number of the position
         ulong ticket = PositionGetTicket(i);

         // Check if the position is active
         if (PositionSelect(ticket))
           {
            // Get the stop loss and take profit levels of the position
            double stop_loss = PositionGetDouble(POSITION_SL);
            double take_profit = PositionGetDouble(POSITION_TP);

            // Get the current market price
            double current_price = SymbolInfoDouble(_Symbol, SYMBOL_BID);

            // Check if the stop loss or take profit level is reached
            if (current_price <= stop_loss || current_price >= take_profit)
              {
               // Send a notification
               string message;
               if (current_price <= stop_loss)
                  message = "Stop Loss Reached for Position " + IntegerToString(ticket);
               else
                  message = "Take Profit Reached for Position " + IntegerToString(ticket);

               SendNotification(message);
              }
           }
        }
     }
  }
 
Nardus Van Staden #:

Try this in the OnTick function


Positions refer to open trades running. So if a trade has TPed or SLed it won't show up in Positions list for you to iterate.

I think best solution is handling OnTradeTransaction event.

 
Guy Hobbs:
I am new to using MT5, after using Ninjatrader, and I can't believe that a trade's SP or TP can be reached and the trade ends and there is no alert noise to inform me. To me this is a basic requirement for a platform and I can't believe it is not on MT5. I can't find a solution. Do MT5 traders simply work in silence? Or am I missing something? I believe I saw an advert for a file you can use for Mt4 but I can find nothing for MT5. It is such a simple thing - am I the only person who wants such an alert ?  
PlaySound

It plays a sound file.

bool  PlaySound(
   string  filename      // file name
   );

Parameters

filename

[in]  Path to a sound file. If filename=NULL, the playback is stopped.

Return Value

true – if the file is found, otherwise - false.

Note

The file must be located in terminal_directory\Sounds or its sub-directory. Only WAV files are played.

Call of PlaySound() with NULL parameter stops playback.

PlaySound() function does not work in the Strategy Tester.

https://www.mql5.com/en/docs/common/playsound
Documentation on MQL5: PlaySound / Common Functions
Documentation on MQL5: PlaySound / Common Functions
  • www.mql5.com
It plays a sound file. Parameters filename [in]  Path to a sound file. If filename=NULL, the playback is stopped. Return Value true – if the...
 
You can simply search "Order Filled Sound" in mql5 site, this will create order filled sound including TP/SL
 

Why reinvent the wheel?

Articles

MQL5 Cookbook: Sound Notifications for MetaTrader 5 Trade Events

Anatoli Kazharski, 2013.10.23 11:38

In this article, we will consider such issues as including sound files in the file of the Expert Advisor, and thus adding sound notifications to trade events. The fact that the files will be included means that the sound files will be located inside the Expert Advisor. So when giving the compiled version of the Expert Advisor (*.ex5) to another user, you will not have to also provide the sound files and explain where they need to be saved.