MAM_Crossover

Author: Copyright � 2010, Andy Tjatur Pramono
MAM_Crossover

This technical indicator is designed to identify specific momentum shifts in the financial markets by analyzing price movement relative to moving averages. Instead of simply following a single trend, it looks for "crossover" patterns where the relationship between opening prices and closing prices changes rapidly over three consecutive timeframes.

How the Logic Works

1. Market Volatility Measurement Before making any calculations, the tool first establishes a baseline for "normal" price movement. It examines the previous 10 bars of data to calculate the average range (the difference between the highest and lowest prices). This ensures that the visual signals placed on your chart are scaled correctly based on current market volatility.

2. Moving Average Analysis The script tracks two primary types of Moving Averages (SMAs) over a 20-period window:

  • Closing Prices: Where the price ended during a period.
  • Opening Prices: Where the price started during a period.

By comparing these two averages, the tool calculates the "gap" or "distance" between where the market opened and where it closed across three specific points in time (the current bar, the previous bar, and the following bar).

3. Identifying the Signal The core logic triggers a signal based on a specific sequence of "crosses":

  • Bullish Signal (Upward Movement): The tool looks for a pattern where the closing price relationship shifts from being below the opening price to above it, then back again in a specific sequence. When this specific "cross" occurs, it identifies a potential buying opportunity and places a visual arrow below the candle.
  • Bearish Signal (Downward Movement): Conversely, it looks for the opposite pattern—where closing prices drop significantly relative to the openings across those three timeframes. When detected, it places an arrow above the candle to signal a potential selling opportunity.

4. User Notifications To ensure you don't miss these occurrences, the script includes an integrated alert system. When a new crossover is detected that meets the criteria, the tool can trigger an audible alert sound, notifying the trader in real-time without requiring them to watch the screen constantly.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
MAM_Crossover
//+------------------------------------------------------------------+
//|                                                MAM_CrossOver.mq4 |
//|                         Copyright © 2010, Andy Tjatur Pramono    |
//|                                         andy.tjatur@gmail.com    |
//+------------------------------------------------------------------+


#property copyright "Copyright © 2010, Andy Tjatur Pramono"
#property link      "andy.tjatur@gmail.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1

double CrossUp[];
double CrossDown[];
extern bool Use_Sound = true;

bool alert;
datetime timestamp;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double x1,y1,x2,y2,x3,y3,A,B,C,D,E,F;
   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;
   
   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;
       
      A=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i);
      B=iMA(NULL,0,20,0,MODE_SMA,PRICE_OPEN,i);
      C=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+1);
      D=iMA(NULL,0,20,0,MODE_SMA,PRICE_OPEN,i+1);
      E=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i-1);
      F=iMA(NULL,0,20,0,MODE_SMA,PRICE_OPEN,i-1);
      
      x1 = (A-B);
      y1 = (B-A);
      x2 = (C-D);
      y2 = (D-C);
      x3 = (E-F);
      y3 = (F-E);
      
      if ((x1>y1)&& (x2<y2)&&(x3>y3)) {
         CrossUp[i] = Low[i] - Range*0.7;if (Use_Sound && !alert) {PlaySound ("alert.wav"); alert=true;}}
      {
      }
      
      if ((x1<y1)&& (x2>y2)&&(x3<y3)) {
         CrossDown[i] = High[i] + Range*0.7;if (Use_Sound && !alert) {PlaySound ("alert.wav"); alert=true;} }
      
      }
     
      
   return(0);
}

Comments