BuySell_v2
Download scriptThis tool is designed as a visual market analysis indicator for the MetaTrader platform. Its primary purpose is to simplify the way traders view price momentum and trend direction by comparing three different Moving Averages simultaneously.
Core Logic and Functionality
The script works by calculating three distinct Moving Averages (MA) based on specific timeframes and lengths that you can customize. These averages represent the "average" price of an asset over different periods, helping to smooth out market noise.
The indicator looks at the relationship between these three averages to determine which "zone" the current price action falls into. It evaluates the position of the fastest moving average relative to the two slower moving averages to create four distinct visual signals:
- Strong Bullish Signal: When the fastest moving average is higher than both of the slower moving averages, it indicates a dominant upward trend.
- Mixed Bullish/Bearish Signal: When the fastest moving average sits between the two slower ones (higher than one but lower than the other), it suggests a period of transition or moderate momentum.
- Weak Bullish/Mixed Signal: This identifies scenarios where the fastest moving average is lower than one slower average but higher than the other, signaling shifting pressure.
- Strong Bearish Signal: When the fastest moving average falls below both of the slower moving averages, it indicates a dominant downward trend.
Visual Representation
Instead of cluttering your main price chart with lines, this tool creates a dedicated visual window at the bottom of your screen. It uses a histogram style to display these four different states using a color-coded system:
- Deep Pink & Light Pink: Represent various degrees of bullish (upward) sentiment.
- Light Sky Blue & Dodger Blue: Represent various degrees of bearish (downward) sentiment.
User Customization
The tool is highly adaptable to different trading styles. You can adjust the following without needing any technical knowledge:
- Timeframes: You can choose which timeframe the indicator should calculate data for (e.g., 1-minute, 1-hour, Daily, etc.).
- Moving Average Lengths: You can define the "speed" of the three averages. By changing the numerical values (like 1, 4, or 20), you can make the indicator more sensitive to quick price changes or more focused on long-term trends.
- Automatic Naming: The script automatically updates its display name based on the timeframe you select, making it easy to identify which chart the data belongs to at a glance.
//+------------------------------------------------------------------+
//| BuySell_v2.mq4 |
//| Copyright © 2008, masemus |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, masemus"
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 4
#property indicator_color1 DeepPink
#property indicator_color2 LightPink
#property indicator_color3 LightSkyBlue
#property indicator_color4 DodgerBlue
//---- input parameters
extern int TF=0;
extern int MA1Val = 1;
extern int MA1Type = 0;
extern int MA2Val = 4;
extern int MA2Type = 0;
extern int MA3Val = 20;
extern int MA3Type = 0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
string TimeFrameStr;
double MA1,MA2,MA3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
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 Timeframe"; TF=0;
}
IndicatorShortName("BuySell_v2 ("+TimeFrameStr+")");
//----
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 < 300; i++){
ExtMapBuffer1[i]=0;
ExtMapBuffer2[i]=0;
ExtMapBuffer3[i]=0;
ExtMapBuffer4[i]=0;
MA1=iMA(NULL,TF,MA1Val,0,MODE_SMA,PRICE_CLOSE,i);
MA2=iMA(NULL,TF,MA2Val,0,MODE_SMA,PRICE_CLOSE,i);
MA3=iMA(NULL,TF,MA3Val,0,MODE_SMA,PRICE_CLOSE,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