!SupportingMACD

Author: Copyright � 2004, MetaQuotes Software Corp.
!SupportingMACD

Here's a breakdown of what this MetaTrader script does in simple terms:

This script is designed to display a popular trading indicator called the MACD (Moving Average Convergence Divergence) on a chart in MetaTrader. The MACD helps traders identify potential buying and selling opportunities by analyzing price trends.

Here's how it works:

  1. Configuration: The script starts by allowing the user to customize three key settings:

    • FastEMA: This sets the period for a faster-moving average.
    • SlowEMA: This sets the period for a slower-moving average.
    • SignalSMA: This sets the period for another moving average, used as a "signal line".
  2. Calculation: The script performs the following calculations for each price bar on the chart:

    • It calculates two Exponential Moving Averages (EMAs) of the closing prices. One EMA uses the "FastEMA" setting, and the other uses the "SlowEMA" setting. The EMA is a type of average that gives more weight to recent prices.
    • It subtracts the "SlowEMA" value from the "FastEMA" value. The result is the MACD line.
  3. Signal Line: To create the signal line:

    • It calculates another moving average (this time a Simple Moving Average or SMA) of the MACD line itself, using the "SignalSMA" setting.
  4. Display: Finally, the script displays two things on a separate window in the chart:

    • A histogram representing the MACD line (the difference between the two EMAs).
    • A line representing the "signal line" (the moving average of the MACD).

In essence, the script automates the complex calculations needed to display the MACD indicator and its signal line. Traders then use these lines and their relationship to identify potential trend changes and trading signals. For instance, crossovers of the MACD line and the signal line are often interpreted as potential buy or sell signals.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
4 Views
0 Downloads
0 Favorites
!SupportingMACD
/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Red

extern int FastEMA = 12;
extern int SlowEMA = 26;
extern int SignalSMA = 9;
double g_ibuf_88[];
double g_ibuf_92[];

int init() {
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexDrawBegin(1, SignalSMA);
   IndicatorDigits(Digits + 1);
   SetIndexBuffer(0, g_ibuf_88);
   SetIndexBuffer(1, g_ibuf_92);
   IndicatorShortName("MACD1(" + FastEMA + "," + SlowEMA + "," + SignalSMA + ")");
   SetIndexLabel(0, "MACD");
   SetIndexLabel(1, "Signal");
   return (0);
}

int start() {
   int li_4 = IndicatorCounted();
   if (li_4 > 0) li_4--;
   int li_0 = Bars - li_4;
   for (int li_8 = 0; li_8 < li_0; li_8++) g_ibuf_88[li_8] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, li_8) - iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, li_8);
   for (li_8 = 0; li_8 < li_0; li_8++) g_ibuf_92[li_8] = iMAOnArray(g_ibuf_88, Bars, SignalSMA, 0, MODE_EMA, li_8);
   return (0);
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---