Professional Documents
Culture Documents
Drawing Indicator's Emissions in MQL5
Drawing Indicator's Emissions in MQL5
METATRADER 5 — EXAMPLES
6 7 030
SERGEY PAVLOV
Introduction
Certainly, many traders and developers of trading strategies are interested in these questions:
Finding the answers for these questions led me to creation of a new approach to the market research: construction and analysis of indicator emissions. To make it clearer, take a look at the
following figures:
It shows the emission from different indicators, but the principle of their construction is the same. More and more points with different color and shape appear after the each tick. They form
numerous clusters in the forms of nebulae, clouds, tracks, lines, arcs, etc. These shapes can help to detect the invisible springs and forces that affect the movement of market prices. The
research and analysis of these emissions are something like chiromancy.
The emission is a set of points, located at the intersection points of specific lines of the indicator.
The properties of emissions haven't been still clear yet, they are still waiting for the researchers. Here is a list of known properties:
This website uses cookies. Learn more about our Cookies Policy.
https://www.mql5.com/en/articles/26 1/8
5/1/2020 Drawing Indicator's Emissions in MQL5 - MQL5 Articles
We need an Expert Advisor to create emission points. It's better to use the MQL5 Wizard to create an Expert Advisor template.
//+------------------------------------------------------------------+
//| Emission of Bands && MA.mq5 |
//| Copyright DC2008 |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "DC2008"
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
First, we need some auxiliary plottings. We need to continue indicator lines using rays (Fig. 5.). It will allow to control the correctness of calculation and visualization of emission points. Later,
we will remove these lines from the chart.
This website uses cookies. Learn more about our Cookies Policy.
https://www.mql5.com/en/articles/26 2/8
5/1/2020 Drawing Indicator's Emissions in MQL5 - MQL5 Articles
Thus, let's add the graphic objects (horizontal and trend lines) to the code of our Expert Advisor.
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- filling the arrays with current values
CopyBuffer(MAHandle,0,0,2,MA);
ArraySetAsSeries(MA,true);
CopyBuffer(BBHandle,0,0,2,BBM);
This website uses cookies. Learn more about our Cookies Policy.
ArraySetAsSeries(BBM,true);
https://www.mql5.com/en/articles/26 3/8
5/1/2020 Drawing Indicator's Emissions in MQL5 - MQL5 Articles
CopyBuffer(BBHandle,1,0,2,BBH);
ArraySetAsSeries(BBH,true);
CopyBuffer(BBHandle,2,0,2,BBL);
ArraySetAsSeries(BBL,true);
CopyTime(Symbol(),0,0,10,T);
ArraySetAsSeries(T,true);
Since the emission continues to the past and to the future, the trend line properties should be following:
As a result, the chart with additional lines will look as presented in Fig. 6.
The preparatory phase is completed, now let's proceed to the emission. We are going to create the first series of points at the intersection of the following lines:
between the "MA" (iMA) line and "BH" line (iBands = UPPER_BAND);
between the "MA" (iMA) line and "BL" line (iBands = LOWER_BAND);
between the "MA" (iMA) line and "BM" line (iBands = BASE_BAND).
Fig. 6. Auxiliary plottings. Continuation of the indicator's lines using straight lines.
Now it's time to calculate the coordinates of intersection and to draw the points of the emission. Let's create the function:
void Draw_Point(
string P_name, // Object name (OBJ_ARROW)
double P_y1, // Y-coordinate of the 1st line at the [1] bar
double P_y0, // Y-coordinate of the 1st line at the [0] bar
double P_yy1, // Y-coordinate of the 2nd line at the [1] bar
double P_yy0, // Y-coordinate of the 2nd line at the [0] bar
char P_code1, // Char at the right side of the [0] bar
char P_code2, // Char at the left side of the [0] bar
color P_color1, // Color of point at the right side of the [0] bar
color P_color2 // color of point at the left side of the [0] bar
)
{
double P,X;
datetime P_time;
if(MathAbs((P_yy0-P_yy1)-(P_y0-P_y1))>0)
{
P=P_y1+(P_y0-P_y1)*(P_y1-P_yy1)/((P_yy0-P_yy1)-(P_y0-P_y1));
X=(P_y1-P_yy1)/((P_yy0-P_yy1)-(P_y0-P_y1));
if(X>draw_period)
{
P_time=T[0]+(int)(X*PeriodSeconds());
ObjectCreate(0,P_name,OBJ_ARROW,0,0,0);
ObjectSetDouble(0,P_name,OBJPROP_PRICE,P);
ObjectSetInteger(0,P_name,OBJPROP_TIME,P_time);
ObjectSetInteger(0,P_name,OBJPROP_WIDTH,0);
ObjectSetInteger(0,P_name,OBJPROP_ARROWCODE,P_code1);
ObjectSetInteger(0,P_name,OBJPROP_COLOR,P_color1);
if(X<0)
{
ObjectSetInteger(0,P_name,OBJPROP_ARROWCODE,P_code2);
ObjectSetInteger(0,P_name,OBJPROP_COLOR,P_color2);
}
}
}
}
//+------------------------------------------------------------------+
int GTC=GetTickCount(); This website uses cookies. Learn more about our Cookies Policy.
https://www.mql5.com/en/articles/26 4/8
5/1/2020 Drawing Indicator's Emissions in MQL5 - MQL5 Articles
//+------------------------------------------------------------------+
name="H"+(string)GTC;
Draw_Point(name,BBH[1],BBH[0],MA[1],MA[0],170,178,Red,Red);
name="L"+(string)GTC;
Draw_Point(name,BBL[1],BBL[0],MA[1],MA[0],170,178,Blue,Blue);
name="M"+(string)GTC;
Draw_Point(name,BBM[1],BBM[0],MA[1],MA[0],170,178,Green,Green);
//---
ChartRedraw(0);
Now let's run the Expert Advisor and look at the result (Fig. 7.).
It's good, but there are some other intersection cases, that we haven't considered. For example, the iBands indicator has three lines that intersect each other and can complement the overall
picture.
Now, let's try to add another one series of point to the calculated emission, the intersection between the following lines:
between the line "BH" (iBands = UPPER_BAND) and line "BL" (iBands = LOWER_BAND);
between the line "BH" (iBands = UPPER_BAND) and line "BM" (iBands = BASE_BAND);
between the line "BL" (iBands = LOWER_BAND) and line "BM" (iBands = BASE_BAND).
Due to these intersections, we would get 3 points, but all they will have the same coordinates. Therefore, it's sufficient to use an only one intersection, between the line "BH" and line "BL".
Let's add these lines of code to our Expert Advisor, and take a look at the result (Fig. 8.).
name="B"+(string)GTC;
Draw_Point(name,BBH[1],BBH[0],BBL[1],BBL[0],170,178,Magenta,Magenta);
So, we have got the emission, but there is a feeling that we have missed something important. Nevertheless, what we have missed?
Why we have used just such input parameters? What we will get if we change them? And anyway, what is their role in the emissions?
All right, the emission we've got corresponds to a single frequency, resulted from the input parameters of the indicator. To calculate the full multi-frequency spectrum, it's necessary to perform
the same calculations for other frequencies. As an example, here is my version of the possible emission spectrum:
https://www.mql5.com/en/articles/26 5/8
5/1/2020 Drawing Indicator's Emissions in MQL5 - MQL5 Articles
//---
return(0);
}
To consider all possible combinations, let's add the following code to the Expert Advisor:
//+------------------------------------------------------------------+
CopyTime(NULL,0,0,10,T);
ArraySetAsSeries(T,true);
int GTC=GetTickCount();
//+------------------------------------------------------------------+
int iMax=ArraySize(BBHandle)-1;
int jMax=ArraySize(MAHandle)-1;
for(int i=0; i<iMax; i++)
{
for(int j=0; j<jMax; j++)
{
//--- filling the arrays with current values
CopyBuffer(MAHandle[j],0,0,2,MA);
ArraySetAsSeries(MA,true);
CopyBuffer(BBHandle[i],0,0,2,BBM);
ArraySetAsSeries(BBM,true);
CopyBuffer(BBHandle[i],1,0,2,BBH);
ArraySetAsSeries(BBH,true);
CopyBuffer(BBHandle[i],2,0,2,BBL);
ArraySetAsSeries(BBL,true);
name="H"+(string)GTC+(string)i+(string)j;
Draw_Point(name,BBH[1],BBH[0],MA[1],MA[0],250,158,Aqua,Aqua);
name="L"+(string)GTC+(string)i+(string)j;
Draw_Point(name,BBL[1],BBL[0],MA[1],MA[0],250,158,Blue,Blue);
name="M"+(string)GTC+(string)i+(string)j;
Draw_Point(name,BBM[1],BBM[0],MA[1],MA[0],250,158,Green,Green);
name="B"+(string)GTC+(string)i+(string)j;
Draw_Point(name,BBH[1],BBH[0],BBL[1],BBL[0],250,158,Magenta,Magenta);
}
}
//---
ChartRedraw(0);
The more frequencies is involved in the emission spectrum, the better picture will be on chart, but you should not abuse it - it's a simplest way to exhaust the computer resources, and to get
the chaos on the chart. The number of frequencies can be determined experimentally. For the better perception of graphics, we must pay special attention to the drawing style.
1. Each person has his own perception of graphic images, so you'll need some time to customize the emissions.
2. The "chaos" in Fig.9. doesn't allow to recognize any regularities or patterns in images. It's an example of bad drawing.
3. Try to use the neighbor colors in the rainbow spectrum.
4. The character codes for the past (from the left side of [0] bar) and for the future (from the right side of [0] bar) should differ.
5. The successful combination of colors and shapes of points is able to turn the emission into the masterpieces, which will not only help in the trade, but will also pleasure your eyes.
As an example, here is my version of drawing style for the emission (see Figures 10-17):
name="H"+(string)GTC+(string)i+(string)j;
Draw_Point(name,BBH[1],BBH[0],MA[1],MA[0],250,158,Aqua,Aqua);
name="L"+(string)GTC+(string)i+(string)j;
Draw_Point(name,BBL[1],BBL[0],MA[1],MA[0],250,158,Blue,Blue);
name="M"+(string)GTC+(string)i+(string)j;
Draw_Point(name,BBM[1],BBM[0],MA[1],MA[0],250,158,Magenta,Magenta);
name="B"+(string)GTC+(string)i+(string)j;
Draw_Point(name,BBH[1],BBH[0],BBL[1],BBL[0],250,158,DarkOrchid,DarkOrchid);
Fig. 10.
This website uses cookies. Learn more about our Cookies Policy.
https://www.mql5.com/en/articles/26 6/8
5/1/2020 Drawing Indicator's Emissions in MQL5 - MQL5 Articles
Fig. 11
Fig. 12.
Fig. 13.
Fig. 14.
Fig. 15.
This website uses cookies. Learn more about our Cookies Policy.
https://www.mql5.com/en/articles/26 7/8
5/1/2020 Drawing Indicator's Emissions in MQL5 - MQL5 Articles
Fig. 16.
Fig. 17.
Emission Analysis
The analysis of emissions is a separate task. The most useful thing is to look at its dynamics in a real time, it's the best way to understand many effects and patterns.
Pay attention to the price corrections - it seems that the emission "knows" the target price. In addition, you can see the support, resistance and equilibrium price levels.
Conclusion
1. The emissions of the indicators might be interesting to traders and trade systems developers, who are looking for new approaches in market research and analysis.
2. As an introductory article, it doesn't contain the ready solutions. However, the presented technology for emission calculation can be applied in other indicators or their combinations.
3. Preparing this article, I have collected more questions than answers. Here are some of them: how to optimize the algorithm of emission drawing; what is the role of the emission
spectrum characteristics in the structure of emission; how to use the emissions in automated trading?
Warning: All rights to these materials are reserved by MetaQuotes Ltd. Copying or reprinting of these materials in whole or in part is prohibited.
This website uses cookies. Learn more about our Cookies Policy.
https://www.mql5.com/en/articles/26 8/8