ma_2xMA_yt_sig_alert
Download scriptThis tool is designed for traders who use Moving Averages (MA) to identify trends and entry points in the financial markets. It simplifies the visual analysis by automatically tracking two different moving averages simultaneously and providing clear signals when they interact with each other.
Core Functionality
The script operates based on the relationship between two distinct moving averages: a Fast MA (which reacts quickly to recent price changes) and a Slow MA (which tracks the broader, long-term trend).
Instead of requiring you to manually watch where these lines cross, the tool performs the following actions:
- Visual Mapping: It draws both the Fast and Slow Moving Averages directly on your chart. This allows you to see the current "momentum" of the price relative to the general trend at a glance.
- Crossover Detection: The underlying logic constantly monitors the position of these two lines. It specifically looks for the exact moment one line moves from above the other to below it (or vice versa).
- Automated Signaling: When a crossover occurs, the script automatically places visual markers on the chart:
- Downwards Signal: If the Fast MA drops below the Slow MA, an arrow is placed above the price candle. This typically indicates a shift in momentum toward the downside.
- Upwards Signal: If the Fast MA climbs above the Slow MA, an arrow is placed below the price candle. This typically indicates a shift in momentum toward the upside.
- Real-Time Alerts: To ensure you don't miss a move while away from the screen, the tool generates an instant audio and pop-up alert the moment a crossover is detected. These alerts include specific details such as the direction of the move and the current timeframe of the chart.
Key Features for Users
- Dynamic Tracking: The script keeps track of time to ensure that it only triggers one alert per candle, preventing repetitive notifications during volatile price action.
- Customizable Parameters: While the logic is fixed, users can adjust the speed of the moving averages (the "Period") and the type of calculation used to suit different trading styles (e.g., scalping vs. swing trading).
- Clean Interface: By providing both visual lines and distinct arrows, it reduces "chart clutter," allowing you to focus on the signals rather than interpreting complex data points manually.
//+------------------------------------------------------------------+
//| 2xMA.mq4 |
//| Yuriy Tokman |
//| yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link "yuriytokman@gmail.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Red
extern string __1__ = "Fast MA";
extern int PeriodMA_1 = 5;
extern int ma_method_1 = 1;//0-3
extern int applied_price_1 = 6;//0-6
extern string __2__ = "Slow MA";
extern int PeriodMA_2 = 12;
extern int ma_method_2 = 1;//0-3
extern int applied_price_2 = 6;//0-6
extern string __3__ = "Another";
extern int shift = 0;
extern int arrow_code_up = 218;
extern int arrow_code_down = 217;
extern int width = 3;
double ExtMapBuffer0[];
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
datetime LastTime=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer0);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer1);
SetIndexStyle(2,DRAW_ARROW,EMPTY,width);
SetIndexArrow(2,arrow_code_up);
SetIndexBuffer(2,ExtMapBuffer2);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW,EMPTY,width);
SetIndexArrow(3,arrow_code_down);
SetIndexBuffer(3,ExtMapBuffer3);
SetIndexEmptyValue(3,0.0);
IndicatorShortName("2xMA ("+PeriodMA_1+")");
SetIndexLabel(0," ISQ#481971287 ");
SetIndexLabel(1," yuriytokman@gmail.com ");
SetIndexLabel(2," ISQ#481971287 ");
SetIndexLabel(3," yuriytokman@gmail.com ");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=limit; i>=0; i--)
{
double MA_1_0 = iMA(NULL,0,PeriodMA_1,0,ma_method_1,applied_price_1,i+shift);
double MA_1_1 = iMA(NULL,0,PeriodMA_1,0,ma_method_1,applied_price_1,i+shift+1);
double MA_2_0 = iMA(NULL,0,PeriodMA_2,0,ma_method_2,applied_price_2,i+shift);
double MA_2_1 = iMA(NULL,0,PeriodMA_2,0,ma_method_2,applied_price_2,i+shift+1);
ExtMapBuffer0[i] = MA_1_0;
ExtMapBuffer1[i] = MA_2_0;
if (MA_1_1>=MA_2_1 && MA_1_0<MA_2_0 && Time[i]!= LastTime)
{
ExtMapBuffer2[i]=High[i]+5*Point;
LastTime = Time[i];
Alert("Downwards "," Period:",Period()," TimeFrame:",GetNameTF());
}
if (MA_1_1<=MA_2_1 && MA_1_0>MA_2_0 && Time[i]!= LastTime)
{
ExtMapBuffer3[i]=Low[i]-5*Point;
LastTime = Time[i];
Alert("Upwards "," Period:",Period()," TimeFrame:",GetNameTF());
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//| Àâòîð : Êèì Èãîðü Â. 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