$npx -y skills add kecoma1/MQL5-SKILLS --skill paint-objectsUse when drawing or updating chart objects in MQL5 for this workspace. Follow the local rules for choosing the right object type, anchoring it to the correct candle, updating existing objects safely, and forcing chart redraw when needed.
| 1 | # Paint Objects |
| 2 | |
| 3 | Use this skill when creating or editing MQL5 code that paints chart objects with `ObjectCreate`, `ObjectMove`, or `ObjectSetInteger`. |
| 4 | |
| 5 | ## Object Choice |
| 6 | |
| 7 | Choose the object type that matches the visual requirement. |
| 8 | |
| 9 | - Use `OBJ_RECTANGLE` for zones, gaps, ranges, and areas with top and bottom. |
| 10 | - Do not simulate a zone with two trend lines when the intent is a filled area. |
| 11 | - Use lines only when the user explicitly wants a line-based drawing. |
| 12 | |
| 13 | ## Anchoring |
| 14 | |
| 15 | Anchor the object to the correct candle and prices. |
| 16 | |
| 17 | - If the drawing is based on a multi-candle pattern, confirm which candle defines the start time. |
| 18 | - For the FVG case in this workspace, the rectangle must start at candle 1, the oldest candle in the 3-candle pattern. |
| 19 | - For zones, use the upper price as the top and the lower price as the bottom. |
| 20 | |
| 21 | Example pattern for FVG: |
| 22 | |
| 23 | ```mq5 |
| 24 | datetime start_time = StructToTime(time); |
| 25 | datetime end_time = start_time + (duration_minutes * 60); |
| 26 | |
| 27 | ObjectCreate(chart_id, rect_name, OBJ_RECTANGLE, 0, start_time, high, end_time, low); |
| 28 | ``` |
| 29 | |
| 30 | ## Repainting And Updates |
| 31 | |
| 32 | Do not assume `ObjectCreate` will succeed repeatedly with the same name. |
| 33 | |
| 34 | - If the object does not exist, create it. |
| 35 | - If the object already exists, update it with `ObjectMove`. |
| 36 | - Keep object names stable and deterministic. |
| 37 | |
| 38 | Pattern: |
| 39 | |
| 40 | ```mq5 |
| 41 | if(ObjectFind(chart_id, object_name) < 0) |
| 42 | { |
| 43 | ObjectCreate(chart_id, object_name, OBJ_RECTANGLE, 0, start_time, high, end_time, low); |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | ObjectMove(chart_id, object_name, 0, start_time, high); |
| 48 | ObjectMove(chart_id, object_name, 1, end_time, low); |
| 49 | } |
| 50 | ``` |
| 51 | |
| 52 | ## Visibility |
| 53 | |
| 54 | After painting or updating objects, force a chart refresh when needed. |
| 55 | |
| 56 | - Call `ChartRedraw(chart_id)` after a batch of object updates. |
| 57 | - Do not assume the chart will visibly refresh immediately on its own. |
| 58 | |
| 59 | ## Validation |
| 60 | |
| 61 | When painted objects do not appear, check these points before changing strategy logic: |
| 62 | |
| 63 | 1. The object name is not colliding with an existing object unexpectedly. |
| 64 | 2. Existing objects are updated with `ObjectMove` instead of recreated blindly. |
| 65 | 3. `ChartRedraw(...)` is called after painting. |