Features of the mql5 language, subtleties and tricks - page 104

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
How many instruments in the market review?
61.
In build 1907 the bugs miraculously disappeared. I don't even know whether to roll back to find them, or something in this place was just fixed...
Question about building indicators
#property indicator_chart_window
#property indicator_buffers 12
#property indicator_plots 6
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_type6 DRAW_COLOR_LINE
SetIndexBuffer(0,upper_line,INDICATOR_DATA);
SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX);
PlotIndexSetString(0,PLOT_LABEL,"Upper Line");
PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);
// ==========
SetIndexBuffer(2,awera_line,INDICATOR_DATA);
SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX);
PlotIndexSetString(1,PLOT_LABEL,"Average Line");
PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle);
PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth);
PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw);
// ==========
SetIndexBuffer(4,lower_line,INDICATOR_DATA);
SetIndexBuffer(5,lower_line_color,INDICATOR_COLOR_INDEX);
PlotIndexSetString(2,PLOT_LABEL,"Lower Line");
PlotIndexSetInteger(2,PLOT_LINE_STYLE,LowerStyle);
PlotIndexSetInteger(2,PLOT_LINE_WIDTH,LowerWidth);
PlotIndexSetInteger(2,PLOT_COLOR_INDEXES,2);
PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,LowerTrendUp);
PlotIndexSetInteger(2,PLOT_LINE_COLOR,1,LowerTrendDw);
How many color buffers can be used?
How are the buffers linked to each other?
#property indicator_buffers 12 // Declare a total of 12 buffers
#property indicator_plots 6 // Graphical constructions
Do I understand correctly, that specifying indicator_type 1 through 6 the indicator will understand that color lines should be drawn for 6 graphical constructions ?
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_type6 DRAW_COLOR_LINE
// =====
SetIndexBuffer(0,upper_line,INDICATOR_DATA); // First buffer for data
SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // Second buffer for color data
PlotIndexSetString(0,PLOT_LABEL, "Upper Line"); // Change the properties of the first buffer
PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);// change the properties of the first buffer
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);// change properties of the first buffer
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);// change properties of the first buffer
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);//changing the properties of the first buffer
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);//change properties of the first buffer
SetIndexBuffer(2,awera_line,INDICATOR_DATA); // The third buffer
SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX); // The fourth color buffer
PlotIndexSetString(1,PLOT_LABEL, "Average Line"); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
Question about building indicators
#property indicator_chart_window
#property indicator_buffers 12
#property indicator_plots 6
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_type6 DRAW_COLOR_LINE
SetIndexBuffer(0,upper_line,INDICATOR_DATA);
SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX);
PlotIndexSetString(0,PLOT_LABEL,"Upper Line");
PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);
// ==========
SetIndexBuffer(2,awera_line,INDICATOR_DATA);
SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX);
PlotIndexSetString(1,PLOT_LABEL,"Average Line");
PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle);
PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth);
PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw);
// ==========
SetIndexBuffer(4,lower_line,INDICATOR_DATA);
SetIndexBuffer(5,lower_line_color,INDICATOR_COLOR_INDEX);
PlotIndexSetString(2,PLOT_LABEL,"Lower Line");
PlotIndexSetInteger(2,PLOT_LINE_STYLE,LowerStyle);
PlotIndexSetInteger(2,PLOT_LINE_WIDTH,LowerWidth);
PlotIndexSetInteger(2,PLOT_COLOR_INDEXES,2);
PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,LowerTrendUp);
PlotIndexSetInteger(2,PLOT_LINE_COLOR,1,LowerTrendDw);
How many color buffers can be used?
How are the buffers linked to each other?
#property indicator_buffers 12 // Declare a total of 12 buffers
#property indicator_plots 6 // Graphical constructions
Do I understand correctly, that specifying indicator_type 1 through 6 the indicator will understand that color lines should be drawn for 6 graphical constructions ?
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_type6 DRAW_COLOR_LINE
// =====
SetIndexBuffer(0,upper_line,INDICATOR_DATA); // First buffer for data
SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // Second buffer for color data
PlotIndexSetString(0,PLOT_LABEL, "Upper Line"); // Change the properties of the first buffer
PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);// change the properties of the first buffer
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);// change properties of the first buffer
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);// change properties of the first buffer
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);//changing the properties of the first buffer
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);//change properties of the first buffer
SetIndexBuffer(2,awera_line,INDICATOR_DATA); // The third buffer
SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX); // The fourth color buffer
PlotIndexSetString(1,PLOT_LABEL, "Average Line"); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // Change the buffer properties for SetIndexBuffer(2,awera_line,INDICATOR_DATA);
You'd better create a separate branch for your question. This branch is about specifics, there shouldn't be any discussions here.
To better understand the principle of building, implement the functionality incrementally. You have built one line, check its functionality, add the next one.
Each graphical series (in this case a color line) can have only one color buffer. Each buffer can contain many colors.
In the 1907 build, the bugs have miraculously disappeared. I don't even know whether to roll back to find them, or something in this place just fixed...
The errors disappeared, but the problems with the event queue did not. After a few hours of work the terminal starts to load the CPU up to 95%. And something tells me that the ticks are skipped.
@Slava, did something change in ChartEvent in the 19xx builds? Does your problem reproduce itself?
The errors disappeared, but the problems with the event queue did not. After a few hours the terminal starts to load the CPU at 95%. And something tells me that the ticks are missing.
@Slava, did something change in ChartEvent in the 19xx builds? Is your problem reproduced?
This is how the resource monitoring looks like after 15 hours of terminal's work (the minimum frequency of spy's event sending is 500 ms):
Although CPU load is close to 0 for several hours after startup.
This is what the resource monitoring looks like after 15 hours of operation of the terminal (the minimum event rate of the spy is 500 ms):
Although CPU load is close to 0 for a few hours after startup.
Bild 1908 - no change.
The ability to replace the operators of structures of the basic type allows you to be flexible in some situations.
As an example, below is one technique for custom sorting an array of structures
Result
This is probably an ancient bicycle.
The ability to replace operators of structures of basic type allows flexibility in some situations.
there are a few points. in mql, the < operator must necessarily be a method of class/structure.
This means that it cannot be set for embedded structures, or for immutable ones.
This way can be improved a bit by adding a template comparison function, which will by default call the < operator
UPD: I write < operator everywhere because they usually overload it instead of >, it's not strict, but it's generally acceptedthere are a few points. in mql, the < operator must necessarily be a method of the class/structure.
This means that it cannot be set for embedded structures. Or for immutable structures.
Result
This way can be improved a bit by adding a template comparison function, which will by default call the < operator
If you use typedef, then you need to define a sort function not only for structures, but also for standard numeric types. Or I don't understand what we're talking about.