View Full Version : Export to Excel in Real Time
Tete999
12-14-2012, 12:08 PM
I use DDE library provided by Windows. No custom / dll that is proprietary.
The process will be as follow:
1. Initialize DDE
2. Create series handle for Excel Appliion (in DDE term, it's known as SERVICE)
3. Create series handle for Sheet title (TOPIC)
4.) Connect to Sheet
5. Free the above handles, they won't be used anymore
6. Create series handle for cell (ITEM) using cell address in R1C1 style
7. Send the information
8. To export information to a different cell, replie 6-7
9. You can reuse the created items' handle (in case you want to update the cells frequently)
10. Before program return, free all items' string handle
11. Disconnect Excel and sheet
12. Uninitialize DDE
Make Certain to enable Allow DLL imports in Expert Advisor configurations.
You might want to disable MT4 DDE Server before running this script.
You will find 2 files attached in this article:
- ExcelExportLib.mq4, put this file in specialists\libraries folder. This is merely a very simple mq4 library that wrap a DDE functions.
- ExcelExportTest.mq4, put this file in specialists\scripts folder. It is a test script that can write text on Excel Sheet 1, cell R2C2
Cheers,
selket97
12-05-2021, 10:23 AM
quote Hi Serkan, I upgraded the library to the latest MT4 build. Place ExcelExportLib.ex4 into MQL4\Libraries folder. I also attached a sample script showing how to call the lib. Finest, s document file Hallo Sir I tried to modify https://www.forexsoutheast.asia/attachments/15184142061557218443.mq4 to get more data in Excel.
This is my code but I get just the personality R CellAddress = R1C2:
that I apriciate your help.
#property copyright Copyright 2012, Stephen Ambatoding
#property Hyperlink http://www.Forexsoutheast.asia.com/sangmane
#property strict
#property show_inputs
extern string Sheet = Sheet1;
string CellAddress ;
string CellValue ;
#import ExcelExportLib.ex4
int ExcelInit(string Sheet);
void ExcelDeinit();
int ExcelWrite(string CellAddress, string CellValue);
#import
void OnStart()
if(CellAddress = R1C2)
string CellValue = From Indonesia with Love;
int iRet;
iRet = ExcelInit(Sheet);
if (iRet == 0)
Alert(ExcelInit failed!) ;
return;
iRet = ExcelWrite(CellAddress, CellValue);
if (iRet == 0)
Alert(ExcelWrite failed!) ;
ExcelDeinit();
return;
Auriwer
12-05-2021, 11:44 AM
That I just wanted to thank you, although MT4 isn't used by me - that I know how much work it is to place such things together.
oxrolme84
12-05-2021, 01:05 PM
Nice work Sangmane - and - thank you.
vicpkrwz
12-05-2021, 02:26 PM
Hello, Can you please the two files? I'd like to provide this a test. Thank you very much
Sangmane,
Is it possible to export real time indior worth to a excel worksheet?
Please re-attach the 2 files.
Thanks and regards,
mamidervasio
12-05-2021, 05:07 PM
Hello,
Im attempting to use your library, unfortunatelly with no success. Also the test file doesn't work, it gives error (1) (see below).
Am utilizing MT4 build 670 on Windows 8 and that I have the following 2 situations:
1) when I attempt to include your library in my code I get the following error:
Cannot loe 'ExcelInit' in 'ExcelExportLib.ex4'
2) To solve the problem in 1) I did a KISS procedure =gt; I have copied ExcelExportLib.mq4 in my EA and called the functions right, after which I have discovered that at ExcelInit(. .) , DdeConnect(...) returns 0, whatever I try.
Then I googled for DdeConnect plus some suggested that I should switch to the Unicode style instead of Ansi, so I changed into utilizing DdeInitializeW(. .) and DdeCreateStringHandleW(. .) But this also didn't help.
Would you understand what's happening and how I can fix this ?
Thanks Beforehand.
Tete999
12-05-2021, 06:28 PM
Hi, Im trying to use your library, unfortunatelly without achievement. In addition, the test file does not work, it gives mistake (1) (see below). Im using MT4 build 670 on Windows 8 and now I have the following 2 scenarios: 1) when I attempt to add your library into my code I get the following error: can't find 'ExcelInit' in 'ExcelExportLib.ex4' two) To solve the problem in 1) I did a KISS method =gt; I've copied ExcelExportLib.mq4 within my EA and called as the functions right, and then I've discovered that in ExcelInit(. .) , DdeConnect(...) returns 0, whatever I attempt.... Hi Serkan,
I upgraded the library to the Most Recent MT4 build. Put ExcelExportLib.ex4 into MQL4\Libraries folder.
I also attached a sample script showing how to call the lib.
Best,
s
https://www.forexsoutheast.asia/attachments/15184142011512546714.ex4
https://www.forexsoutheast.asia/attachments/1518414203239519258.mq4
mamidervasio
12-05-2021, 07:49 PM
OK thx for the effort.
I have analyzed your new files and mistake (1) doesn't seem anymore, but (2) still happens if I run your test (an alert is displayed with the message ExcelWrite neglected !) ;
Btw, correct me if I am wrong, but the idea of your code is that you create your own DDE service that could be called from Excel or OpenOffice, right ? Like this (in OpenOffice) =DDE(EXCEL, sheet1; r1c1).
Pancora9580
12-05-2021, 09:10 PM
Thanks so much sangmane, been searching everywhere for something like this!
Cheers
selket97
12-05-2021, 10:30 PM
1 Attachment(s) that is a pleasant Tool.
I attempted to publish my Trades on my Homepage Afterward I discovered this program:
https://www.mql5.com/de/code/1246
how do I convert mq5 to mq4? This tool was composed in mq4 but is altered to mq5.
All information that become available in MQL5 can be exported via this DDE interface.
How do I modify dde_example in order to export my Closed Transactions, Open concessions and pending orders to excel.
https://www.forexsoutheast.asia/general-forex/116-favorite-alert-systems.html
Oxcame
12-05-2021, 11:51 PM
I liked this solution very much, but it needed updating to today's MT4.
So I attach new files after minor changes that I made.
Really changes were made only to ExcelExportLib, but I attach the test record also just in case.
@bah12ram - This solution will mend what you experienced.
https://www.forexsoutheast.asia/attachments/15184142072128899637.mq4
https://www.forexsoutheast.asia/attachments/15184142091600486381.ex4
I liked this solution very much, but it needed updating to the MT4.
So I attach new documents after minor changes that I made.
Really changes were made solely to ExcelExportLib, but that I attach the test file also only in case.
@friday13, thanks very much. Would you mind submitting the ExcelExportLib.mq4 file?
Regards
@friday13, thanks very much. Would you mind submitting the ExcelExportLib.mq4 file with the changes you have made?
No worries, I figured out it. Watch file attached.
https://www.forexsoutheast.asia/attachments/1518414210593033486.mq4
Oxcame
12-06-2021, 03:54 AM
quote No worries, I figured out it. See file attached. file Nicely done. I did not add the code out of admiration to Sangmane, who did not place it here.
Two opinions:
1. Adding the ? is not necessary, as:
MQL4 utilizes both approaches, with one exception: arrays, structure type factors and class objects are always passed by reference. (from https://docs.mql4.com/basis/function/parameterpass)
2. Your code determines of a maximum cell size of 256 bytes, while my lib file uses dynamic range since I don't wish to limit my memory intake to a fixed size every time, and also an excel cell size may hold up to 32,767 bytes, according to: https://support.office.com/en-us/article/excel-specifiions-and-limits-1672b34d-7043-467e-8e27-269d656771c3.
quote Properly done. I simply didn't add the code out of respect to Sangmane, that didn't post it in the first loion. Hi,
Thank you for your remarks, you're absolute right. Can you make any progress with reading from Excel using DDE?
Regards
Oxcame
12-06-2021, 06:35 AM
quote Hello, Thanks for your opinions, you are absolute right. Can you perhaps make any progress with studying from Excel using DDE? Regards Hello,
Actually no, I didn't attempt to read from Excel using DDE, only to export to Excel.
Why do you wish to read from Excel using DDE and where do you want the information to be exported to?
We can open a new thread regarding your idea if you want.
quote Hi, Actually no, I didn't try and read from Excel using DDE, only to export into Excel. Do you want to read using DDE and where do you want the information to be exported to? We can open a new thread if you want. Hi,
I wish to read information back to MT4 for various purposes. This is sometimes caused by calculations in Excel, or control issued from Excel. Excel is a great research tool. Anyway, I managed to get 2 way communiion functioning and have produced a C# DDE wrapper. It's a work in progress, but in principle it works fine.
Regards
Oxcame
12-06-2021, 09:17 AM
quote Hi, I want to read data back to MT4 for various purposes. This is sometimes the result of calculations in Excel, as well as command issued from Excel. Excel is a great research tool. Anyhow, I have created a C# DDE wrapper and was able for 2 way communiion working. It is a work in progress, but in principle it works alright. Regards Sounds cool!
Powered by forexsoutheast.asia® Version 4.2.5 Copyright © 2023 forexsoutheast.asia Solutions, Inc. All rights reserved.