Vertical Histograms Constructor
Info
The Vertical Histograms Constructor is a Library for MetaTrader 5 that a histogram is a bar chart of frequencies. One axis represents variable values, while the other axis represents the frequency of these values' occurrence.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Vertical Histograms Constructor
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
What this tool does
A histogram is a bar chart of frequencies.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: check for market open hours - another powerful library for MetaTrader 5 traders.
A histogram is a bar chart of frequencies. One axis represents variable values, while the other axis represents the frequency of these values' occurrence. The height of each bar indicates the frequency (number) of values belonging to the respective interval, which is equal to the column width.Also recommended: Array String String - similar library with strong performance on MetaTrader 5.
This library focuses on vertical histograms of order statistics: price values of the analyzed parameters are displayed on the vertical axis in ascending order, and frequency is shown on the horizontal axis. Incoming price data is distributed and grouped on the current bar and can be presented relative to its axis from the left, right, or both sides simultaneously.
Fig. 1. Vertical histogram of bid and ask prices distribution.
The vertical histograms constructor is based on the chistogram class. All its methods are implemented using 'graphic' memory.
Method: Class Constructor chistogram
Initializes an instance of the class.
void chistogram( string name, // unique name prefix int hsize, // chart scale int width, // width of the histogram line bars color active, // color of the active line bars color passive, // color of the passive line bars bool left_right=true, // left=false or right=true bool relative_frequency=false, // relative or absolute histogram int sub_win=0 // index of the window for plotting histogram );
Parameters:
name
[in] Unique name prefix for the histogram columns.
hsize
[in] Scale of the histogram display.
width
[in] Width of the histogram line bars.
active
[in] Color of the histogram columns updated on the current bar.
passive
[in] Color of the histogram columns not updated on the current bar.
left_right=true
[in] Direction of the histogram display. False for left, true for right.
relative_frequency=false
[in] Frequency value method. False for absolute, true for relative.
sub_win=0
[in] Index of the window for plotting the histogram. 0 for the main chart window.
Returned Value:
No return value. Creates an instance of the class with the specified parameters on success.
Method: Histogram Display drawhistogram
Displays the histogram bars: creates new bars, edits existing bars, stores frequency values in graphic memory, and presents the histogram on the current bar.
void drawhistogram( double price, // value of the variant datetime time // time of the current bar );
Parameters:
price
[in] Value of the studied market characteristic variant.
time
[in] Time of the current bar, which will be the histogram axis.
Returned Value:
No return value. Creates or adjusts histogram columns on success. Shifts the histogram if a new bar appears.
Method: Calculation of Histogram Characteristics histogramcharacteristics
Returns the calculated order statistic characteristics in an svseries variable.
svseries histogramcharacteristics();
Parameters:
No input parameters.
Returned Value:
Returns an svseries variable on success.
Structure for obtaining current histogram characteristics (svseries).
Structure for storing past values of statistical distribution characteristics. Designed to access the most demanded order statistic information.
The svseries type variable provides all main order statistic characteristics displayed as a histogram through a single call to the histogramcharacteristics() function.
Method: Visualization of the Mean Value drawmean
Displays the weighted arithmetic mean of the order statistic on the chart.
void drawmean( double coord, // value of the weighted arithmetic mean datetime time, // time of the current bar bool marker=false,// display the marker or not bool save=false // store the value to history or not );
Parameters:
coord
[in] Value of the weighted arithmetic mean.
time
[in] Time of the current bar, where the mean value is measured.
marker=false
[in] Display marker on the chart. False for no marker, true for marker display.
save=false
[in] Store the weighted arithmetic mean value in history. False for no display, true for display.
Returned Value:
Displays a horizontal line representing the weighted arithmetic mean on success.
Method: Visualization of the Standard Deviation drawsd
Displays the standard deviation as a rectangle. The rectangle width matches the average frequency, and its height represents the standard deviation plotted above and below the weighted arithmetic mean.
void drawsd( svseries &coord, // variable of type svseries datetime time, // time of the current bar double deviation=1.0, // deviation color clr=clryellow // display color );
Parameters:
coord
[in] Value of the svseries variable.
time
[in] Time of the current bar.
deviation=1.0
[in] Coefficient to scale the standard deviation.
clr=clryellow
[in] Color of the rectangle visualizing the standard deviation.
Returned Value:
Displays a rectangle characterizing the standard deviation from the weighted arithmetic mean on success.
The class capabilities are demonstrated in the video, and the test sample code is provided in the attachment. The code illustrates how to call specific class methods.
Tips:
- The class is best utilized on smaller timeframes.
You may also like: cdatetime msc - excellent alternative for library users on MetaTrader 5.
Source Code
/
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.