Populate the current offers from TS into Excel using DDE

Strategies are published here.

Moderator: admin

Populate the current offers from TS into Excel using DDE

Postby Nikolay.Gekht » Mon May 09, 2011 12:19 pm

The DDE (Dynamic Data Exchange) is a windows service, which helps to populate the data from one application into another.

To put data via DDE in excel, all you need is to enter the following formula into the excel cell:
=A|B!C
where
A is a service name
B is a topic
and
C is a value.

So, all you need is a service which publish the current offer data via DDE.

The Trading Station or Lua themselves do not support DDE, so you need an extension module for Lua which provides DDE services.

I developed such extension, you must download and install it before using the DDE offers publishing strategy:
ddeserver_lua.dll
(18.5 KiB) Downloaded 1250 times


To install the extension module:
1) Save the ddeserver_lua.dll file to your computer.
2) Copy the file into:
* "C:\Program Files\Candleworks\FXTS2\" folder if you use a 32 bit operating system
or
* "C:\Program Files (x86)\Candleworks\FXTS2\" folder if you use a 64 operating system

That's all, the extension is ready to be used in this or other strategies.

Now download and install (as described here on wiki: http://fxcodebase.com/wiki/index.php/Cu ... arketscope) the DDE_Offers.lua strategy:

dde_offers.lua
(2.3 KiB) Downloaded 1049 times


Now you can launch DDE_Offers strategy and just watch the data in Excel (click on the image to see it in full size):
dde_offers.png


Note 1: The strategy has just one parameter - the name of the service. Each DDE publishing strategy you are executing must have its unique name. However, you can run as many DDE publishing strategies as you need, just put the new service name every time when you start another one strategy.

Note 2: The strategy populates the following data:

1) =TS2OFFERS|OFFERS!LIST
(if you changed the name of the service, use it instead of TS2OFFERS in the formulas!, for example is the service name you entered in the strategy parameters is MYOFFERS, the formula must be =MYOFFERS|OFFERS!LIST).

The semicolon-separated list of the topics. A topic is created for each instrument you are subscribed. The non-character symbols (such as / (slash)) are replaced with an underscore. So, for example EUR/USD offer will be translated as EUR_USD topic.

2) Each offer's topic has the following values:
BID - current bid price
ASK - current ask price
TIME - date and time of the last price change.
DIGITS - precision of the offer's prices.

For example to get a bid price of the EUR/USD, you must enter:
=TS2OFFERS|EUR_USD!BID

3) Please note, that the date and time is populated as a number. But, Trading Station and Excel uses exactly the same date/time format, so all you need is to change the cell format to date/time (for example to m/d/yy hh:mm:ss), and the date/time will be displayed properly.

4) The date/time is always in EST/EDT (New York) time zone

5) The prices are updated every second.

Additional Material:

1) Source code of the strategy:
Code: Select all
function Init()
    strategy:name("DDE Offer")
    strategy:description("Publishes Offers via DDE")

    strategy.parameters:addString("SRV", "Service Name", "The service name must be unique amoung all running instances of the strategy", "TS2OFFERS");
end

require("ddeserver_lua");

local dde_server;
local ids = {};
local timeid;

function Prepare(onlyName)
    instance:name(profile:id() .. "(" .. instance.parameters.SRV .. ")");
    if onlyName then
        return ;
    end

    -- start dde server
    dde_server = ddeserver_lua.new(instance.parameters.SRV);
   
    local enum = core.host:findTable("offers"):enumerator();
    local row, topic;
    local offers, offer;
    -- create topics
    offers = "";
    local ofr, val;
    while true do
        row = enum:next();
        if row == nil then
            break ;
        end
        topic = {};
        offer = string.gsub(row.Instrument, "([^A-Za-z0-9])", "_");
        offers = offers .. offer .. ";";

        topic.id = dde_server:addTopic(offer);

        topic.bid = dde_server:addValue(topic.id, "Bid");
        topic.ask = dde_server:addValue(topic.id, "Ask");
        topic.time = dde_server:addValue(topic.id, "Time");

        val = dde_server:addValue(topic.id, "Digits");
        dde_server:set(topic.id, val, row.Digits);
        ids[row.Instrument] = topic;
    end

    ofr = dde_server:addTopic("OFFERS");
    val = dde_server:addValue(ofr, "LIST");
    dde_server:set(ofr, val, offers);

    timerid = core.host:execute("setTimer", 1, 1);

end

function Update()
end

function AsyncOperationFinished(cookie, success, msg)
    if cookie == 1 then
        local enum = core.host:findTable("offers"):enumerator();
        local row, topic;
        -- create topics
        while true do
            row = enum:next();
            if row == nil then
                return ;
            end
            topic = ids[row.Instrument];
            if topic ~= nil then
                dde_server:set(topic.id, topic.bid, row.Bid);
                dde_server:set(topic.id, topic.ask, row.Ask);
                dde_server:set(topic.id, topic.time, row.Time);
            end
        end
    end
end

function ReleaseInstance()
    core.host:execute("killTimer", timerid);
    dde_server:close();
end


2) the source code of ddeserver_lua extension (Visual C++). Please note that you will need Indicore Integration SDK (see here: http://fxcodebase.com/wiki/index.php/Ca ... grationSDK) to compile that code.
luadde.zip
(7.76 KiB) Downloaded 845 times


3) How to use ddeserver_lua in your own strategy (or indicator)

Step 1) Deploy ddeserver_lua.dll into the same folder where the application is deployed (for TS see instruction above, for Indicore SDK - deploy to C:\Gehtsoft\IndicoreSDK\, for your own application - put into the same folder where lua5.1.dll is located).

Step 2) Add require("ddeserver_lua"); before Prepare() function.

Step 3) Declare a global variable for the server, e.g. local dde_server before Prepare() function.

Step 4) In the Prepare() function, when onlyName parameter is false:
a) create an instance of the dde server and give the service an unique name. This value shall be used as first part of the DDE reference, e.g. for the code below, all DDE references will be started with MYSERVICENAME.

dde_server = ddeserver_lua.new("MYSERVICE");

b) Register topic and value inside the topic, keep the identifiers of the topic and value for further usage:

topic = dde_server:addTopic("MYTOPIC");
value = dde_server:addValue(topic, "MYVALUE");

where topic and value are global variables.

Now, your value is available from Excel as =MYSERVICE|MYTOPIC!MYVALUE.

Step 5). Set the value whereever you need.

dde_server:set(topic, value, 12345);

The value can be either a number or a string.

Step 6) Implement ReleaseInstance() function and call dde_server:close() in this function.
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1222
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Populate the current offers from TS into Excel using DDE

Postby ancient-school » Thu Jun 02, 2011 7:08 am

Could you please provide for Access to the following Info:

1 - MMR
2 - Pip Cost
3 - High
4 - Low
5 - Account
6 - Balance
7 - Equity
8 - Used Margin
9 - Usable Margin
10 - Gross P/L

Thank You ...
Going for it is more important than winning or losing!
User avatar
ancient-school
 
Posts: 20
Joined: Tue Apr 13, 2010 1:56 pm

Re: Populate the current offers from TS into Excel using DDE

Postby luigifx » Tue Jun 14, 2011 2:16 pm

It would be really great if we can access to this information asked by ancient-school.

Thanks
luigifx
 
Posts: 10
Joined: Tue Jun 14, 2011 2:11 pm

Re: Populate the current offers from TS into Excel using DDE

Postby sunshine » Sun Jul 17, 2011 8:18 am

luigifx wrote:It would be really great if we can access to this information asked by ancient-school.

Thanks


You can access to the accounts through the dde_accounts strategy (see the attachment).
The strategy populates the following data:

1) =TS2ACCOUNTS|ACCOUNTS!LIST
The semicolon-separated list of the topics. A topic is created for each account.

2) Each account's topic has the following values:
BALANCE - account balance
EQUITY - account equity balance
USEDMARGIN - account used margin
USABLEMARGIN - account usable margin
GROSSPL - account gross P/L

For example to get a Gross P/L for account 01380757, you must enter:
=TS2ACCOUNTS|01380757!GROSSPL

Also in the attachment you can find the modified "dde_offers.lua" which provides access to pip cost, high and low.
Attachments
dde_accounts.lua
(2.8 KiB) Downloaded 714 times
dde_offers_adv.lua
(2.83 KiB) Downloaded 694 times
sunshine
 

Re: Populate the current offers from TS into Excel using DDE

Postby BlueBloodedTrader » Sun Sep 18, 2011 5:40 pm

This is an absolutely awesome tool, but it would be far more powerful tool if it allowed more detailed information to be grabbed from the trading station or better still from the charting software.

For example, if I want to run algorithms in Excel for the purpose of trading then information that would be useful would include:

OPEN PRICE
CLOSE PRICE
MOVING AVERAGE
HIGHS AND LOWS USING DNC CHANNELS
ATR
etc.

Is there anyway of further developing this tool in order to allow data to be grabbed from the charting package Marketscope 2.0 ? This would allow you to grab data from any indicator installed on the charting package.

Thanks for the great work guys!
BlueBloodedTrader
 
Posts: 11
Joined: Tue Feb 15, 2011 6:02 pm

Re: Populate the current offers from TS into Excel using DDE

Postby sunshine » Tue Sep 20, 2011 7:12 am

BlueBloodedTrader wrote: information that would be useful would include:

OPEN PRICE
CLOSE PRICE

Could you please explain what do you mean by Open/Close prices?
As far as I understand, the strategy could have the parameter 'Timeframe'. 'Open' price is the open price of the current period for the selected timeframe. 'Close' is the current Bid/Ask price. Is that correct?
By the way, currently Bid/Ask prices are available through the dde_offers.lua strategy.

BlueBloodedTrader wrote:
MOVING AVERAGE
HIGHS AND LOWS USING DNC CHANNELS
ATR
etc.

Please explain which data you would like to get. Is this just current indicator value or the last N indicator values?
sunshine
 

Re: Populate the current offers from TS into Excel using DDE

Postby zmender » Sat Dec 10, 2011 11:36 am

Would it also be possible to do the reverse?

More specifically, I want to maintain historical database of SSI that is published on dailyfx+. Have tradestation pull in the data from excel and plot it up as an indicator.
zmender
 
Posts: 43
Joined: Thu Nov 10, 2011 11:00 pm

Re: Populate the current offers from TS into Excel using DDE

Postby alpha_bravo » Wed Oct 24, 2012 7:17 am

Could anyone give me an example of how to populate data from excel into Merketscope. For example, if i had a live bid in excel, and i wanted that price denoted by a horizontal line in marketscope? Any chance? Just one line into marketscope?

cheers.
alpha_bravo
 
Posts: 49
Joined: Thu Jan 13, 2011 3:51 pm

Re: Populate the current offers from TS into Excel using DDE

Postby ddrrbb » Sun Mar 24, 2013 9:02 pm

Is it possible to load historical prices into excel with this strategy? Right now, I manually load prices into excel at the end of the day.
ddrrbb
 
Posts: 9
Joined: Wed Feb 22, 2012 6:10 pm

Re: Populate the current offers from TS into Excel using DDE

Postby sunshine » Tue Mar 26, 2013 8:25 am

Yes, it should be possible. I have forwarded the issue to the developers. I hope they will prepare the example.
sunshine
 

Next

Return to Custom Strategies

Who is online

Users browsing this forum: No registered users and 7 guests