This tool is designed to act as an automated monitoring system for your trading platform, specifically aimed at identifying periods of extreme market instability or major economic news events. Instead of manually watching the price action 24/7, the script works in the background to detect sudden "shocks" in the marketplace's liquidity and trading constraints.
How it Works
The logic follows a simple three-step process:
1. Establishing the Baseline When you first load the tool onto your chart, it performs a "snapshot" of the current market conditions. It looks at two specific metrics:
- The Spread: The difference between the buy and sell prices.
- The Stop Level: The minimum distance required to place a pending order.
By recording these numbers at the start, the script creates a "normal" benchmark for the asset you are trading.
2. Continuous Real-Time Monitoring Once the baseline is set, the tool constantly refreshes its data to compare the live market against those initial numbers. It is looking for any significant deviations where the current costs of trading suddenly spike.
3. Instant Alerts and Notifications If the market experiences a sudden surge in volatility—often caused by high-impact news—the spread or stop level will widen significantly beyond the normal range. When this happens, the tool triggers:
- A Visual/Audio Alert: An immediate pop-up notification appears on your screen to warn you of the high volatility.
- A Data Log: It records the exact numerical difference in the background logs for your reference.
- A Cooling Period: The script pauses for a few seconds after an alert to prevent your screen from being flooded with repetitive notifications during a single news event.
Key Benefit
The primary purpose of this logic is to act as an early warning system. It helps traders identify the exact moment when market conditions become too erratic or expensive, allowing you to stay informed about high-volatility periods without having to constantly monitor the raw data yourself.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| News Alert 2.mq4 |
//| João Barbosa |
//| obarbosa2001@yahoo.com.br |
//+------------------------------------------------------------------+
#property copyright "João Barbosa"
#property link "obarbosa2001@yahoo.com.br"
#property indicator_chart_window
int NormalSpread, NormalStopLevel;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
NormalSpread=MarketInfo(Symbol(),MODE_SPREAD);
NormalStopLevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
start();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
RefreshRates();
int ActualSpread=(Ask-Bid)/Point;
int ActualStopLevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
if (ActualSpread>NormalSpread) { Alert("News or High Volatility !!! Spread has change.");
Print("Actual Spread: ",ActualSpread," Pips, Normal Spread: ",NormalSpread," Pips");
Sleep(50000);}
if (ActualStopLevel>NormalStopLevel) { Alert("News or High Volatility !!! Stop Level has change.");
Print("Actual Stop Level: ",ActualStopLevel," Pips, Normal Stop Level: ",NormalStopLevel," Pips");
Sleep(50000); }
return(0);
}
//+------------------------------------------------------------------+
Comments