Download MetaTrader 5

Scripts: MS Excel: Data Exchange and Management

To add comments, please log in or register
Do you know that MQL5 has event handling?
MetaQuotes Software Corp.
MetaQuotes Software Corp. 2008.06.03 09:59 

MS Excel: Data Exchange and Management:

A DLL to manage and exchange data between MT4 and MS Excel. OLE is used. The description of the DLL functions is given in the attached example. The example is a script that sends quotes to Excel and builds the diagram of daily price changes. At exiting,

Author: Слава

MQL4 Comments
MQL4 Comments 2008.07.05 16:42  

Can you send buy orders to MetaTrader from Excel?


MQL4 Comments
MQL4 Comments 2008.07.11 20:35  
HI, Avals, You did a good job. Is that possible to read or write specific sheet? I mean it's seem to me that I can't control the sheet except ExcelAddSheet(). Sometime, I may need to exchange data in certain sheet. Thank you!
Lococo 2008.08.13 15:55  

I added the mt4excel.dll to the expert folder (i dont know if it should be there), and then I to run your shablon1.mq4 but nothing happens. I have Office 2007. I am doing something wrong?

Thank you for your help.

MQL4 Comments
MQL4 Comments 2008.08.25 10:41  


Great job. Thank you very much.

I have one suggestion. May you add function(s) that controls calculation methods (automatic or manual)? It would be very useful when you have sophisticated spreadsheet and load a lot of data using your library. That way after inserting one value the whole spreadsheet is automatically recalculated, which is very time consuming. It would be very convenient, if you could turn calculation method into manual, transfer all the data, and then turn the calculation methods back to automatic.


P.S. In the meaning of VBA it is the "Application.Calculation = xlCalculationManual" and "Application.Calculation = xlCalculationAutomatic" and "Application.Calculate".

MQL4 Comments
MQL4 Comments 2009.06.13 23:33  

Not bad. However here is a better, easier way with hell of a lot more features than that. You can see it here

MQL4 Comments
MQL4 Comments 2009.06.13 23:33  

Yes you can send order from excel to mt4 -

Michael 2010.02.04 05:43  

I know this is an old thread, but I hope the author is still checking it.


Can you post the source code for your dll?



MQL4 Comments
MQL4 Comments 2010.03.01 13:29  

Hi to all, I'm new in the site and this is my first posting :-) I want to thank all those who contribute to the overall improvement of the systems,

and make themselves available to all.

Just a question, for now. Can you explain how to set and where patch, the two files you've posted?

thankyou in advance!

PS: sorry for my english, scant correct :-)) i'm from Italy.

MQL4 Comments
MQL4 Comments 2010.03.16 10:59  

Well done Avals!

For newbies please put mt4excell.dll in experts/libraries folder and shablon1.mq4 in experts folder.

Avals could you provide us with documentation of api commands for your dll. I've looked in the shablon1.mq4 but it's all gibberish (russian?). Would like to see your list of commands in english short description is enough! Thanks.

Sébastien Leuba
Sébastien Leuba 2013.03.28 23:22  

A quick  translation made via Google to understand what happen with shablon1.

//| translated via google by         shablon.mq4 |
//|                                             Viatcheslav Suvorov  |
#property copyright "Viatcheslav Suvorov"
#property show_inputs
#include <WinUser32.mqh>
#import "mt4excel.dll"
bool ExcelOpen () ;/ / Opens Excel and creates a blank page
bool ExcelClose () ;/ / Close Excel
bool ExcelOpenPattern (int NumPatt) ;/ / Open the Excel Pattern
bool ExcelOpenFile (string FileName) ;/ / Open the Excel file
bool ExcelSave () ;/ / save the file
bool ExcelSaveAs (string FileName) ;/ / save the file in the FileName
bool ExcelAddSheet (string Name) ;/ / Add sheet and make it active
bool ExcelSetFormulaCell (int X, int Y, string Value) ;/ / Write the formula in cell
double ExcelGetValueCell (int X, int Y) ;/ / counts the number of cells
string ExcelGetTextCell (int X, int Y) ;/ / Read the text from a cell
string ExcelGetFormulaCell (int X, int Y) ;/ / Read the formula in cell
/*TypeD - тип диаграммы:
xl3DArea -4098        xl3DAreaStacked 78      xl3DAreaStacked100 79   xl3DBarClustered 60     xl3DBarStacked 61    xl3DBarStacked100 62 
xl3DColumn -4100      xl3DColumnClustered 54  xl3DColumnStacked 55    xl3DColumnStacked100 56 xl3DLine -4101       xl3DPie -4102 
xl3DPieExploded 70    xlArea 1                xlAreaStacked 76        xlAreaStacked100 77     xlBarClustered 57    xlBarOfPie 71 
xlBarStacked 58       xlBarStacked100 59      xlBubble 15             xlBubble3DEffect 87     xlColumnClustered 51 xlColumnStacked 52 
xlColumnStacked100 53 xlConeBarClustered 102  xlConeBarStacked 103    xlConeBarStacked100 104 xlConeCol 105        xlConeColClustered 99 
xlConeColStacked 100  xlConeColStacked100 101 xlCylinderBarClustered 95 xlCylinderBarStacked 96 xlCylinderBarStacked100 97 xlCylinderCol 98 
xlCylinderColClustered 92 xlCylinderColStacked 93 xlCylinderColStacked100 94 xlDoughnut -4120 xlDoughnutExploded 80 xlLine 4 xlLineMarkers 65 
xlLineMarkersStacked 66 xlLineMarkersStacked100 67 xlLineStacked 63 xlLineStacked100 64 xlPie 5 xlPieExploded 69 xlPieOfPie 68 xlPyramidBarClustered 109 
xlPyramidBarStacked 110 xlPyramidBarStacked100 111 xlPyramidCol 112 xlPyramidColClustered 106 xlPyramidColStacked 107 xlPyramidColStacked100 108 
xlRadar -4151 xlRadarFilled 82 xlRadarMarkers 81 xlStockHLC 88 xlStockOHLC 89 xlStockVHLC 90 xlStockVOHLC 91 xlSurface 83 
xlSurfaceTopView 85 xlSurfaceTopViewWireframe 86 xlSurfaceWireframe 84 xlXYScatter -4169 xlXYScatterLines 74 xlXYScatterLinesNoMarkers 75 
xlXYScatterSmooth 72 xlXYScatterSmoothNoMarkers 73 */  
bool ExcelSetDiagramma(int TypeD,string Title,string XRange,string YRange,int Left,int Top,int Riht,int Bottom);//Добавляет диаграму
bool ExcelDiagrammaAddRange () ;/ / Add data to a chart. The first line - the title
bool ExcelSetValueCell (int X, int Y, double Value) ;/ / Write the number in a cell
bool ExcelSetTextCell (int X, int Y, string Value) ;/ / save the text in a cell
bool ExcelSetRange (string Range) ;/ / Remember range
string ExcelGetFormat () ;/ / Returns the format range
bool ExcelSetFormat (string Format) ;/ / Set the format for diapozana
bool ExcelSetFormula (string Formula) ;/ / write the formula in a range
bool ExcelIsFormula () ;/ / true if the formula is in the range
int ExcelRangeCount () ;/ / Number of cells in a range
string ExcelRangeAdress () ;/ / Address Range
bool ExcelRangeColumnWidth (int Width) ;/ / Bandwidth
bool ExcelRangeRowHeight (int Height) ;/ / height range
bool ExcelRangeInteriorColor (int Color) ;/ / background color range
bool ExcelRangeFontColor (int Color) ;/ / font color range
int ExcelGetLastErrorCode () ;/ / last error Excel
string ExcelGetLastErrorText () ;/ / The text of the last error Excel
int start()
       if (ExcelOpen ()) Print ("Ucpeshno opened Excel"); else Print ("Can not open Excel:", ExcelGetLastErrorText ()) ;/ / Open the Excel
        ExcelSetTextCell (1,1, "Tools");
        ExcelSetTextCell(1,2,"Оpening(0:0 GMT)");
        ExcelSetTextCell(1,3,"last Bid");       
        ExcelSetTextCell(1,4,"Change Change");        
        ExcelSetDiagramma(103,"Change Change","A2:A4","D1:D4",1,50,400,200);                  
        bool NeedLoop=true;  
        double lastEURUSD,lastGBPUSD,lastUSDCHF;
        double curEURUSD,curGBPUSD,curUSDCHF;
          if  (lastEURUSD!=curEURUSD){
          if  (lastGBPUSD!=curGBPUSD){
          if  (lastUSDCHF!=curUSDCHF){
void deinit()

 Not 100% sure of the translation quality, but better than nothing.

To add comments, please log in or register