MA_Details
Download scriptThis custom technical indicator is designed to provide traders with a visual representation of price trends by calculating and displaying various types of Moving Averages on a trading chart. Its primary goal is to simplify market analysis by smoothing out price fluctuations, making it easier to identify the underlying direction of the market.
Core Functionality
The script performs three main actions: calculating mathematical averages, drawing a visual trend line, and providing a real-time data label.
1. Flexible Calculation Methods The tool is highly versatile because it allows users to choose between four different types of Moving Averages depending on their trading style:
- Simple (SMA): The standard average of price over a specific period.
- Exponential (EMA): Gives more weight to recent price action, making it more responsive to sudden changes.
- Smoothed (SMMA): Provides a much smoother line by calculating a moving average of previous averages.
- Linear Weighted (LWMA): Weights the data linearly to prioritize the most recent candles.
2. Dynamic Data Source Selection The logic allows the user to decide which part of the price candle the average should be based on. You can choose to calculate the average based on the Close, Open, High, or Low prices. This flexibility is crucial for traders who may prefer focusing on volatility (Highs/Lows) versus actual completed transactions (Close).
3. Real-Time Visual Reporting Beyond just drawing a line on the chart, the script includes an automated labeling system. It identifies the current value of the Moving Average and displays it directly on the screen in a clean, readable font. This label updates instantly as new price data arrives, showing:
- The specific type of average being used (e.g., SMA, EMA).
- The timeframe period selected.
- The specific price source (represented by letters like C, O, H, or L).
- The exact numerical value of the current average.
User Experience Summary
For a non-technical user, this script acts as an intelligent "trend assistant." You can customize how sensitive the line is (the Period), how far it sits from the current price (the Shift), and what color it appears as on your screen. It automates the heavy math of technical analysis, providing a steady visual guide and instant numerical feedback to help you make informed decisions about market momentum.
//+------------------------------------------------------------------+
//| Custom Moving Average.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 1
//#property indicator_color1 Red
//---- indicator parameters
extern int MA_Period=13;
extern int MA_Shift=0;
extern int MA_Method=0;
extern int MA_Applied=0;
extern int Fontsize=10;
extern color Color_1 = Red;
//---- indicator buffers
double ExtMapBuffer[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
int draw_begin;
string short_name;
SetIndexStyle(0,DRAW_LINE,EMPTY,EMPTY,Color_1);
SetIndexShift(0,MA_Shift);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
if(MA_Period<2) MA_Period=13;
draw_begin=MA_Period-1;
switch(MA_Method)
{
case 1 : short_name="EMA("; draw_begin=0; break;
case 2 : short_name="SMMA("; break;
case 3 : short_name="LWMA("; break;
default :
MA_Method=0;
short_name="SMA(";
}
IndicatorShortName(short_name+MA_Period+")");
SetIndexDrawBegin(0,draw_begin);
SetIndexBuffer(0,ExtMapBuffer);
return(0);
}
int start()
{
int limit;
string short_name;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
ExtMapBuffer[i]=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,MA_Applied,i);
switch(MA_Method)
{
case 0 : short_name="SMA("; break;
case 1 : short_name="EMA("; break;
case 2 : short_name="SMMA("; break;
case 3 : short_name="LWMA(";
}
double ma_1;
ma_1=iMA(0,0,MA_Period,MA_Shift,MA_Method,MA_Applied,0);
ObjectDelete("MA"+MA_Period);
ObjectCreate("MA"+MA_Period ,OBJ_TEXT, 0, Time[0], ma_1+0.0010);
ObjectSetText("MA"+MA_Period," "+short_name+ MA_Period+") "+GetMethodText(MA_Applied)+" "+ (DoubleToStr(ma_1,Digits)) ,Fontsize, "MS Sans Serif", Color_1);
return(0);
}
string GetMethodText(int MA_Applied)
{
switch(MA_Applied)
{case 0: return("C"); break; // Close
case 1: return("O"); break; // Open
case 2: return("H"); break; // High
case 3: return("L"); break; } // Low
}
Comments