Is it possible to launch Excel within a signal

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Is it possible to launch Excel within a signal

Postby arjfca » 11 Jul 2011

Hello

Is it possible to test for an Excel file opened and if not found to launch it?

Martin

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Is it possible to launch Excel within a signal

Postby TJ » 11 Jul 2011

Hello

Is it possible to test for an Excel file opened and if not found to launch it?

Martin
for excel file?
nothing in EasyLanguage/PowerLanguage that I know of.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Is it possible to launch Excel within a signal

Postby TJ » 11 Jul 2011

for ASCII file, or CSV delimited file, which can be read by Excel:

you can use the PRINT keyword and specify a filename.


PRINT

...

File("PathFilename")


Where: PathFilename - a string expression specifying the path and filename

Specifies an ASCII file as the output target;

if the specified file does not exist, the file will be created.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Is it possible to launch Excel within a signal

Postby arjfca » 11 Jul 2011

Thanks TJ

Then, i will launch MC workbook using Excel. I had done a similar job few years ago where Excel was launching a screen capture application.

Martin

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Is it possible to launch Excel within a signal

Postby furytrader » 11 Jul 2011

This is something you could probably achieve using a .dll - in response to another post recently, I put together a .dll that lets you execute shell commands. The solution to this would probably be similar, I think.

Just to clarify, is what you're trying to do:

1) See if an existing Excel document is open already in Excel
2) If it's not open, then open it in Excel

Is that right?

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Is it possible to launch Excel within a signal

Postby arjfca » 12 Jul 2011

Hello FuryTrader
1) See if an existing Excel document is open already in Excel
2) If it's not open, then open it in Excel
Is that right?
Yes. I want to make sure that both are open at the same time. A one step process.

Martin

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Is it possible to launch Excel within a signal

Postby furytrader » 13 Jul 2011

It's not hard to create a .dll that would allow you to launch a document (Excel or anything else) from within EasyLanguage. It gets a little trickier when it comes to creating a .dll that can determine whether some document is already open by another program, because you have to make certain Windows API calls to make that determination.

If there was a way to have the EasyLanguage indicator or strategy keep track of whether the document was already open, that'd probably be the easiest way to go. In other words, the first time that the strategy opens the document, it sets a variable to indicate that this has happened. Before the strategy tries to open the document a second time, it would first check that EasyLanguage variable to see if the document is already open.

However, if this same strategy is being used across different markets, that's a bit harder to pull off, since the strategy may have already opened the doc in one market, but in some other market, that hasn't happened yet. It may be possible to create a Global Variable that is flagged when the document is first opened by any instance of the strategy, and then other instances of that strategy could first check that global variable to see whether it's "turned on" to determine whether the document is already open.
Last edited by furytrader on 14 Jul 2011, edited 1 time in total.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Is it possible to launch Excel within a signal

Postby arjfca » 13 Jul 2011

Hello FuryTrader

Code: Select all

It's not hard to create a .dll that would allow you to launch a document (Excel or anything else) from within EasyLanguage.
Never done that, will work on the subject

Code: Select all

If there was a way to have the EasyLanguage indicator or strategy keep track of whether the document was already open, that'd probably be the easiest way to go. In other words, the first time that the strategy opens the document, it sets a variable to indicate that this has happened. Before the strategy tries to open the document a second time, it would first check that EasyLanguage variable to see if the document is already open.

It may be possible to create a Global Variable that is flagged when the document is first opened by any instance of the strategy, and then other instances of that strategy could first check that global variable to see whether it's "turned on" to determine whether the document is already open.
Nice point here. I'm actually leaning how to play with Global Variable.

I will work on these and post the code when I succeed
Thanks again for your input

Martin

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Is it possible to launch Excel within a signal

Postby furytrader » 13 Jul 2011

Actually, in investigating this idea, I created a .dll that does this (launches a doc from any app). I will post it later today, along with the FreeBasic source code so you can see how it works.

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Is it possible to launch Excel within a signal

Postby furytrader » 13 Jul 2011

Okay, attached is a .zip file that contains the code for being able to launch a document (Excel or otherwise) from inside EasyLanguage. Note that this code does not check to see if the document in question is already open.

The .zip contains three files:

1) "LaunchDoc.dll" - This is a .dll that should be saved on the "c:\" level of your hard-drive (i.e., "c:\LaunchDoc.dll"). The EasyLanguage function that calls this .dll refers to this specific name and file location, so if you want to save this .dll somewhere else on your system, change the file reference in the EasyLanguage function below.

2) "LaunchDocFiles.pla" - This is the EasyLanguage archive that contains the following:

(a) a function called "LaunchDocument" - this is what you call from your strategy to load up the document in whatever application you want. This function takes the following three parameters:

'AppPath' - This is the full path for the directory in which the application is loaded. So, for example, on my computer, the AppPath for Excel is: "c:\Program Files\Microsoft Office\Office\"

'AppName' - This is the file name of the application as an executable file. So, for example, Microsoft Excel would be 'Excel.exe'

'DocName' - This is the complete file name of the document you want to launch, including the path. So, if I had a document on the top level of my c:\ drive called 'Book1.xls', the 'docname' would be described as 'c:\Book1.xls'

(b) There is also an example indicator called "LaunchDoc" that simply shows this function in action. When you look at this code, note how it defines the AppPath, AppName, and DocName before calling the LaunchDocument function.

Also note that in the example indicator, you will see the following line:

Code: Select all

If Date = 1110707 Then value1 = LaunchDocument(vAppPath, vAppName, vDocName);
The term "value1 = " is simply used as part of the standard EasyLanguage convention for calling a function. We do not use value1 anywhere else in the program.

3) "LaunchDoc.bas" - This is the FreeBasic file which was used to create the .dll. I've included it so you can see what was involved with creating this functionality - it's actually pretty simple.

Let me know if you have any problems or concerns.
Attachments
LaunchDoc.zip
(13.58 KiB) Downloaded 146 times

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Is it possible to launch Excel within a signal

Postby sptrader » 14 Jul 2011

Possibly a macro program could be used...(Macroexpress etc)


Return to “MultiCharts”