SoundAtOpenNewBar
Download scriptThis tool is designed to provide traders with an audible notification every time a new price candle (or "bar") appears on their trading chart. It serves as a simple sensory alert to help you keep track of market movements without having to constantly watch the screen.
How it works:
The script functions by monitoring the current time of the candles on your platform. Here is the step-by-step logic it follows:
- Initial Setup: When you first load the tool, it takes a mental "note" of the exact time the current candle started.
- Continuous Monitoring: The script constantly checks the live market feed to see if the time of the current candle has changed.
- Detection: As soon as the previous candle closes and a new one opens, the tool recognizes that the time has progressed to a new period.
- Action: Once this change is detected, the tool plays a specific sound file (by default, an alert音) through your computer's audio system.
- Reset: After playing the sound once for the new bar, it updates its "note" to the new time and waits for the next candle to appear before alerting you again.
Key Benefit:
Instead of relying solely on visual cues, this script allows you to stay informed about market transitions—such as the start of a new minute, hour, or day—via audio, making it easier to manage multiple charts simultaneously.
//+------------------------------------------------------------------+
//| SoundAtOpenNewBar.mq4 |
//| Copyright © 2008, Serega Lykov |
//| http://mtexperts.narod.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Serega Lykov"
#property link "http://mtexperts.narod.ru/"
//---- property of indicator ----------------------------------------+
#property indicator_chart_window
//---- external parameters ------------------------------------------+
extern string SoundFile = "alert.wav";
//---- global variables ---------------------------------------------+
static datetime bartime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- initialization of parameters
bartime = Time[0];
//---- finish of initialization
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- finish of deinitialization
return(0);
}
//+------------------------------------------------------------------+
//| Sound At Open New Bar |
//+------------------------------------------------------------------+
int start()
{
if(bartime == Time[0]) return(0);
bartime = Time[0];
PlaySound(SoundFile);
// finish of iteration
return(0);
}
//+------------------------------------------------------------------+
Comments