Errors, bugs, questions - page 758

 
Yeah, now they're four seconds ahead.
 
Why does the midpoint disappear when the trend line changes position?
 

Hello!

I need to see graphically how the value of a certain variable changes on each bar during a visual test, i.e. I need to build a separate graph in a sub-window. For example, I want to see a graph of equity changes on each bar in a separate window below the chart.

What should I do? Should I write an indicator, attach it to the chart and pass to it the values of variables from the EA through global variables of the terminal? Or there is a "better" way?

Thank you in advance.

Документация по MQL5: Основы языка / Переменные / Глобальные переменные
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
  • www.mql5.com
Основы языка / Переменные / Глобальные переменные - Документация по MQL5
 
Alex5757000:

Hello!

I need to see graphically how the value of a certain variable changes on each bar during a visual test, i.e. I need to build a separate graph in a sub-window. For example, I want to see a graph of equity changes on each bar in a separate window below the chart.

What should I do? Should I write an indicator, attach it to the chart and pass to it the values of variables from the EA through global variables of the terminal? Or there is a "better" way?

Thank you in advance.

Not at all, you can get equity or balance values directly in the indicator.

Define the parameters of the indicator buffer drawing as a bar chart.

And write all four values in the appropriate buffers,

Open at bar opening, high-low and dynamic (the last bar).

In short, it looks like this: in the attachment

Of course, you can use absolute value (recommended option), but I don't think it shows small initial increments, so I think the difference between initial and current values is better.

ZS, but no, the scale is dynamic so you can do the second option, it's quite readable.

Files:
 
Urain:

Not at all, you can get the equity or balance values directly in the indicator.

Set the parameters for drawing the indicator buffer as a bar chart.

and write all four values to the corresponding buffers,

open at bar open, high low and close dynamically (last bar).

Equity and balance values - yes, but what if I want to see the value of a variable calculated in the EA?
 
Alex5757000:
Equity and balance values - yes, but what if I want to see the value of a variable calculated in an EA?

You can do it via custom event, just don't forget to update the chart after the event,

because the tick comes before the event is processed, in order of priority.

But it is possible to do it with globals, but there is the same problem - the tick has already come and the variable is still being processed in the EA (its changes are being prepared), of course, the data will be received, but there will be a delay on one tick, it is still more correct in the event, there is a place to put update the chart after the fact, when you already know for sure that the variable has the actual data.

 

This code does not compile with the error "'return' - structure has objects and cannot be copied" because of the"CTest getCopy(void) {CTest res; return res;}" stop.

This can be fixed in 2 ways:

1) change"class" to"struct"

2) uncomment the stopka with an overloaded assignment operator.

So it should be so that the role of copy constructor is performed by overloaded assignment operator? Why then it is not mentioned in the reference book, except for one example of a matrix class (detailed analysis of which, by the way, allowed me to find the error in my code)?

class CTest
  {
public:
    CTest(void): cnt(0) {}
   ~CTest(void) {}
    CTest(const CTest& T) {cnt = T.cnt;} // copy constructor
    //------------------------
    CTest getCopy(void) {CTest res; return res;} 
    //------------------------
    //CTest* operator=(const CTest& T) {cnt = T.cnt; return GetPointer(this);}
private:
         int cnt;
  };
Документация по MQL5: Основы языка / Операторы / Оператор-выражение
Документация по MQL5: Основы языка / Операторы / Оператор-выражение
  • www.mql5.com
Основы языка / Операторы / Оператор-выражение - Документация по MQL5
 
WWer:

This code does not compile with the error "'return' - structure has objects and cannot be copied" because of the"CTest getCopy(void) {CTest res; return res;}" stop.

Of course, an object cannot be returned from functions.(Unlike structures.) It's documented.


This can be fixed in 2 ways:

1) change"class" to"struct"

See above.

2) uncomment the stopka with an overloaded assignment operator.

Of course, the overloaded operator returns a handle-pointer, which is normal. Now it's not the object returned from the getCopy() function but the pointer (the return from the function is an implicit assignment) which makes the code correct.

// Only syntactically correct.

// Return of an uninitialized variable from the getCopy() function, I hope, serves only to demonstrate the syntax problem and does not pretend to be reasonable.

So it should be so that the role of copy constructor is performed by overloaded assignment operator?

Um... What do roles have to do with it? You may overload the assignment operator in any way you want and write the copy constructor correctly. The error in your case lies elsewhere.


Why is it not mentioned in the reference book, except for one example of a matrix class (its detailed analysis, by the way, helped me find the error in my code)?

Because on February 11, 2096785 BC, dinosaur Vasya carelessly stepped on the lizard Clava. It caused a long chain of causes and consequences, which led to the current situation. You can't help it.

;)

 
MetaDriver:// Return of an uninitialized variable from getCopy() function, hopefully, serves only to demonstrate the syntax problem, and does not pretend to be reasonable.

Why should it be initialised? It's an instance of a class that has a constructor for just that purpose.

MetaDriver:
Um... What do roles have to do with it? You may overload the assignment operator in any way you want and write the copy constructor correctly. Your error is in another place entirely.

And then how to write a correct copying constructor for this purpose?