Join our fan page
Vertical histograms constructor - library for MetaTrader 5
- Views:
- 7238
- Rating:
- Published:
- 2017.01.18 09:25
- Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
A histogram is a bar chart of frequencies. One of the axes represents variable values, while another — the frequency of these values' occurrence. The height of each bar shows the frequency (number) of values belonging to the respective interval equal to the column width. Such diagrams are usually displayed horizontally, i.e. variable values are located on a horizontal axis, while frequency — on a vertical one.
In this library, we will focus on the vertical histograms of the order statistics: price values of the analyzed parameters are to be located on the vertical axis in ascending order, while frequency is to be located on the horizontal axis. Incoming price data are distributed and grouped on the current bar and can be displayed relative to its axis from the left, right or both sides simultaneously.
Fig. 1. Vertical histogram of Bid and Ask prices distribution.
Constructor of vertical histograms is based on the CHistogram class. Implementation of all its methods are based on the use of so-called "graphic" memory.
Method: class constructor CHistogram.
Initializes an instance of the class.
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] The unique name prefix for the columns of the histogram.
hsize
[in] The scale of the histogram display.
width
[in] The width of the histogram line bars
active
[in] The color of the histogram columns updated on the current bar.
passive
[in] The color of the histogram columns not updated on the current bar.
Left_Right=true
[in] The direction of the histogram display. false — histogram to the left of the current bar, true — to the right.
relative_frequency=false
[in] The method of accounting the frequency values. false — absolute frequency values, true — relative frequency values.
sub_win=0
[in] The index of the window for plotting the histogram. 0 — main chart window.
Returned value:
No return value. If successful, it creates an instance of the class with the specified parameters.
Method: histogram display DrawHistogram.
Displays the histogram bars: creates new bars; edits existing bars; stores the frequency values to the graphic memory; displays the histogram on the current bar.
double price, // value of the variant
datetime time // time of the current bar
);
Parameters:
price
[in] Value of the variant of the studied market characteristics.
time
[in] Time of the current bar. This bar will be the histogram axis.
Returned value:
No return value. If successful, creates new or adjusts existing histogram column. If a new bar appeared, the histogram is shifted so that the axis is on the current bar.
Method: calculation of the histogram characteristics HistogramCharacteristics.
Returns the calculated characteristics of the order statistic in a variable of type sVseries.
Parameters:
No input parameters.
Returned value:
If successful, it returns the value of a variable of type sVseries.
Structure for getting the current values of the histogram characteristics (sVseries).
Structure for storing past values of the characteristics of the statistical distribution. Designed for getting the most demanded information on the order statistic.
{
long N; // total number of observations
double Na; // average value of frequencies
double Vmax; // maximum value of the variant
double Vmin; // minimum value of the variant
double A; // amplitude of the order statistic
double Mean; // weighted arithmetic mean
double D; // variance
double SD; // standard deviation
};
Method: visualization of the mean value DrawMean.
Displays the value of the weighted arithmetic mean of order statistic on the chart.
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] The value of the weighted arithmetic mean.
time
[in] Time of the current bar. The value of the weighted arithmetic mean will be measured on this bar.
marker=false
[in] Display marker on the chart or not. false — marker is not displayed, true — marker is displayed on the chart.
save=false
[in] Store the value of the weighted arithmetic mean to history. false — do not display, true — display the value on the chart.
Returned value:
If successful, a horizontal line is displayed on the chart, which corresponds to the value of the weighted arithmetic mean.
Method: visualization of the standard deviation DrawSD.
Displays the value of standard deviation as a rectangle. The rectangle width matches the average frequency and its height matches the standard deviation plotted up and down of the weighted arithmetic mean value.
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] The value of a variable of type sVseries.
time
[in] Time of the current bar.
deviation=1.0
[in] Coefficient to increase the value of the standard deviation.
clr=clrYellow
[in] Color of the rectangle that visualizes the standard deviation.
Returned value:
If successful, displays a rectangle on the chart, which characterizes the standard deviation from the value of the weighted arithmetic mean.
Capabilities of the class are demonstrated in the video. Code of the test sample is provided in the attachment.
The provided code shows how to call a particular method (function) of the class.
Tips:
- It is better to use the class on the smaller timeframes.
Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/16365
The Exp_AFL_WinnerV2 Expert Advisor that uses the AFL_WinnerV2 indicator.
AFL_WinnerV2_HTFThe AFL_WinnerV2 indicator with the timeframe selection option available in input parameters.
The indicator implements a breakout system using a channel based on the High and Low price series processed by the algorithm of JSatl_Digit.
Exp_JSatl_Digit_SystemTrading system based on the signals of the JSatl_Digit_System indicator.