ma_2xMAcross_alert_satop

Author: Yuriy Tokman
ma_2xMAcross_alert_satop

The 2xMA indicator is designed to provide visual signals on a trading chart by tracking the relationship between two different Moving Averages (MA). It simplifies market analysis by identifying specific moments when the trend changes direction, using price averages as the primary filter.

Core Logic Overview

The script operates by calculating two distinct moving averages simultaneously:

  1. Fast MA: A shorter-term average that reacts quickly to recent price fluctuations.
  2. Slow MA: A longer-term average that represents the broader, underlying trend of the market.

By plotting these two lines on your chart, the tool allows you to see whether the immediate price action is aligned with or moving away from the general trend.

How the Signals Work

The primary purpose of this script is to detect "crosses" between these two averages. A cross occurs when the Fast MA moves from one side of the Slow MA to the other. The indicator interprets these crossovers as specific entry or exit signals:

  • Downwards Signal: When the Fast MA was previously above the Slow MA but moves below it, the script identifies a potential bearish shift. It places a visual arrow marker above the price bar and can trigger a notification alert.
  • Upwards Signal: When the Fast MA was previously below the Slow MA but moves above it, the script identifies a potential bullish shift. It places a visual arrow marker below the price bar and can trigger a notification alert.

Key Features for the User

  • Visual Indicators: Rather than just providing lines, the script draws clear arrows (Up/Down) at the exact moment a crossover occurs, making it easy to spot trend changes at a glance.
  • Customizable Sensitivity: Users can adjust the "Period" of both the Fast and Slow averages. A shorter period makes the indicator more sensitive to small price movements, while a longer period smooths out the data to focus on major trends.
  • Noise Filtering: The script includes a toggle to manage alerts based on market "noise," allowing the user to decide how frequently they want to be notified of trend shifts.
  • Automated Alerts: When a crossover is detected, the tool can provide a pop-up alert containing the direction of the move, the timeframe of the chart, and the period settings currently in use.

In summary, this tool acts as a trend-following assistant that automates the process of watching for "crossovers," highlighting potential buying and selling opportunities through both visual markers and real-time alerts.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
15 Views
0 Downloads
0 Favorites
ma_2xMAcross_alert_satop
//+------------------------------------------------------------------+
//|                                                         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 bool tired_from_noise = true;

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];
       if(!tired_from_noise)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];
       if(!tired_from_noise)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