Normalizer_3param

Author: Copyright � 2008, al_su
Normalizer_3param

The Normalizer tool is designed to take standard technical indicators—specifically those that cross a zero level (such as MACD or CCI)—and convert their raw data into a standardized, consistent format. The primary goal of this script is to "level the playing field" for different types of market signals so they can be compared more easily on a single visual scale.

How it Works

The logic behind this tool operates in three distinct stages:

1. Dynamic Environment Analysis

Before displaying any data, the tool analyzes the historical price action to understand the specific "personality" of the market conditions. It looks for instances where your chosen indicator crosses the zero line. By calculating the frequency and timing of these crossings, the script determines a Characteristic Period. This value essentially identifies the natural rhythm or volatility cycle of the current market environment.

2. Statistical Standardization

Once the market's rhythm is established, the tool applies a mathematical transformation to the indicator’s values. It calculates a moving average of the magnitude of the indicator over that characteristic period. By dividing the raw indicator value by this calculated average, it removes the "noise" and extreme outliers caused by sudden price spikes. This ensures that an indicator moving in a high-volatility market looks visually similar to the same indicator moving in a low-volatility market.

3. Smooth Curve Mapping (Tanh Transformation)

The final step of the logic involves a mathematical function called "Hyperbolic Tangent" (Tanh). This is used to compress the resulting data into a specific, bounded range. Instead of allowing the indicator values to wander off infinitely in either direction, this process "smooths out" the line, making it more fluid and easier to read. It effectively creates a refined visual representation where the most significant trends are highlighted while maintaining a clean, consistent boundary.

Summary for the User

In simple terms, this script takes a messy, raw indicator and "normalizes" it. It automatically detects how fast and how far your chosen indicator usually moves, then scales everything down so that you can view the trend clearly without being overwhelmed by extreme price fluctuations. This allows for a much cleaner visual analysis of momentum and direction.

Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
Normalizer_3param
//+------------------------------------------------------------------+
//|                                                   Normalizer.mq4 |
//|                                          Copyright © 2008, al_su |
//|                                                  al_su31@mail.ru |
//+------------------------------------------------------------------+
//mod Normalizer_3param.mq4
#property copyright "Copyright © 2008, al_su"
#property link      "al_su31@mail.ru"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_maximum 1
#property indicator_minimum -1
#property indicator_level1 0.25
#property indicator_level2 0.5
#property indicator_level3 0.75
#property indicator_level4 -0.25
#property indicator_level5 -0.5
#property indicator_level6 -0.75
#property indicator_levelcolor C'74,85,96'//SlateGray

//---- input parameters
#define PERIODS_CHARACTERISTIC 7

extern string  Indicator="macd";//macd, cci ... any  with zero cross
extern int     mode=0;
extern int     param1=12;//Íó èëè 9, íå âàæíî...
extern int     param2=26;
extern int     param3=9;//Ñêîêà íàäî ïàðàìåòðîâ, ñòîêà è çàäàåì
extern string  note_Indicator="type-in IndicatorFileName like macd, cci ... any  with zero level cross";

//---- buffers 
double Normalizer[];
double characteristic_period;
double sigma;

//-------------------------------------------------------------------------------
double Indyuk(int shift)
{
   return (iCustom(0,0,Indicator,param1,param2,param3,/* è ò.ä.:)*/mode,shift));
}

double MathTanh(double x)
{ 
   double exp;
   if(x>0)  {exp=MathExp(-2*x);return ((1-exp)/(1+exp));}
   else {exp=MathExp(2*x);return ((exp-1)/(1+exp));}
}

double ArrayAverage(double a[])
{
   int i;
   double s;
   if(ArraySize(a)<1) return (0);
   s=0;
   for(i=0;i<ArraySize(a);i++)  s+=a[i];
   return (s/ArraySize(a));
}

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorShortName("Normalized "+Indicator);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Normalizer);
   
   int i;
   int count, count_zeros;
   count=0;
   count_zeros=0;

   double periods[];
   for(i=Bars-2;i>=0;i--)
   {
      if(Indyuk(i)*Indyuk(i+1)<0)//ïåðåõîä ÷åðåç 0
         {
            count++;
            ArrayResize(periods,count);
            periods[ArraySize(periods)-1]=0;
         }
      if(ArraySize(periods)>0) periods[ArraySize(periods)-1]++;
   }

   characteristic_period=2*PERIODS_CHARACTERISTIC*ArrayAverage(periods);
   
   SetIndexDrawBegin(0,characteristic_period);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int   i,j, counted_bars=IndicatorCounted();
   double S;
//----
//   for(i=Bars-counted_bars-characteristic_period-1;i>=0;i--)
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int  limit=Bars-counted_bars;
   limit=MathMax(limit,characteristic_period-1);
   for (i=limit; i>=0; i--)
   {
      S=0;
      for(j=0;j<characteristic_period;j++) S+=MathPow(Indyuk(i+j),2);
      S/=characteristic_period;
      S=MathSqrt(S);
      if(S!=0) Normalizer[i]=Indyuk(i)/S;
      Normalizer[i]=MathTanh(Normalizer[i]);
   } 
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments