Squize_MA
Download scriptThis custom indicator is designed to help traders visualize market trends by analyzing the relationship between two different moving averages. Its primary goal is to identify periods of significant price movement while visually "smoothing out" or compressing the data during times of low volatility.
Core Logic Overview
The tool operates by constantly comparing two separate Moving Averages (MA). By default, these are set as Exponential Moving Averages, which give more weight to recent price action, helping the indicator react quickly to new market information.
The logic follows three specific rules to determine what appears on your chart:
1. Identifying High Volatility (Active Trends) The script first calculates the "distance" or gap between the two moving averages. If this gap is large enough—specifically, if it exceeds a user-defined threshold—the indicator treats this as a significant trend. In these moments, the script displays the two moving averages separately on your chart (represented in Blue and Red). This allows you to see the clear momentum of the market.
2. Identifying Low Volatility (Market Squeeze) When the distance between the two moving averages is small (less than your defined threshold), it indicates that the market is moving sideways or "squeezing." Instead of showing a wide gap, the script performs a calculation to pull both lines toward each other.
3. The Smoothing Mechanism During these "squeeze" periods, the indicator creates a visual convergence. It takes the average position between the two lines and draws them at that specific point. This effectively collapses the distance between the lines, signaling to the trader that there is currently little clear direction in the price action.
Summary for the Trader
Essentially, this script acts as a dynamic filter. When the market is moving strongly in one direction, it expands to show you the trend clearly. When the market becomes choppy or stagnant, the lines "squeeze" together, providing a visual cue that volatility has decreased and the trend may be consolidating.
//+------------------------------------------------------------------+
//| Squize_MA.mq4 |
//| Kalenzo |
//| bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link "bartlomiej.gorski@gmail.com"
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
double upma[];
double dnma[];
extern int MaDifrential = 5;
extern int Ma1Type = MODE_EMA;
extern int Ma1Price = PRICE_CLOSE;
extern int Ma1Period = 5;
extern int Ma2Type = MODE_EMA;
extern int Ma2Price = PRICE_CLOSE;
extern int Ma2Period = 20;
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,upma);
SetIndexBuffer(1,dnma);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
//----
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) counted_bars=0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(int i = 0 ;i <= limit ;i++)
{
double ma1 = iMA(Symbol(),0,Ma1Period,0,Ma1Type,Ma1Price,i);
double ma2 = iMA(Symbol(),0,Ma2Period,0,Ma2Type,Ma2Price,i);
double madif = MathAbs(ma1-ma2);
if(madif/Point > MaDifrential)
{
upma[i] = ma1;
dnma[i] = ma2;
}
else
{
if(ma1>ma2)
{
upma[i] = ma1 - (madif/2);
dnma[i] = ma1 - (madif/2);
}
else
{
upma[i] = ma2 - (madif/2);
dnma[i] = ma2 - (madif/2);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments