JMA_alert
Download scriptThis script is designed to serve as an automated monitoring tool for traders who use the "JMA" (Jurik Moving Average) indicator. Its primary purpose is to provide real-time notifications when two different versions of this moving average intersect, which is often interpreted by traders as a signal for a potential change in market momentum.
Core Functionality
The script works by simultaneously tracking two distinct JMA lines on your trading chart:
- A Slow Line: Calculated using a longer timeframe (set by the user).
- A Fast Line: Calculated using a shorter, more responsive timeframe.
By running these two lines in tandem, the script identifies the relationship between the overall trend and the immediate price action.
How the Logic Works
The logic follows a systematic three-step process to ensure accuracy:
1. Data Retrieval The script constantly pulls data from the JMA indicator. It looks at two specific settings (the "Fast" and "Slow" lengths) and maps them onto your current chart. This allows it to see where each line sits at any given moment in time.
2. Crossing Detection The heart of the script is its ability to detect a "Cross." It compares the numerical value of the Fast line against the Slow line. Specifically, it looks for the exact moment when the lines swap positions—for example, when the Fast line moves from below the Slow line to above it (or vice versa).
3. Smart Alerting System To prevent the software from sending constant, repetitive notifications every second while the lines are crossed, the script includes a "memory" feature. It remembers the last direction of the cross. An alert will only be triggered at the precise moment the direction changes. Once an alert is sent, it will remain silent until the lines cross each other again in the opposite direction.
User Experience
When the criteria are met (a crossover occurs), the script automatically triggers a pop-up alert on your trading platform. This alert specifies the asset symbol and the timeframe you are currently viewing, allowing you to react quickly to potential trend shifts without having to manually watch the charts at all times.
//+------------------------------------------------------------------+
//| CrossedAlerts.mq4 |
//| Coders Guru |
//| Newdigital (just use the Codersguru code for JMA alert.
//| http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Coders Guru"
#property link "http://www.forex-tsd.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Aqua
extern int Length_slow = 7;
extern int Length_fast = 5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
bool Crossed (double line1 , double line2 )
{
static string last_direction = "";
string current_dirction = "";
if(line1>line2)current_dirction = "up";
if(line1<=line2)current_dirction = "down";
if(current_dirction != last_direction)
{
Alert("EMA Cross for "+Symbol()+" on the "+Period()+" minute chart.");
last_direction = current_dirction;
return (true);
}
else
{
return (false);
}
}
int start()
{
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--;
int pos=Bars-counted_bars;
while(pos>=0)
{
ExtMapBuffer1[pos]= iCustom(NULL,0,"JMA",Length_slow,0,1,pos);
ExtMapBuffer2[pos]= iCustom(NULL,0,"JMA",Length_fast,0,1,pos);
pos--;
}
Print(Crossed (ExtMapBuffer1[0],ExtMapBuffer2[0]));
//----
return(0);
}
//+------------------------------------------------------------------+
Comments