BuySell_Filter
Download scriptThis tool is designed as a visual filtering system for traders who want to identify market trends and potential entry points by analyzing the relationship between different moving averages. Instead of looking at raw price action alone, this script simplifies the data into a clear visual display that categorizes the current market "momentum" into specific states.
How it Works
The logic is based on comparing four distinct Moving Averages (MA) against one another. Think of these moving averages as different "speeds" of the market: some react very quickly to price changes, while others are slower and represent the broader trend.
By measuring how these various speeds interact, the script identifies four specific market conditions:
- Strong Bullish Momentum: When the fastest average is positioned above both the medium-speed and the slow-speed averages, it signals a strong upward push.
- Bullish Correction/Consolidation: When the fastest average stays above the slow-speed trend but falls below the medium-speed average, it suggests the upward move might be slowing down or encountering resistance.
- Bearish Correction/Consolidation: When the fastest average remains above the medium-speed average but falls below the slow-speed trend, it indicates a potential cooling off of a previous move.
- Strong Bearish Momentum: When the fastest average drops below both the medium and slow averages, it signals a dominant downward trend.
Visual Representation
The script translates these mathematical comparisons into a visual histogram in a separate window on your chart. This allows you to see the market status at a glance:
- Green Tones: Represent different types of upward (bullish) pressure.
- Red Tones: Represent different types of downward (bearish) pressure.
Key Features
- Multi-Timeframe Compatibility: The tool can be set to analyze various timeframes, from 1-minute "scalping" charts to daily or monthly views, allowing you to see trend filters across different horizons.
- Customizable Sensitivity: You can adjust the periods and calculation methods of the four moving averages to make the filter more sensitive to fast price changes or more stable for long-term trend tracking.
- Quick Identification: By summarizing complex math into a simple visual output, it helps traders quickly filter out "noise" and focus on trades that align with the prevailing market direction.
//+------------------------------------------------------------------+
//| BuySell_Filter.mq4 |
//| Copyright © 2008, masemus |
//| Gresik@Indonesia |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, masemus"
#property link "Gresik@Indonesia"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 FireBrick
#property indicator_color3 SeaGreen
#property indicator_color4 Lime
//---- input parameters
extern int TF=0;
extern int MA1Period = 4;
extern int MA1_Shift = 0;
extern int MA1_Method = 0;
extern int MA1_Price_Type = 0;
extern int MA2Period = 4;
extern int MA2_Shift = 0;
extern int MA2_Method = 0;
extern int MA2_Price_Type = 1;
extern int MA3Period = 20;
extern int MA3_Shift = 0;
extern int MA3_Method = 0;
extern int MA3_Price_Type = 0;
extern int MA4Period = 20;
extern int MA4_Shift = 0;
extern int MA4_Method = 0;
extern int MA4_Price_Type = 1;
extern string Display_Text = " Scalp";
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
string TimeFrameStr;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3,ExtMapBuffer4);
switch(TF)
{
case 1 : TimeFrameStr="Period_M1"; break;
case 5 : TimeFrameStr="Period_M5"; break;
case 15 : TimeFrameStr="Period_M15"; break;
case 30 : TimeFrameStr="Period_M30"; break;
case 60 : TimeFrameStr="Period_H1"; break;
case 240 : TimeFrameStr="Period_H4"; break;
case 1440 : TimeFrameStr="Period_D1"; break;
case 10080 : TimeFrameStr="Period_W1"; break;
case 43200 : TimeFrameStr="Period_MN1"; break;
default : TimeFrameStr="Current TF"; TF=0;
}
IndicatorShortName("BS_Filter ("+TimeFrameStr+")" + Display_Text);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
for (int i = 0; i < 1000; i++){
ExtMapBuffer1[i]=0;
ExtMapBuffer2[i]=0;
ExtMapBuffer3[i]=0;
ExtMapBuffer4[i]=0;
double MA1 = iMA(Symbol(),TF,MA1Period,MA1_Shift,MA1_Method,MA1_Price_Type,i);
double MA2 = iMA(Symbol(),TF,MA2Period,MA2_Shift,MA2_Method,MA2_Price_Type,i);
double MA3 = iMA(Symbol(),TF,MA3Period,MA3_Shift,MA3_Method,MA3_Price_Type,i);
double MA4 = iMA(Symbol(),TF,MA4Period,MA4_Shift,MA4_Method,MA4_Price_Type,i);
if(MA1>MA2 && MA1>MA3)ExtMapBuffer4[i] = 1;
if(MA1<=MA2 && MA1>MA3){ExtMapBuffer2[i] = 1;}
if(MA1>MA2 && MA1<=MA3)ExtMapBuffer3[i] = 1;
if(MA1<MA2 && MA1<MA3){ExtMapBuffer1[i] = 1;}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments