Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1934

 
Ivan Butko #:

Artyom, I probably didn't quite understand, maybe I asked the question wrongly:

There are three (four, five...) man-made objects (ObjectCreate). The first one hides behind the third one, the second one is in the foreground,. How to set one to foreground, second to second, third to background. So that the first object is always visible, the second one is always visible but not behind the first one. The third object is also always visible, but not behind the first and the second. A kind of alternating plan.
I just didn't quite understand about the TF.

Take turns doing as described above for each of your objects. The alternation will affect the layout. The very last one to which this action will be applied will be the topmost one.

Once you have determined that any graphical object that should be below your objects has appeared on the graph, alternately do a hiding-display for each of your objects (as I wrote above). This action brings the object to the foreground of the graphic. Your first object to which this action was applied will be at the bottom (but above any other graphical object drawn on the chart after your objects have been created), the second will be above the first, the third will be above the first and second, and so on. All objects that have been hid-overed will be above the rest of the graphical objects.

That is, the order in which the hiding-objects are applied to your objects sets their order above each other. But they will all appear above everything else on the graph.

The logic is this:

If any graphical object appears on the graph that shouldn't overlap your objects, you do a hiding-display for each of your objects in the order in which they should visually appear (first at the very bottom, last at the very top). After hiding-displaying all your objects do ChartRedraw().
This is important - redraw the chart only after all your objects have been hidden-displayed, so that visually there is no flickering on the chart.

 
Artyom Trishkin #:

Take it in turns to do as described above for each of your properties. The rotation will affect the positioning. The most recent object to which this action is applied will be the uppermost.

Once you have determined that any graphical object that should be below your objects has appeared on the graph, alternately do a hiding-display for each of your objects (as I wrote above). This action brings the object to the foreground of the graphic. Your first object to which this action was applied will be at the bottom (but above any other graphical object drawn on the chart after your objects have been created), the second will be above the first, the third will be above the first and second, and so on. All objects that have been hid-overed will be above the rest of the graphical objects.

That is, the order in which the hiding-objects are applied to your objects determines their order above each other. But they will all appear above everything else on the graph.

The logic is this:

If any graphical object appears on the graph that shouldn't overlap your objects, you do a hiding-display for each of your objects in the order in which they should visually appear (first at the very bottom, last at the very top). After hiding-displaying all your objects do ChartRedraw().
This is important - redraw the chart only after all your objects have been hidden-displayed, so that visually there is no flickering on the chart.

Ahhhh, thank you very much! Now I get it. Great
 
Please, one more thing: I switched from a 2k monitor to a 1080 laptop and all the text became big and overlapped each other. Can you please advise how to solve this problem?
 
Ivan Butko #:
Kindly, one more thing: changed from 2k monitor to 1080 laptop and all the text became too big and overlapped each other. Please advise how to solve this problem

It's more complicated than that. You need to use resources to output graphics. Read TextSetFont() - this is about font size in logical pixels.

Accordingly TextOut() - about text output from the resource. You can find everything about this in the links in the documentation.

Документация по MQL5: Графические объекты / TextSetFont
Документация по MQL5: Графические объекты / TextSetFont
  • www.mql5.com
TextSetFont - Графические объекты - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Artyom Trishkin #:

It's more complicated than that. You need to use resources to output graphics. Read TextSetFont() - this is about font size in logical pixels.

Accordingly TextOut() - about text output from the resource. And all about it - via links in documentation.

Got it! Thanks a lot.

 
Ivan Butko #:
Please, one more thing: I switched from a 2k monitor to a 1080 laptop and all the text became big and overlapped each other. Please advise how to solve this problem
Windows tools. Graphics setup large small font should also adjust.
 
Valeriy Yastremskiy #:
With the help of the Windows. Graphics setting large small font should also adjust.

What if there are two monitors? Different ones...

 
Artyom Trishkin #:

What if there are two monitors? Different...

Then you need to understand the resolution of the screen where the image is displayed. The object can also get to 2 monitors) but it's a more complicated task.
Yes, binding to the system's standard fonts via negativeTextSetFont() values is a good solution.
 

Help optimise the indicator. The indicator works but slowly, it takes a very long time to optimise the EA with it. Please advise what has been done wrong? How to speed up its work?

//+------------------------------------------------------------------+
//|                                                     Momentum.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red

#property indicator_maximum 1
#property indicator_minimum 0

#property indicator_width1 2

//---- input parameters
extern int  MomPeriod    = 10;
extern int  WindowOfNorm = 45; // ширина окна нормирования в барах
extern int  MA_Length    = 10; // Average Period
extern int  MA_Mode      =  0; // Mode of Moving Average

//---- buffers
double NormBuffer[],MomBuffer[],AvgVolumes[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   SetIndexStyle(2,DRAW_NONE);
   SetIndexBuffer(2,NormBuffer);

   SetIndexStyle(1,DRAW_NONE);
   SetIndexBuffer(1,MomBuffer);
   
    SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,AvgVolumes);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Momentum                                                         |
//+------------------------------------------------------------------+
int start()
  {
   for(int i = 1;i <= 130; i++)
     {
      MomBuffer[i]=iMA(NULL,0,MomPeriod,0,0,0,i)*100/iMA(NULL,0,MomPeriod,0,0,0,i+MomPeriod);

      // нормирование
      NormBuffer[i]=Norm(WindowOfNorm,i);
      //-----
      AvgVolumes[i] = iMAOnArray(NormBuffer,0,MA_Length,0,MA_Mode,i);
     }
   return(0);
  }
//+------------------------------------------------------------------+

// нормирование
double Norm(int norm, int i) {
   // экстремумы
   double max=MomBuffer[ArrayMaximum(MomBuffer,norm,i)];
   double min=MomBuffer[ArrayMinimum(MomBuffer,norm,i)];
   // вычисление осциллятора
   double delta=max-min; // размах
   if(delta==0) return(1);
   else return((MomBuffer[i]-min)/delta);
  }

 
IrishDance #:

Help optimise the indicator. The indicator works but slowly, it takes a very long time to optimise the EA with it. Please advise what has been done wrong? How to make it work faster?

This is not the way it is done. Just pay attention to this line

//|                      Copyright © 2004, MetaQuotes Software Corp. |

The programming language has changed so much in 18 years that it should not work at all. I don't understand why MQ still hasn't disabled int init() and int start() altogether