Scripts: MS Excel: Data Exchange and Management

 

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: Слава

 

Can you send buy orders to MetaTrader from Excel?



Thanks!

 
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!
 

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.

 

Hi,

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.

JD_Investment

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

 

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

 

Yes you can send order from excel to mt4 - www.fxdialogue.com

 

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

Avals,

Can you post the source code for your dll?

Thanks.

-Non.

 

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.

 

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.

 

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

//+------------------------------------------------------------------+
//| translated via google by sebastrien@leuba.eu         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
#import
int start()
  { 
  
       if (ExcelOpen ()) Print ("Ucpeshno opened Excel"); else Print ("Can not open Excel:", ExcelGetLastErrorText ()) ;/ / Open the Excel
        ExcelSetTextCell (1,1, "Tools");
        ExcelSetTextCell(2,1,"EURUSD");        
        ExcelSetTextCell(3,1,"GBPUSD");        
        ExcelSetTextCell(4,1,"USDCHF");        
        
        ExcelSetTextCell(1,2,"Оpening(0:0 GMT)");
        ExcelSetValueCell(2,2,iOpen("EURUSD",PERIOD_D1,0));        
        ExcelSetValueCell(3,2,iOpen("GBPUSD",PERIOD_D1,0));                
        ExcelSetValueCell(4,2,iOpen("USDCHF",PERIOD_D1,0));        
                
        ExcelSetTextCell(1,3,"last Bid");       
        ExcelSetValueCell(2,3,MarketInfo("EURUSD",MODE_BID));        
        ExcelSetValueCell(3,3,MarketInfo("GBPUSD",MODE_BID));                
        ExcelSetValueCell(4,3,MarketInfo("USDCHF",MODE_BID));        
        
        ExcelSetTextCell(1,4,"Change Change");        
        ExcelSetRange("D2:D4");        
        ExcelSetFormula("=C2-B2");                
           
        ExcelSetRange("A1");
        ExcelRangeColumnWidth(15);
        ExcelSetRange("B1");
        ExcelRangeColumnWidth(20);
        ExcelSetRange("C1");
        ExcelRangeColumnWidth(20);
        ExcelSetRange("D1");
        ExcelRangeColumnWidth(20);
        ExcelSetRange("A1:D1");
        ExcelRangeInteriorColor(0x000000);   
        ExcelRangeFontColor(0xFFFFFF);                      
        
        ExcelSetDiagramma(103,"Change Change","A2:A4","D1:D4",1,50,400,200);                  
        bool NeedLoop=true;  
        double lastEURUSD,lastGBPUSD,lastUSDCHF;
        double curEURUSD,curGBPUSD,curUSDCHF;
        while(NeedLoop){           
          curEURUSD=MarketInfo("EURUSD",MODE_BID);
          curGBPUSD=MarketInfo("GBPUSD",MODE_BID);
          curUSDCHF=MarketInfo("USDCHF",MODE_BID);
          if  (lastEURUSD!=curEURUSD){
            lastEURUSD=curEURUSD;
            ExcelSetValueCell(2,3,MarketInfo("EURUSD",MODE_BID));                    
          }
          if  (lastGBPUSD!=curGBPUSD){
            lastGBPUSD=curGBPUSD;
            ExcelSetValueCell(3,3,MarketInfo("GBPUSD",MODE_BID));                    
          }          
          if  (lastUSDCHF!=curUSDCHF){
            lastUSDCHF=curUSDCHF;
            ExcelSetValueCell(4,3,MarketInfo("USDCHF",MODE_BID));                    
          }                              
          Sleep(1000);
        }//while     
        
   return(0);
  }
void deinit()
  {
   ExcelSaveAs("C:\proba.xls");
   ExcelClose();
  }

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

Reason: