iMACross_v1

Author: Copyright � 2005, Metaquotes
iMACross_v1

This script functions as a technical analysis tool designed to help traders identify momentum shifts and trend reversals by visualizing the relationship between two different moving averages. It essentially takes standard price data and processes it into a simplified "crossing" signal that appears in a separate window below your main price chart.

Core Logic and Functionality

1. Dual Moving Average Calculation The core of this tool relies on comparing two distinct types of Moving Averages (MA):

  • Fast Moving Average: This reacts quickly to recent price changes.
  • Slow Moving Average: This tracks the broader, long-term trend of the market.

By subtracting the value of the Slow Moving Average from the Fast Moving Average, the script calculates the "distance" between the two. If the Fast MA is above the Slow MA, it suggests upward momentum; if it falls below, it indicates downward pressure.

2. Signal Smoothing (The MACD Influence) Rather than just showing the raw difference between the averages, the script applies a smoothing mathematical formula (similar to a Signal Line in a MACD indicator). This creates a secondary "Signal" line.

  • The Main Line shows the immediate momentum.
  • The Signal Line acts as a smoothed version of that momentum, helping to filter out "noise" or minor price fluctuations that might otherwise lead to false signals.

3. Customizable Sensitivity The script is designed to be flexible. Users can define exactly how "fast" or "slow" the logic reacts by adjusting four primary parameters:

  • Periods: You can choose how many previous candles the tool looks at to calculate its averages (e.g., a short period for fast reactions, a long period for steady trends).
  • MA Type: You can switch between different calculation methods (Simple, Exponential, or Linear Weighted), which changes how much weight is given to the most recent price data versus older data.

How to Read the Results

When viewing this on a chart, the tool provides a visual representation of momentum:

  • The Main Line: Represents the current gap between the fast and slow trends.
  • The Signal Line (Dotted): Provides a baseline for that momentum.

Traders typically look for "crosses" between these two lines. When the Main Line crosses over the Signal Line, it often suggests a shift in market direction, providing a visual cue for potential entry or exit points based on whether the momentum is accelerating upward or downward.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
iMACross_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                     iMACross.mq4 |
//|                                Copyright © 2005, David W. Thomas |
//|                                Copyright © 2005, firedave - MOD  |
//|                                           mailto:davidwt@usa.net |
//|                                    mailto:firedave@fx-review.com |
//+------------------------------------------------------------------+
// This is the correct computation and display of MACD,
// that modified to a MA Cross Indicator
#property copyright "Copyright © 2005, Metaquotes"
#property link      "mailto:metaquotes@metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_color2 Blue


//---- input parameters
extern int       FastMAPeriod=4;
extern int       SlowMAPeriod=14;
extern int       FastMAType=1;
extern int       SlowMAType=1;

//---- buffers
double MACDLineBuffer[];
double SignalLineBuffer[];
int    FastMAMode;
int    SlowMAMode;
string strFastMAType;
string strSlowMAType;

//---- variables
double alpha = 0;
double alpha_1 = 0;
int    SignalMAPeriod = 1;




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
switch (FastMAType)
   {
      case 1: strFastMAType="S"; FastMAMode=MODE_SMA; break;
      case 2: strFastMAType="E"; FastMAMode=MODE_EMA; break;
      case 3: strFastMAType="W"; FastMAMode=MODE_LWMA; break;
      default: strFastMAType="S"; FastMAMode=MODE_SMA; break;
   }

switch (SlowMAType)
   {
      case 1: strSlowMAType="S"; SlowMAMode=MODE_SMA; break;
      case 2: strSlowMAType="E"; SlowMAMode=MODE_EMA; break;
      case 3: strSlowMAType="W"; SlowMAMode=MODE_LWMA; break;
      default: strSlowMAType="S"; SlowMAMode=MODE_SMA; break;
   }


   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   //---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MACDLineBuffer);
   SetIndexDrawBegin(0,SlowMAPeriod);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1,SignalLineBuffer);
   SetIndexDrawBegin(1,SlowMAPeriod+SignalMAPeriod);
   SetIndexDrawBegin(2,SlowMAPeriod+SignalMAPeriod);
   //---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MA Cross ("+FastMAPeriod+"-"+strFastMAType+","+SlowMAPeriod+"-"+strSlowMAType+") ");
   SetIndexLabel(0,"DPO");
   SetIndexLabel(1,"Signal");
   SetLevelStyle(STYLE_DOT,1,Silver);
   SetLevelValue(0,0);
   
   //----
	alpha = 2.0 / (SignalMAPeriod + 1.0);
	alpha_1 = 1.0 - alpha;
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   //---- 
   
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int limit;
   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(int i=limit; i>=0; i--)
   {
      MACDLineBuffer[i] = MathRound((iMA(NULL,0,FastMAPeriod,0,FastMAMode,PRICE_CLOSE,i) - iMA(NULL,0,SlowMAPeriod,0,SlowMAMode,PRICE_CLOSE,i))*10000);
      SignalLineBuffer[i] = alpha*MACDLineBuffer[i] + alpha_1*SignalLineBuffer[i+1];

   }
   
   //----
   return(0);
}
//+------------------------------------------------------------------+

Comments