MA_SquizeMA_Eds_mtf

Download script
Author: Kalenzo

The Squize_MA_E_mtf indicator is a specialized technical analysis tool designed for traders who want to visualize market trends and identify periods of low volatility or "squeezes." Unlike standard moving averages that simply track price, this script calculates the relationship between two different moving averages to determine when the market is consolidating.

Core Functionality

The logic operates by comparing a fast-moving average (short-term trend) with a slow-moving average (long-term trend). When these two lines get very close to one another, it indicates that price action is tightening—a state often referred to as a "squeeze." This is frequently a precursor to a significant breakout in either direction.

Key Technical Behaviors

  • Multi-Timeframe Analysis: One of the primary features of this script is its ability to look at higher timeframes than the one currently displayed on your chart. This allows you to see the broader market trend (e.g., looking at the Daily trend while trading on a 15-minute chart) without switching windows.
  • Dynamic Volatility Adjustment: The tool includes a smart mechanism to decide what constitutes a "squeeze." You can set it to use a fixed number of pips, or you can enable an ATR (Average True Range) mode. In ATR mode, the indicator automatically adjusts its sensitivity based on recent market volatility, making it more reliable during different market conditions.
  • Visual Envelopes: When the "squeeze" condition is met (the distance between the two moving averages falls below your defined threshold), the indicator can draw visual envelopes. These serve as a boundary, highlighting the zone where price activity is compressed.
  • Convergence Logic: If envelopes are turned off, the script performs a mathematical "merger" of the two moving averages when they are in a squeeze state, effectively unifying the signals to show a single point of equilibrium.

How it Helps Traders

By identifying these "squeezes," the indicator helps traders spot moments where market energy is building up. Instead of getting caught in choppy, sideways movements, traders can use this tool to recognize when the market is "coiling" like a spring, potentially preparing for a large explosive move once the price breaks out of the defined squeeze zone.

Indicators Used
Moving average indicatorIndicator of the average true range
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
MA_SquizeMA_Eds_mtf
//+------------------------------------------------------------------+
//| Squize_MA_E_mtf                                    Squize_MA.mq4 |
//| mtf:ForexTSD.com 2007                                    Kalenzo |
//| mladen's formula   ki                bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_buffers 4

#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Goldenrod

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2

double upma[];
double dnma[];
double SqLup[]; 
double SqLdn[]; 

extern int Ma1Period = 5;
extern int Ma1Type   = MODE_EMA;
extern int Ma1Price  = PRICE_CLOSE;
extern string     ___= "___";
extern int Ma2Period = 21;
extern int Ma2Type   = MODE_EMA;
extern int Ma2Price  = PRICE_CLOSE;
extern string  _____ = "_______";

extern int MAsThreSHoldPips = 15;
extern bool    ATRmode   =true; 
extern int     ATRperiod =50;
extern double  ATRmultipl=0.4;
extern bool    envelopes   =true; 


extern int     TimeFrame = 0;
extern string  note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
extern string   note_MA_Type    = "SMA0 EMA1 SMMA2 LWMA3";
extern string   note_Price      = "0C 1O 2H 3L 4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";

string IndicatorFileName;
#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0,upma);
   SetIndexBuffer(1,dnma);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   
   SetIndexBuffer(2,SqLup);
   SetIndexBuffer(3,SqLdn);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   
   SetIndexLabel(0,"SqMA1("+Ma1Period+")["+TimeFrame+"]");
   SetIndexLabel(1,"SqMA2("+Ma2Period+")["+TimeFrame+"]");
   SetIndexLabel(2,"SqMA Env("+MAsThreSHoldPips+")("+Ma1Period+","+Ma2Period+")["+TimeFrame+"]");
   SetIndexLabel(3,"SqMA Env("+MAsThreSHoldPips+")("+Ma1Period+","+Ma2Period+")["+TimeFrame+"]");

//----
   IndicatorShortName("SquizeMA ("+Ma1Period+","+Ma2Period+")["+TimeFrame+"]");
   if (TimeFrame < Period()) TimeFrame = Period();
   IndicatorFileName = WindowExpertName();



   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int limit,i;    
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit = Bars-counted_bars;
   
   
   if (TimeFrame != Period())
       {
         limit = MathMax(limit,TimeFrame/Period());
         datetime TimeArray[];
        
         ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame);
          
           for(i=0,int y=0; i<limit; i++)
           {
              if(Time[i]<TimeArray[y]) y++;
              
              upma  [i]  = iCustom(NULL,TimeFrame,IndicatorFileName,
                                    Ma1Period,Ma1Type,Ma1Price,"",Ma2Period,Ma2Type,Ma2Price,"",
                                    MAsThreSHoldPips,ATRmode,ATRperiod,ATRmultipl,envelopes,0,y);

              dnma  [i]  = iCustom(NULL,TimeFrame,IndicatorFileName,
                                    Ma1Period,Ma1Type,Ma1Price,"",Ma2Period,Ma2Type,Ma2Price,"",
                                    MAsThreSHoldPips,ATRmode,ATRperiod,ATRmultipl,envelopes,1,y);
 
              SqLup [i]   =iCustom(NULL,TimeFrame,IndicatorFileName,
                                    Ma1Period,Ma1Type,Ma1Price,"",Ma2Period,Ma2Type,Ma2Price,"",
                                    MAsThreSHoldPips,ATRmode,ATRperiod,ATRmultipl,envelopes,2,y);

              SqLdn [i]   =iCustom(NULL,TimeFrame,IndicatorFileName,
                                    Ma1Period,Ma1Type,Ma1Price,"",Ma2Period,Ma2Type,Ma2Price,"",
                                    MAsThreSHoldPips,ATRmode,ATRperiod,ATRmultipl,envelopes,3,y);


           }
         return(0);         
        }
//----
   
   for( 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);
 
         upma[i] = ma1;
         dnma[i] = ma2;
          
      if (ATRmode)   double delta = iATR(NULL,0,ATRperiod,i) * ATRmultipl/Point;
      else                  delta = MAsThreSHoldPips;


   
   if(madif/Point< delta)
     
   {
      if (envelopes)
       { 
       
       SqLup   [i] = ma2+ delta*Point; 
       SqLdn   [i] = ma2- delta*Point; 
       }
       else 
       {
               upma[i]  = ma1 -  (madif/2);
               dnma[i]  = ma1 -  (madif/2);
       }
         
   }
      
   }
   
   
      return(0);
  }
//+------------------------------------------------------------------+

Comments