HLine Alert_once_per_bar
Download scriptThis tool is designed to act as a visual and auditory monitoring system for specific price levels on your trading chart. It automates the process of watching a horizontal line, notifying you the moment the market price interacts with it, while ensuring you aren't overwhelmed by repetitive notifications.
Visual Setup
When you apply this script, it places a customizable horizontal line on your chart. You have the flexibility to define its appearance—specifically its name, color, and style (such as a solid line). This serves as your primary "target" or "boundary" marker on the price action.
How the Logic Works
The script continuously monitors the live market price in relation to the position of that horizontal line. It operates based on three core logic steps:
- Proximity Detection: The tool looks for a specific "trigger zone." Instead of requiring the price to hit the line perfectly (which can sometimes be missed due to rapid fluctuations), it checks if the current price falls within a user-defined range of pips near the line.
- Alert Triggering: Once the market price enters this designated proximity zone, the script identifies that a "hit" has occurred.
- Smart Notification Management: To prevent the system from triggering hundreds of alerts every second while the price lingers near the line, the script includes an intelligent filter. It tracks the movement of the candles; it will play your chosen alert sound once per bar. This means you get notified immediately when the price hits your target, but the notification remains silent until a new candle forms or the price moves significantly away and returns.
User Experience
When the conditions are met, the script automatically plays an audio file (such as a .wav file) to grab your attention. It essentially acts as an automated "lookout," allowing you to step away from the screen while knowing that the system will sound an alarm the moment your chosen price level is reached.
//+------------------------------------------------------------------+
//| HLine Alert.mq4 |
//+------------------------------------------------------------------+
#property copyright "raff1410@o2.pl"
//Alert once per bar added by Jack Hewings
#property indicator_chart_window
extern string LineName="MyLine1";
extern color LineColor=AliceBlue;
extern int LineStyle=STYLE_SOLID;
extern int AlertPipRange=1;
extern string AlertWav="alert.wav";
extern string Subject = "level 0";
extern string message = "level 0 reached";
//jjj
int LastAlert=0;
int NewAlert=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
ObjectCreate(LineName, OBJ_HLINE, 0, 0, Bid);
ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
ObjectSet(LineName, OBJPROP_COLOR, LineColor);
NewAlert = 0;
double val = ObjectGet( LineName, OBJPROP_PRICE1);
if (Bid-AlertPipRange*Point <= val && Bid+AlertPipRange*Point >= val) NewAlert=1;
if ( NewAlert==1)
{
if (LastAlert == 0 || LastAlert < Bars )
{
PlaySound(AlertWav);
LastAlert = Bars;
}
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Comments