This script is designed to act as a real-time notification system for traders using the MetaTrader platform. Its primary purpose is to keep you informed the exact moment a new candle (or "bar") appears on your trading chart, which is a critical signal for many trading strategies that rely on price action changes at specific intervals.
Core Functionality
The tool continuously monitors the live market feed to detect when the current time period ends and a new one begins. Instead of requiring you to watch the screen constantly, it automatically triggers two types of alerts based on your preferences:
- Visual Alerts: A pop-up message box appears on your screen, providing an immediate notification that a new bar has formed. This message includes specific details, such as the current timeframe (e.g., M15, H1, Daily) and the exact time of the update.
- Audio Notifications: The script can play a standard system sound to provide an audible cue, ensuring you don't miss a new candle even if you are looking at a different window or working on another task.
How It Works Internally
The logic follows a straightforward "check and notify" process:
- Time Tracking: The script keeps a record of the timestamp of the most recent bar it has seen.
- Comparison: Every time the market updates, the script compares the current candle's start time with the last recorded time.
- Execution: If the times are different, the script recognizes that a "New Bar" event has occurred. It then triggers the alert system only once per bar, preventing repetitive notifications during the same period.
- Dynamic Identification: The tool automatically identifies which timeframe you are currently viewing (ranging from 1-minute charts to Monthly charts) and includes that information in the alert text for better clarity.
Customization Options
The script is built with toggle switches that allow you to control how you receive these notifications. You can choose to turn off the pop-up alerts, disable the sound effects, or keep both active, depending on your preferred trading environment.
//+------------------------------------------------------------------+
//| ytg_Alert_New_Bar.mq4 |
//| Yuriy Tokman |
//| yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link "yuriytokman@gmail.com"
//Çâóêîâàÿ èíäèêàöèÿ íîâîãî áàðà
//Ïî èäåå Bidrio
#property indicator_chart_window
extern bool off_Alert = false;
extern bool off_Play_Sound = false;
string NameFileSound = "expert.wav";
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if(NevBar())
{
if(!off_Alert)Alert("New Bar;"," Time Frame=",GetNameTF(),"; CurTime=",TimeToStr(TimeCurrent(), TIME_MINUTES));
if(!off_Play_Sound)PlaySound(NameFileSound);
}
return(0);
}
//+----------------------------------------------------------------------------+
// Ôóíêöèÿ êîíòðîëÿ íîâîãî áàðà |
//-----------------------------------------------------------------------------+
bool NevBar(){
static int PrevTime=0;
if (PrevTime==Time[0]) return(false);
PrevTime=Time[0];
return(true);}
//+----------------------------------------------------------------------------+
//| Àâòîð : Êèì Èãîðü Â. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 01.09.2005 |
//| Îïèñàíèå : Âîçâðàùàåò íàèìåíîâàíèå òàéìôðåéìà |
//+----------------------------------------------------------------------------+
//| Ïàðàìåòðû: |
//| TimeFrame - òàéìôðåéì (êîëè÷åñòâî ñåêóíä) (0 - òåêóùèé ÒÔ) |
//+----------------------------------------------------------------------------+
string GetNameTF(int TimeFrame=0) {
if (TimeFrame==0) TimeFrame=Period();
switch (TimeFrame) {
case PERIOD_M1: return("M1");
case PERIOD_M5: return("M5");
case PERIOD_M15: return("M15");
case PERIOD_M30: return("M30");
case PERIOD_H1: return("H1");
case PERIOD_H4: return("H4");
case PERIOD_D1: return("Daily");
case PERIOD_W1: return("Weekly");
case PERIOD_MN1: return("Monthly");
default: return("UnknownPeriod");
}
}
Comments