Test_ADXWOnArray

Author: Integer

Here's a breakdown of what this MetaTrader script does, explained in a way that's easy to understand without any technical programming knowledge:

This script is designed to display information about the market using a technical indicator called the Average Directional Index, or ADX. Think of it as a tool that helps traders understand how strong a trend is in the market (whether the price is consistently going up or down, or just moving sideways).

Here?s how the script works:

  1. It Sets Up The Basics: It begins by setting up essential information, like the author, a link to their profile, and a version number. It defines that this script will show its output in a separate window, not directly on the price chart. Also, it defines names for the lines that will be plotted.

  2. Defines Visual Elements: The script defines three lines to be plotted:

    • Label1, which will be Lime color. This will represent the ADX itself.
    • Label2, which will be Blue. This will represent the Positive Directional Indicator (+DI).
    • Label3, which will be Red. This will represent the Negative Directional Indicator (-DI).
  3. Input Parameters: It allows the user to customize two key settings:

    • ADX Period: This is the number of past price periods the script uses to calculate the ADX. A longer period makes the ADX smoother, while a shorter one makes it more responsive to recent price changes. Think of this as looking back a certain number of days/weeks/months when calculating the indicator. The default is 14.

    • ADX Method: This determines which type of average is used in the calculations. The default is "SMMA," which is a type of smoothing average.

  4. Data Storage: The script creates several "buckets" (called buffers) to store various data. These buckets hold things like the ADX values, the Positive Directional Indicator (+DI), the Negative Directional Indicator (-DI), price data (high, low, close), and some intermediate calculations.

  5. Initialization (OnInit): This section prepares the script for action. It links the data "buckets" (the buffers) to the ADX indicator calculation. This makes sure that the calculated results will be stored in the correct place, and that the indicator knows which price data to use. It also sets initial labels for the information it plots.

  6. Calculation (OnCalculate): This is the heart of the script, where the actual calculations take place. It does the following for each new price bar that appears on the chart:

    • Data Prep: It takes the current high, low, and closing prices and stores them in its internal "buckets."

    • ADX Calculation: It uses an external include (IncADXWOnArray.mqh) to perform all the complex math for calculating the ADX, +DI, and -DI. This include contains a set of instructions that calculates the values of the indicators based on the price data.

    • Result Storage: The calculated ADX, +DI, and -DI values are stored in their respective "buckets," making them ready for display.

  7. Plotting: The script automatically plots the calculated ADX, +DI, and -DI lines on the chart. These lines visually represent the strength and direction of the trend.

In essence, this script acts as a display for the ADX indicator and related components. The script uses historical prices to perform calculations and present the findings through 3 colored lines. Traders can then use these lines to asses the trend.

3 Views
0 Downloads
0 Favorites
Test_ADXWOnArray
//+------------------------------------------------------------------+
//                                              Test_ADXWOnArray.mq5 |
//|                                                          Integer |
//|                          https://login.mql5.com/en/users/Integer |
//+------------------------------------------------------------------+
#property copyright "Integer"
#property link      "https://login.mql5.com/en/users/Integer"
#property version   "1.00"
//--- 
#property indicator_separate_window
#property indicator_buffers 11
#property indicator_plots   3
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLime
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Label3
#property indicator_label3  "Label3"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrRed
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- indicator input parameters
input int            ADXPeriod  =  14;
input ENUM_MA_METHOD ADXMethod  =  MODE_SMMA;

//--- indicator buffers
double         ADXBuffer[];
double         PDIBuffer[];
double         MDIBuffer[];

double         PBuffer[];
double         MBuffer[];
double         ADXRBuffer[];

double         TRBuffer[];
double         ATRBuffer[];

double         DataClose[];
double         DataHigh[];
double         DataLow[];

#include <IncOnArray/IncADXWOnArray.mqh>
CADXWOnArray adx;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   adx.Init(ADXPeriod,ADXMethod);

//--- indicator buffers mapping
   SetIndexBuffer(0,ADXBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,PDIBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,MDIBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,PBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(4,MBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,ADXRBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(6,TRBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(7,ATRBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(8,DataClose,INDICATOR_CALCULATIONS);
   SetIndexBuffer(9,DataHigh,INDICATOR_CALCULATIONS);
   SetIndexBuffer(10,DataLow,INDICATOR_CALCULATIONS);

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,adx.BarsRequiredADX());
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,adx.BarsRequiredPDIMDI());
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,adx.BarsRequiredPDIMDI());

   PlotIndexSetString(0,PLOT_LABEL,adx.Name());
   PlotIndexSetString(1,PLOT_LABEL,adx.PDIName());
   PlotIndexSetString(2,PLOT_LABEL,adx.MDIName());
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int start;
   if(prev_calculated>0)
     {
      start=prev_calculated-1;
     }
   else
     {
      start=0;
     }
   for(int i=start;i<rates_total;i++)
     {
      DataClose[i]=close[i];
      DataHigh[i]=high[i];
      DataLow[i]=low[i];
     }

   adx.Solve(rates_total,prev_calculated,DataClose,DataHigh,DataLow,PBuffer,MBuffer,TRBuffer,ATRBuffer,PBuffer,MBuffer,PDIBuffer,MDIBuffer,ADXRBuffer,ADXBuffer);

   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments