- Application of graphic resources in trading
- Setting levels in level objects
- Ray properties for objects with straight lines
can any one help me with this code?
Traders and coders are working for free:
-- if it is interesting for them personally, or
-- if it is interesting for many members on this forum.
Freelance section of the forum should be used in most of the cases.
- 2026.05.06
- www.mql5.com
The compilation errors were primarily caused by:
-
Incompatible syntax: MQL5 has strict limitations on operator overloading for structures.
-
Incorrect function signatures: The method required more arguments than provided. Attach
-
Library differences: The class uses rather than to release resources. CCanvas Destroy() Detach()
| Original Code | Corrected Code | Note | |
| bool operator==(...) | Removed (Moved to a method within ViewportState ) | MQL5 doesn't support global equality operators for structs in this context. | |
| m_canvas.Attach(m_obj_name) | m_canvas.Attach(0, m_obj_name, COLOR_FORMAT_ARGB_NORMALIZE) | Added the missing Chart ID and Color Format parameters. | |
| m_canvas.Detach() | m_canvas.Destroy() | Replaced with the valid method name for the CCanvas library. | |
| if(cur != g_last_viewport_state) | if(cur.IsChanged(g_last_viewport_state)) | Updated the logic to call the newly created comparison method. |
Technical Explanation
-
Operator Overloading: Instead of using global operators, we implemented a member function (e.g., ) within the structure to compare states. IsChanged ViewportState
-
CCanvas Method Signatures: The method in MQL5's requires a minimum of three arguments: , , and . Attach Canvas.mqh chart_id obj_name color_format
-
Resource Management: In the standard class, is the proper method to clean up the canvas object and detach it from the chart. CCanvas Destroy()
Incompatible syntax: MQL5 has strict limitations on operator overloading for structures.
What are you talking about? Operation overloading works great for structures.
struct S { private: int x; public: bool operator==(const S& other) { return x == other.x; } S(int a_x) : x(a_x) {} }; #define _print(x) Print(#x" --> ", (x)) void OnStart() { S one(1); S two(2); _print(one == one); _print(one == two); }
Output:
one == one --> true
one == two --> false
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use