5-8openEMA_Cross_Arrow_with_Alerts
Download scriptThis script is designed to enhance your trading experience by identifying specific momentum shifts on your charts. It focuses on a "crossover" strategy, which occurs when two different moving average lines—specifically the Exponential Moving Averages (EMAs)—intersect each other.
Core Functionality
The primary purpose of this tool is to pinpoint the exact moment one EMA passes another. In trading, these crossovers are often used as signals for potential trend changes. Because these lines can sometimes become cluttered or difficult to see when you zoom out on a chart, this script places visual markers (arrows) directly on the price action to highlight these events clearly.
How It Works
The logic operates by constantly comparing two different sets of data: a "Faster" EMA and a "Slower" EMA.
- Trend Detection: The script looks at the current position of both lines, their previous positions, and their subsequent positions.
- The "Cross Up": When the Faster EMA moves from below the Slower EMA to above it, the script identifies this as a bullish signal. It places an arrow below the price candle and triggers a notification.
- The "Cross Down": Conversely, when the Faster EMA moves from above the Slower EMA to below it, the script identifies this as a bearish signal. It places an arrow above the price candle and triggers a notification.
Key Features
- Visual Clarity: By placing arrows on the chart, you can quickly identify trend shifts without needing to squint at overlapping lines. You also have the option to remove the moving average lines from your view entirely while still keeping these visual markers active.
- Automated Notifications: The script is equipped with a multi-channel alert system. When a crossover occurs, you can choose to receive:
- A pop-up Alert on your trading platform.
- An audible Sound notification.
- An automated Email sent directly to your inbox.
- Smart Filtering: To prevent the system from overwhelming you with constant alerts during a single trend move, the script includes logic to ensure it only notifies you once per trend change. It also features a built-in time buffer to ensure notifications are spaced appropriately.
Customization
The script is highly adaptable, allowing you to define the specific "periods" for both the Faster and Slower EMAs to match your unique trading style. You can also toggle the alerts, sounds, and emails on or off depending on your preferred notification settings.
//+------------------------------------------------------------------+
//| EMA-Crossover_Signal.mq4 |
//| |
//+------------------------------------------------------------------+
/*
+------------------------------------------------------------------+
| Allows you to enter two ema periods and it will then show you at |
| Which point they crossed over. It is more usful on the shorter |
| periods that get obscured by the bars / candlesticks and when |
| the zoom level is out. Also allows you then to remove the emas |
| from the chart.
+------------------------------------------------------------------+
*/
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightBlue
#property indicator_color2 Magenta
double CrossUp[];
double CrossDown[];
int CurrentTrend = 0;
int starttime = 0;
extern int FasterEMA = 5;
extern int SlowerEMA = 8;
extern int Show_Alert = 1;
extern int Play_Sound = 1;
extern int Send_Mail = 1;
extern string SoundFilename = "alert.wav";
int init()
{
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
starttime = TimeLocal();
return(0);
}
int deinit()
{
return(0);
}
int start() {
int limit, i, counter, loop;
double fasterEMAnow, slowerEMAnow, fasterEMAprevious, slowerEMAprevious, fasterEMAafter, slowerEMAafter;
double Range, AvgRange;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
loop = 0;
for(i = 0; i <= limit; i++) {
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
fasterEMAnow = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i);
fasterEMAprevious = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
fasterEMAafter = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);
slowerEMAnow = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_OPEN, i);
slowerEMAprevious = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_OPEN, i+1);
slowerEMAafter = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_OPEN, i-1);
if ((fasterEMAnow > slowerEMAnow) && (fasterEMAprevious < slowerEMAprevious) && (fasterEMAafter > slowerEMAafter)) {
CrossUp[i] = Low[i] - Range*0.5;
if ((loop == 0) && (CurrentTrend != 1) && (TimeLocal() - starttime >= 10)) {
if (Show_Alert == 1) {
Alert("Cross Up on " + Symbol() + " " + Period() + "min " + FasterEMA + "/" + SlowerEMA + " EMA");
}
if (Play_Sound == 1) {
PlaySound(SoundFilename);
}
if (Send_Mail == 1) {
SendMail("Cross Up on " + Symbol() + " " + Period() + "min " + FasterEMA + "/" + SlowerEMA + " EMA", "");
}
CurrentTrend = 1;
}
if (loop == 0) {
loop = 1;
}
}
else if ((fasterEMAnow < slowerEMAnow) && (fasterEMAprevious > slowerEMAprevious) && (fasterEMAafter < slowerEMAafter)) {
CrossDown[i] = High[i] + Range*0.5;
if ((loop == 0) && (CurrentTrend != -1) && (TimeLocal() - starttime >= 10)) {
if (Show_Alert == 1) {
Alert("Cross Down on " + Symbol() + " " + Period() + "min " + FasterEMA + "/" + SlowerEMA + " EMA");
}
if (Play_Sound == 1) {
PlaySound(SoundFilename);
}
if (Send_Mail == 1) {
SendMail("Cross Down on " + Symbol() + " " + Period() + "min " + FasterEMA + "/" + SlowerEMA + " EMA", "");
}
CurrentTrend = -1;
}
if (loop == 0) {
loop = 1;
}
}
}
return(0);
}
Comments