blauergodicmdi

Download script
Author: Copyright � 2013, Nikolay Kositsin

The BlauErgodicMDI is a sophisticated technical analysis tool designed to help traders visualize price momentum and trend direction by analyzing the relationship between current market prices and their smoothed historical averages. Instead of simply looking at where the price is, this indicator focuses on how much the price is "deviating" from its expected path, providing a layered approach to identifying trend strength and potential shifts.

Core Logic and Mechanism

The indicator operates through a multi-stage filtering process. Rather than using a single calculation, it passes price data through several layers of smoothing and differentiation:

  1. Price Smoothing: The script starts by taking a raw price point (which can be customized to include Close, Open, High, Low, or various weighted averages) and applies a specialized smoothing algorithm (XMA). This removes "noise" from the market to reveal the underlying trend.
  2. Deviation Analysis: Once the price is smoothed, the script calculates the difference between the actual price and this smoothed average. This represents the immediate momentum of the market.
  3. Nested Smoothing Layers: The logic does not stop at the first calculation. It takes that "difference" value and runs it through three additional layers of smoothing (XMA2, XMA3, and XMA4). Each layer acts as a filter, progressively refining the data to isolate significant structural movements while discarding minor fluctuations.
  4. Final Output: The resulting data points are used to populate two main visual elements: a "cloud" (representing the core signal) and a multi-colored histogram.

Visual Interpretation

The script translates these complex calculations into two distinct visual formats on a separate window below the price chart:

  • The Colored Cloud: This provides a primary visual representation of the indicator's signal, helping traders see the overall "flow" of the market momentum.
  • The Multi-Colored Histogram: The histogram changes colors dynamically based on the direction and velocity of the smoothed data. It uses a five-color logic to communicate different states:
    • It tracks whether the indicator value is moving up or down relative to its previous position.
    • It detects whether the current momentum is positive (above zero) or negative (below zero).
    • By changing colors based on these movements, it allows a trader to see at a glance if momentum is accelerating, decelerating, or reversing.

Summary for the Trader

In essence, this tool acts as a sophisticated "momentum filter." By processing price data through four distinct stages of smoothing and difference calculation, it attempts to provide a clearer picture of the market's true trend than standard indicators might offer. It helps users identify not just whether the price is moving, but the underlying strength and reliability of that movement.

15 Views
0 Downloads
0 Favorites
blauergodicmdi
//+---------------------------------------------------------------------+
//|                                                  BlauErgodicMDI.mq5 |
//|                                  Copyright © 2013, Nikolay Kositsin | 
//|                                 Khabarovsk,   farria@mail.redcom.ru | 
//+---------------------------------------------------------------------+ 
//| Place the SmoothAlgorithms.mqh file                                 |
//| in the directory: terminal_data_folder\MQL5\Include                 |
//+---------------------------------------------------------------------+
//--- Copyright
#property copyright "Copyright © 2013, Nikolay Kositsin"
//--- link to the website of the author
#property link "farria@mail.redcom.ru" 
#property description "Ergodic MDI-Oscillator"
//--- Indicator version
#property version   "1.00"
//--- drawing the indicator in a separate window
#property indicator_separate_window
//--- four buffers are used for indicator calculation and drawing
#property indicator_buffers 4
//--- two plots are used
#property indicator_plots   2
//+----------------------------------------------+
//|  Indicator 1 drawing parameters              |
//+----------------------------------------------+
//---- drawing the indicator as a colored cloud
#property indicator_type1   DRAW_FILLING
//---- the following colors are used as the indicator colors
#property indicator_color1  clrLime,clrViolet
//--- displaying the indicator label
#property indicator_label1  "Blau Ergodic MDI Signal"
//+----------------------------------------------+
//|  Indicator 2 drawing parameters              |
//+----------------------------------------------+
//---- drawing indicator as a four-color histogram
#property indicator_type2 DRAW_COLOR_HISTOGRAM
//--- colors of the five-color histogram are as follows
#property indicator_color2 clrDeepPink,clrOrange,clrGray,clrYellowGreen,clrTeal
//--- Indicator line is a solid one
#property indicator_style2 STYLE_SOLID
//--- indicator line width is 2
#property indicator_width2 2
//--- displaying the indicator label
#property indicator_label2  "Blau Ergodic MDI"
//+----------------------------------------------+
//|  CXMA class description                      |
//+----------------------------------------------+
#include <SmoothAlgorithms.mqh> 
//+----------------------------------------------+
//--- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file
CXMA XMA1,XMA2,XMA3,XMA4;
//+----------------------------------------------+
//|  declaration of enumerations                 |
//+----------------------------------------------+
enum Applied_price_      // type of constant
  {
   PRICE_CLOSE_ = 1,     // Close
   PRICE_OPEN_,          // Open
   PRICE_HIGH_,          // High
   PRICE_LOW_,           // Low
   PRICE_MEDIAN_,        // Median Price (HL/2)
   PRICE_TYPICAL_,       // Typical Price (HLC/3)
   PRICE_WEIGHTED_,      // Weighted Close (HLCC/4)
   PRICE_SIMPL_,         // Simple Price (OC/2)
   PRICE_QUARTER_,       // Quarted Price (HLOC/4) 
   PRICE_TRENDFOLLOW0_,  // TrendFollow_1 Price 
   PRICE_TRENDFOLLOW1_,  // TrendFollow_2 Price 
   PRICE_DEMARK_         // Demark Price
  };
//+----------------------------------------------+
//| Indicator input parameters                   |
//+----------------------------------------------+
input Smooth_Method XMA_Method=MODE_EMA; // Averaging method
input uint XLength=20;                   // Depth of price averaging 
input uint XLength1=5;                   // Depth of the first averaging
input uint XLength2=3;                   // Depth of the second averaging
input uint XLength3=8;                   // Depth of averaging of the signal line
input int XPhase=15;                     // Smoothing parameter
//--- XPhase: for JJMA it varies within the range -100 ... +100 and influences the quality of the transient period;
//--- XPhase: for VIDIA it is a CMO period, for AMA it is a slow average period
input Applied_price_ IPC=PRICE_CLOSE;    // Price constant
//--- declaration of dynamic arrays that
//--- will be used as indicator buffers
double IndBuffer[],ColorIndBuffer[];
double UpBuffer[],DnBuffer[];
//--- declaration of the integer variables for the start of data calculation
int min_rates_total,min_rates_1,min_rates_2,min_rates_3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+  
void OnInit()
  {
//--- initialization of variables of the start of data calculation
   min_rates_1=XMA1.GetStartBars(XMA_Method,XLength,XPhase);
   min_rates_2=min_rates_1+XMA1.GetStartBars(XMA_Method,XLength1,XPhase);
   min_rates_3=min_rates_2+XMA1.GetStartBars(XMA_Method,XLength2,XPhase);
   min_rates_total=min_rates_3+XMA1.GetStartBars(XMA_Method,XLength3,XPhase);   
//--- Set dynamic array as an indicator buffer
   SetIndexBuffer(0,UpBuffer,INDICATOR_DATA);
//--- Set dynamic array as an indicator buffer
   SetIndexBuffer(1,DnBuffer,INDICATOR_DATA);
//--- Set dynamic array as an indicator buffer
   SetIndexBuffer(2,IndBuffer,INDICATOR_DATA);
//--- Setting a dynamic array as a color index buffer   
   SetIndexBuffer(3,ColorIndBuffer,INDICATOR_COLOR_INDEX);
//--- shifting the start of drawing of the indicator
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//--- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- shifting the start of drawing of the indicator
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//--- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
//--- Creation of the name to be displayed in a separate sub-window and in a pop up help
   IndicatorSetString(INDICATOR_SHORTNAME,"BlauErgodicMDI");
//--- Determining the accuracy of displaying the indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//---
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,    // number of bars in history at the current tick
                const int prev_calculated,// amount of history in bars at the previous tick
                const datetime &time[],
                const double &open[],
                const double& high[],     // price array of price maximums for the indicator calculation
                const double& low[],      // price array of minimums of price for the indicator calculation
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- checking if the number of bars is enough for the calculation
   if(rates_total<min_rates_total) return(0);

//--- declarations of local variables 
   double price,xprice,dif,xdif,xxdif,xxxdif;
   int first,bar;

//--- calculation of the 'first' starting index for the bars recalculation loop
   if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator
     {
      first=0; // starting index for calculation of all bars
     }
   else first=prev_calculated-1; // starting number for calculation of new bars

//--- main indicator calculation loop
   for(bar=first; bar<rates_total && !IsStopped(); bar++)
     {

      price=PriceSeries(IPC,bar,open,low,high,close);   
      xprice=XMA1.XMASeries(0,prev_calculated,rates_total,XMA_Method,XPhase,XLength,price,bar,false);     
      dif=(price-xprice)/_Point;    
      xdif=XMA2.XMASeries(min_rates_1,prev_calculated,rates_total,XMA_Method,XPhase,XLength1,dif,bar,false);
      xxdif=XMA3.XMASeries(min_rates_2,prev_calculated,rates_total,XMA_Method,XPhase,XLength2,xdif,bar,false);
      xxxdif=XMA4.XMASeries(min_rates_3,prev_calculated,rates_total,XMA_Method,XPhase,XLength3,xxdif,bar,false);
      
      IndBuffer[bar]=xxdif;
      UpBuffer[bar]=xxdif;
      DnBuffer[bar]=xxxdif;
     }

   if(prev_calculated>rates_total || prev_calculated<=0) first++;
//--- Îñíîâíîé öèêë ðàñêðàñêè èíäèêàòîðà Ind
   for(bar=first; bar<rates_total && !IsStopped(); bar++)
     {
      int clr=2;

      if(IndBuffer[bar]>0)
        {
         if(IndBuffer[bar]>IndBuffer[bar-1]) clr=4;
         if(IndBuffer[bar]<IndBuffer[bar-1]) clr=3;
        }

      if(IndBuffer[bar]<0)
        {
         if(IndBuffer[bar]<IndBuffer[bar-1]) clr=0;
         if(IndBuffer[bar]>IndBuffer[bar-1]) clr=1;
        }

      ColorIndBuffer[bar]=clr;
     }
//---     
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments