There are probably tons of reasons, why someone would want to manipulate QuantShare from another application. Here are some examples: - You have an excel sheet with ticker symbols and some custom data. You would like to display the symbol's chart in QuantShare when clicking on the ticker symbol cell - Click on a button in excel to instruct QuantShare to do a scan and return a list of symbols that meet your criteria - You want to get a list of trades from your QuantShare portfolios in your own application How to send commands to QuantShare from Excel Let us take the first example described above and implement it. What we want is that when a user clicks on a button or cell in excel, QuantShare automatically updates the active chart with a specific ticker symbol. There are several ways to implement this (files, sockets...). We will use here a technique that consists of running "QuantShare.exe" file with some specific arguments. In these arguments, we will define an existing task to execute. - First, let us open QuantShare and create a script by selecting "Tools -> Script Editor". - Select "File -> New" then type "ChangeSymbol" as file name - In the script editor, type the following formula to update the active chart then save the script: string symbol = (string)Global.GetVariable("newsymbol"); Chart chart = Charts.GetSelectedChart(); if(chart != null) { chart.SymbolName = symbol; } In the first line, we got the new symbol from a global variable. We will see later how to set that global variable "newsymbol" from excel. The second step consists of creating a new task: - Select "Tools -> Task Manager" - Click on "Click here to add a task" - Select "App based task" tab (We just need to create a task that is never executed by the application without instructions from us) - In "Add Task" control and under "Scripts to be executed", click on "Add" then select "ChangeSymbol" script we have just created - Next to "Task Name", type "ChangeSymbol" then click on "OK" to save the task The third step would be to open Excel and implement the QuantShare call. - Open Excel and create a new document - Create a new button then associate a function to it (click event) More info can be found here: Add a button and assign a macro to it - Type the following code (macro): res = Shell("E:\Program Files\CTrading\QuantShare5\QuantShare.exe TaskManager ChangeSymbol newsymbol:" + Range("A2"), 1) Explanation: - The "Shell" function executes a specific file (QuantShare.exe for instance) - "TaskManager" is the first argument and it instructs QuantShare to use the task manager plug-in to execute the task specified in the second argument (ChangeSymbol) - The third argument instructs QuantShare to create a global variable "newsymbol" and set its value with the content of cell A2 (Range function) Now, you can type a ticker symbol in the cell "A2" and click on the button to update QuantShare's active chart. Note that you can define several global variables by separating them with a semi-colon. Example: newsymbol:GOOG;var2:Test This command instructs QuantShare to create two global variables (newsymbol and var2) and associates them with the following values (GOOG and Test).
|