Volumen 4
Volumen 4
Volumen 4
The RTD app can also be used to send simple trading commands from VBA code in
Excel. You can also programmatically read the same data which is available via the
RTD function.
The following features can in fact be used from any programming language which
supports COM, not just from VBA in Excel.
The property names for the Read() function are the same as the property names for
use with Excel’s RTD function.
You can successfully create the ExcelReader object and call the Connect() function
even if no RTD app is currently running for that account.
In order to check whether data is actually available you can use Read() to make sure
that properties such as balance are not blank, or you can read the LastUpdateTime
property and check that the time is later than 1/1/2000.
If you are querying multiple pieces of data, particularly multiple pieces of ticket data,
then you need to be careful about updates and data consistency. For example,
consider the following code which loops through the ticket list:
Page 19 of 26
www.pepperstone.com Excel RTD
For i = 1 To reader.Read("tickets")
strSymbol = reader.Read("t" & i & "s")
vVolume = reader.Read("t" & i & "v")
Next
Reader.ReaderLock()
For i = 1 To reader.Read("tickets")
strSymbol = reader.Read("t" & i & "s")
vVolume = reader.Read("t" & i & "v")
Next
Reader.ReaderUnlock()
You can send simple commands from Excel using the FXBlueLabs.ExcelCommand
object. For example:
Page 20 of 26
www.pepperstone.com Excel RTD
SendCommand() is synchronous. It returns either when the RTD app completes the
command, or when the timeout period expires. (Timeout does not mean that the
request such as a market order has been withdrawn/cancelled. It only means that
the broker/platform has not responded within the acceptable time.)
The return value from SendCommand() is a string, beginning either with ERR: to
indicate that an error occurred, or with OKAY:. The only exception to this is the TEST
command, which returns the text HELLO.
There are some minor differences in the trading features which are currently
supported on different platforms:
• "Magic numbers" are only valid for MT4 and MT5, and these parameters will
be ignored on other platforms.
• Order comments are only available on some platforms.
• Stop-losses and take-profits are not currently supported on tradable
Trading volumes are always specified as cash amounts, not as lot sizes. The format
of symbol names depends on whether the "Use standardised symbol names" option
is turned on in the RTD app.
Page 21 of 26
www.pepperstone.com Excel RTD
Submits buy or sell market orders. If successful, it returns the ID of the new ticket in
the form OKAY:ticket-number
Submits a new pending order. If successful, it returns the ID of the new ticket in the
form OKAY:ticket-number
Page 22 of 26
www.pepperstone.com Excel RTD
Reverses an open position, e.g. closing an open sell and replacing it with a buy.
Returns OKAY:okay if successful.
Closes all open positions and pending orders for a specific symbol. Returns
OKAY:okay if successful.
Page 23 of 26
www.pepperstone.com Excel RTD
Closes all open positions and pending orders for all symbols. Returns OKAY:okay if
successful. Please note that closing everything can require a substantial timeout.
For example:
Changes both the stop-loss and take-profit on an open trade or pending order. For
pending orders, you can also alter the entry price.
Page 24 of 26
www.pepperstone.com Excel RTD
Property Meaning
ERR:Need account Account value for SendCommand() is blank
ERR:Need command Command value for SendCommand() is blank
ERR:No listening app Cannot find an running instance of the RTD app
for the specified account
ERR:No response within No response from the broker/platform within the
timeout specified number of seconds
ERR:Commands not The "Allow commands" option is not turned on
allowed in the RTD app
ERR:Unrecognised The command value for SendCommand() is not
command understood by the RTD app
ERR:Missing parameters The command was missing one or more
compulsory parameters
For example:
Page 25 of 26