6MovingAcerages
Download scriptThis technical tool is designed to provide a comprehensive visual overview of market trends by plotting six different Simple Moving Averages (SMA) directly onto your trading chart. By displaying multiple averages simultaneously, the script allows traders to see the relationship between short-term price fluctuations and long-term momentum at a single glance.
Core Functionality
The primary logic of the script revolves around calculating "Simple Moving Averages." An SMA takes the closing prices of an asset over a specific period of time and calculates their average. This smoothes out the "noise" of minor price spikes, making it easier to identify the underlying direction of the market.
Key Features
- Multi-Timeframe Perspective: The script tracks six distinct periods (defaulting to 5, 10, 25, 75, 100, and 200 units). This allows you to observe:
- Short-Term Trends: Fast-moving lines that react quickly to immediate price changes.
- Medium-Term Trends: Balanced lines that show the current "wave" of the market.
- Long-Term Trends: Slow-moving lines that act as major support or resistance levels and indicate the overall health of the market over a larger duration.
- Visual Clarity: Each of the six averages is assigned a unique color and distinct line style. This ensures that even when the lines overlap or cluster together, you can easily distinguish which timeframe each line represents.
- Dynamic Calculation: The script automatically updates with every new price tick. It calculates the average based on the "Close" price, ensuring that the data displayed is always synchronized with the most recent completed price action.
How it Benefits Your Trading
Instead of looking at just one indicator, this tool provides a layered view of market sentiment. By observing where these lines cross each other (cross-overs) or how they cluster together, traders can better identify potential trend reversals, momentum shifts, and significant price corridors. It serves as a foundational visual aid for identifying the "big picture" while keeping an eye on immediate price movements.
/*------------------------------------------------------------------+
6MovingAverages.mq4
Copyright (c) 2010, Ken.tak
http://kenchanfxblog.blog76.fc2.com/
+------------------------------------------------------------------+*/
#property copyright "ken.tak"
#property link "http://kenchanfxblog.blog76.fc2.com/"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 LightBlue
#property indicator_color2 LightGreen
#property indicator_color3 Khaki
#property indicator_color4 LightSalmon
#property indicator_color5 Pink
#property indicator_color6 Violet
//---- input parameters
extern int MA1= 5;
extern int MA2= 10;
extern int MA3= 25;
extern int MA4= 75;
extern int MA5= 100;
extern int MA6= 200;
//---- buffers
double MABuffer1[];
double MABuffer2[];
double MABuffer3[];
double MABuffer4[];
double MABuffer5[];
double MABuffer6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,1,2);
SetIndexBuffer(0,MABuffer1);
string index0=StringConcatenate("MA ",MA1);
SetIndexLabel(0,index0);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,MABuffer2);
string index1=StringConcatenate("MA ",MA2);
SetIndexLabel(1,index1);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,MABuffer3);
string index2=StringConcatenate("MA ",MA3);
SetIndexLabel(2,index2);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,MABuffer4);
string index3=StringConcatenate("MA ",MA4);
SetIndexLabel(3,index3);
SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,MABuffer5);
string index4=StringConcatenate("MA ",MA5);
SetIndexLabel(4,index4);
SetIndexStyle(5,DRAW_LINE);
SetIndexBuffer(5,MABuffer6);
string index5=StringConcatenate("MA ",MA6);
SetIndexLabel(5,index5);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int limit = Bars - counted_bars;
for (int i = 0; i < limit; i++)
{
MABuffer1[i] = iMA(NULL, 0, MA1, 0, MODE_SMA, PRICE_CLOSE, i);
MABuffer2[i] = iMA(NULL, 0, MA2, 0, MODE_SMA, PRICE_CLOSE, i);
MABuffer3[i] = iMA(NULL, 0, MA3, 0, MODE_SMA, PRICE_CLOSE, i);
MABuffer4[i] = iMA(NULL, 0, MA4, 0, MODE_SMA, PRICE_CLOSE, i);
MABuffer5[i] = iMA(NULL, 0, MA5, 0, MODE_SMA, PRICE_CLOSE, i);
MABuffer6[i] = iMA(NULL, 0, MA6, 0, MODE_SMA, PRICE_CLOSE, i);
}
return(0);
}
//+------------------------------------------------------------------+
Comments