BB_FlatSq_mtf_sw
Download scriptThis tool is designed to help traders identify specific moments of market tension and potential price breakouts by combining two distinct types of technical analysis: volatility measurements and "squeeze" mechanics.
Core Logic Overview
The script operates by analyzing price action across different timeframes to determine when the market is transitioning from a period of low activity (consolidation) to a period of high activity (expansion). It focuses on identifying these phases to help users spot potential moves before they happen.
Key Components of the Analysis
1. Volatility Boundaries (Bollinger Band Logic) The tool establishes a baseline for "normal" market behavior using standard deviation.
- It calculates an average price and then determines a range above and below that average based on the volatility of the asset.
- Essentially, it creates a "buffer zone." When the price stays within these bounds, the market is considered to be in a state of relative equilibrium.
2. The Squeeze Mechanism The script includes a secondary layer of logic known as a "Squeeze" indicator. This measures the relationship between two different types of volatility:
- It compares short-term price fluctuations against longer-term price averages.
- When these two measurements converge (meaning the market is moving very little and becoming "compressed"), the script identifies a "Squeeze."
3. Signal Generation The tool combines these two data points to provide visual cues:
- The Squeeze Detection: The logic looks for instances where volatility is exceptionally low (the squeeze).
- The Directional Cue: If the market is in a squeezed state, the script looks at the current price position relative to its moving average.
- If the price is trending above the average during a squeeze, it flags a potential upward move.
- If the price is trending below the average during a squeeze, it flags a potential downward move.
How it appears to the user
Rather than just showing raw numbers, the script translates this complex math into visual markers on your chart:
- It plots the volatility boundaries so you can see the "normal" range of price movement.
- It places specific symbols (arrows) to alert you when the technical conditions for a "Squeeze" are met. These symbols act as an early warning system, suggesting that energy is building up and a breakout in a specific direction may be imminent.
Summary for the Trader
In short, this script filters out the "noise" of the market. It waits for the market to get quiet and compressed (the squeeze) and then watches where the price is leaning. When it detects both conditions simultaneously, it alerts you, helping you anticipate the next major move in price direction.
//+------------------------------------------------------------------+
//| BBflat_sw.mq4 |
//|mtf 2007forextsd +BBSqueeze ki by Raff |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 BlueViolet
#property indicator_levelcolor SlateGray
#property indicator_level1 0.0004
#property indicator_level2 -0.0004
extern int TimeFrame=0;
extern int period=20;
extern int method=0;
extern int price=0;
extern double deviation=2;
extern int shift=0;
extern int MaxBarsToCount = 1500;
extern double SqzSigLevel = -0.0006; // bbsqueeze
extern int SqzbolPrd = 20;
extern double SqzbolDev = 2.0;
extern int SqzkeltPrd = 20;
extern double SqzkeltFactor= 1.5;
extern string note_Price = "0C1O 2H3L 4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
extern string MA_Method = "SMA0 EMA1 SMMA2 LWMA3";
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN";
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double upK[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexStyle(4,DRAW_ARROW,EMPTY);
SetIndexBuffer(4,upK);
SetIndexEmptyValue(4,EMPTY_VALUE);
SetIndexArrow(4,159);
SetIndexLabel(0,"");
SetIndexLabel(1,"Std"+deviation+"");
SetIndexLabel(2,"");
SetIndexLabel(3,"");
SetIndexLabel(4,"");
//----
switch(TimeFrame)
{
case 1 : string TimeFrameStr= "M1"; break;
case 5 : TimeFrameStr= "M5"; break;
case 15 : TimeFrameStr= "M15"; break;
case 30 : TimeFrameStr= "M30"; break;
case 60 : TimeFrameStr= "H1"; break;
case 240 : TimeFrameStr= "H4"; break;
case 1440 : TimeFrameStr= "D1"; break;
case 10080 : TimeFrameStr= "W1"; break;
case 43200 : TimeFrameStr= "MN1"; break;
default : TimeFrameStr= "CurrTF";
}
IndicatorShortName("BBFlat ("+period+";"+deviation+") ["+TimeFrameStr+"]");
if (TimeFrame < Period()) TimeFrame = Period();
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
datetime TimeArray[];
int i,limit,y=0,counted_bars=IndicatorCounted();
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
double ima, std;
double diff,d,dPrev, Std,bbs;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = Bars-counted_bars;
limit = MathMax (limit,TimeFrame/Period());
limit= MathMin(limit,MaxBarsToCount);
for(i=0,y=0;i<limit;i++)
{
if (Time[i]<TimeArray[y]) y++;
ima=iMA(NULL,TimeFrame,period,0,method,price,y);
std=deviation*iStdDev(NULL,TimeFrame,period,0,method,price,y);
ExtMapBuffer1[i]=0;
ExtMapBuffer2[i]=std;
ExtMapBuffer3[i]=-std;
ExtMapBuffer4[i]=iClose(NULL,TimeFrame,y)-ima;
////
diff = iATR(NULL,TimeFrame,SqzkeltPrd,y)*SqzkeltFactor;
Std = iStdDev(NULL,TimeFrame,SqzbolPrd,MODE_SMA,0,PRICE_CLOSE,y);
bbs = SqzbolDev * Std / diff;
if(bbs<1)
{
if (ExtMapBuffer4[i]>0)
upK[i]= SqzSigLevel;
else
upK[i]= -SqzSigLevel;
} else {
upK[i]=EMPTY_VALUE;
}
////
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments