Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

ChartObjectsCopyPaste - MetaTrader 5 Script - MT4/MT5 Resources

author EAcpu | 2 reads | 0 comments |

ChartObjectsCopyPaste - indicator for MetaTrader 5

Have you ever needed to copy and paste some graphical objects between open charts? I think you have. Surprisingly, MetaTrader does not provide "copy and paste" functionality for objects. The only thing that allows you to achieve something more or less similar is a template (tpl file). But the template stores the complete chart state, including indicators, settings and a lot of auxiliary content that may be irrelevant and unnecessary for the required copying process.

That's why I developed this indicator chart object copypaste.mq5 . It copies the selected objects to the clipboard, where they can then be pasted onto other charts. no strings attached.

This indicator is based on another indicator published in Algorithmic Trading Book - objectgroupedit.mq5 .

Please follow the link to learn more about all the underlying classes ( object monitors , mapped arrays and others) working behind the scenes.

This indicator has no buffer. It should be attached to at least 2 charts: the source chart from which you want to copy the object, and the target chart to which you plan to paste the object.

When running on a chart, the indicator tracks existing graphical objects and records the selected objects.

As usual, the "copy and paste" commands work in pairs:

Why press Ctrl+Q/Ctrl+J? These are just 2 free key combinations chosen voluntarily from a very small number. This is because MetaTrader intercepts many hotkeys and does not propagate them to the MQL program. This is especially true for the standard Ctrl+C/Ctrl+V/Ctrl+Ins/Shift+Ins, which don't work in this context.

Since the source code is available, you can change the hotkeys to other combinations.

Since the indicator uses a system DLL to access the Windows clipboard, you should allow this in the Properties dialog box, on the Dependencies tab.

Since the code base does not allow DLL imports, the clipboard related code is wrapped into a conditional preprocessor directive #ifdef DLL_LINK, so uncomment that line

#Define DLL_LINK

before compiling. Otherwise, you'll see how the clipboard functionality stub shows you an alert in response to pressing the hotkey, and doesn't do anything real!

Here is an example of clipboard text containing 2 objects:

OBJ_VLINE H1 vertical line 5578 0 0
Enumeration ENUM_OBJECT_PROPERTY_INTEGER
0OBJPROP_COLOR 55295
1 OBJPROP_STYLE 2
2OBJPROP_WIDTH 1
3OBJPROP_BACK 0
4OBJPROP_SELECTED 1
7OBJPROP_TYPE 0
8OBJPROP_TIME 1726739940
10OBJPROP_SELECTABLE 1
11 OBJPROP_CREATETIME 1726847009
12 OBJPROP_TIMEFRAMES 2097151
200OBJPROP_LEVELS 0
207 OBJPROP_ZORDER 0
208 OBJPROP_HIDDEN 0
1032 OBJPROP_RAY 1
Enumeration ENUM_OBJECT_PROPERTY_DOUBLE
9OBJPROP_PRICE 1.11449
Enum ENUM_OBJECT_PROPERTY_STRING
5 OBJPROP_NAME H1 vertical line 5578
6 OBJPROP_TEXT 206 OBJPROP_TOOLTIP 
OBJ_Channel H1 Equally spaced channel 40885 5 1
Enumeration ENUM_OBJECT_PROPERTY_INTEGER
0OBJPROP_COLOR 255
1OBJPROP_STYLE 0
2OBJPROP_WIDTH 1
3OBJPROP_BACK 0
4OBJPROP_SELECTED 1
7OBJPROP_TYPE 5
8OBJPROP_TIME 1726758000
8OBJPROP_TIME . 1 1726797600
8OBJPROP_TIME . 2 1726758000
10OBJPROP_SELECTABLE 1
11 OBJPROP_CREATETIME 1726847883
12 OBJPROP_TIMEFRAMES 2097151
200OBJPROP_LEVELS 0
207 OBJPROP_ZORDER 0
208 OBJPROP_HIDDEN 0
1003 OBJPROP_RAY_LEFTclass="number">0 1004 OBJPROP_RAY_RIGHT 0 1031 OBJPROP_FILL 0 enumeration ENUM_OBJECT_PROPERTY_DOUBLE 9 OBJPROP_PRICE - 28.113879003558715 9 OBJPROP_PRICE . 1 - 21.708185053380777 9 OBJPROP_PRICE . 2 - 48.04270462633452 ENUM_OBJECT_PROPERTY_STRING 5 OBJPROP_NAME H1 Isometric Channel 40885 6 OBJPROP_TEXT 206 OBJPROP_TOOLTIP

Here are these objects pasted on the chart:

ChartObjectsCopyPaste - indicator for MetaTrader 5


Attachment download

📎 objectmonitorext.mqh (12.33 KB)

📎 maparray.mqh (2.74 KB)

📎 autoptr.mqh (1.86 KB)

📎 chartobjectscopypaste.mq5 (10.35 KB)

Source: MQL5 #52263

Verification code Refresh