Excel RTD
Set up alerts and notifications with the Trader Tools Alarm Manager, carry out automated actions, such as opening and closing positions. Customise which action you want your alarm to trigger.
Set up alerts and notifications with the Trader Tools Alarm Manager, carry out automated actions, such as opening and closing positions. Customise which action you want your alarm to trigger.
The Excel RTD app lets you do two things:
• Put real-time data into Excel using only Excel’s RTD() function. No macros; no programming; no XLL add-ins
• Send simple trading commands from VBA code in Excel
You can run multiple copies of the Excel RTD app for different accounts, and then combine the data for those accounts in a single spreadsheet.
The app is supplied with an example spreadsheet which lets you enter up to 5 account numbers, and then automatically displays a dashboard of equity and balance etc; symbol prices; and a consolidated list of open positions.
2.1 Running the RTD app
In order to put real-time data into Excel you need to run the RTD app. The Excel formulas listed below will give blank values if the app is not running.
2.1.1 Available symbols
Information about the following symbols will be available in the Excel RTD app:
• MT4/5
: the app will report all the symbols which are included in the MT4/5 market watch
• Tradable
: the app will report all available symbols in the platform
• All other platforms:
you configure which symbols the app reports using the app’s Symbols menu.
2.2 Excel formula
Once the RTD app is running, you can use the following formula in Excel to insert a realtime feed of account, ticket, or price data. You simply need to fill in the account number, and the “property” which you want to display:
=RTD(«FXBlueLabs.ExcelRTD», , "account number", "property")
For example, if your account number is 156734 and you want to display the account’s balance, or the bid price of GBPUSD:
=RTD(«FXBlueLabs.ExcelRTD», , «156734», «balance»)
=RTD(«FXBlueLabs.ExcelRTD», , «156734», «bidGBPUSD»)
Please note : with some language settings – for example, Polish – Excel may want the sections of the formula to be separate by semi-colons instead of commas. For example:
=RTD(«FXBlueLabs.ExcelRTD»; ; "account number"; "property")
2.3 Property names
The RTD app supplies data about the account (e.g. equity and balance), symbol prices, “tickets“, bar history, and technical indicator values. The list of tickets includes both open positions and pending orders.
2.3.1 Account data properties
2.3.2 Price and symbol data properties
The app supplies the current ask and bid prices for all symbols configured in the app. For example, if the symbol name you are interested in is EURUSD, then the property name for its ask price is askEURUSD. For example:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “askEURUSD“)
The app also provides a count and a list of all configured symbols. For example, the following formulas return the number of available symbols and the name of the 5th symbol on the list (which can be in any order):
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “symbols“)
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “s5“)
2.3.3 Ticket data properties
The app supplies the following information about each “ticket“, i.e. each open position and pending order. The N value in each property name is an index between 1 and the total number of tickets (reported by the tickets property).
For example, you can get the symbol name and net profit of the 2nd ticket (if there is one) using the following formulas:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “t2s“)
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “t2npl“)
2.3.4 Bar history
You can use the Excel RTD app to request recent price history from the platform. All values are bid prices. (Please note that this price history is not available on the tradable platform.)
The property name for bar history is as follows: @bh,symbol,timeframe,data,shift. For example, the following formula shows the high of the current EUR/USD H1 bar:
=RTD(“FXBlueLabs.ExcelRTD“, ,“156734“, “@bh,EURUSD,H1,high,0“)
2.3.4.1 Timeframe value
The bar timeframe can either be specified as a number of minutes – e.g. 60 for hourly bars – or you can use standard notations such as H1 or M3. The available timeframes are as follows:
2.3.4.2 Price data
You can request the following information about each bar:
2.3.4.3 Bar shift
The final part of the price history formula is the bar “shift“, i.e. which bar to get information about. Bars are numbered with the newest at zero, and increasing in order of age. In other words, bar 0 is the current in-progress bar; bar 1 is the last complete bar etc.
Therefore, the close price on bar 0 (for any timeframe) is the current bid price. In effect, the following two formulas are identical:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “bidGBPUSD“)
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@bh,GBPUSD,60,close,0“)
The amount of data available on each timeframe depends on the underlying platform, but will typically be around 250 bars.
2.3.5 Technical indicators
The Excel RTD app has some built-in indicator calculations which you can request using formulas. For example, the following formula will show 14-bar Relative Strength Index for GBP/USD M5:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@rsi,GBPUSD,M5,14,0“)
Please note that the technical indicators are not available on the tradable platform.
The property name for a technical indicator starts with an indicator name such as @rsi or @ema, and is then followed by a list of parameters separated by commas.
The first two parameters for an indicator are always the symbol name and the timeframe, which can be specified either as H2 or as the equivalent number of minutes such as 120.
The last parameter is always the bar “shift“. You will normally want to use a value of 0 for the shift, in order to get the current indicator value, but you can also use a shift of e.g. 1 to get the value of the indicator at the end of the previous bar. (The only exception are the swingpoint indicators, which always return the latest swing point and do not use a shift parameter.)
Many indicators can be applied to different data values from each bar, e.g. the high price or even the bar range instead of the close price.
Please bear in mind that exponential moving averages and similar calculations are affected by the amount of available bars. For convenience, everyone always refers to the N value in such calculations as “N bars“ (e.g. “21-bar EMA“), but this is not what it truly means. The N is a weighting factor, and a calculation such as an EMA always looks at the entire bar history which it has collected, but giving increased weight to the most recent N bars. Two calculations of an EMA can be different – though only usually by small amounts – if they are using different amounts of bar history.
2.3.5.1 @sma – Simple Moving Average
You can calculate a simple moving average (i.e. arithmetic mean) using the @sma indicator.
For example, the following formula does an average of the median prices for the last 10 bars on GBP/USD M5:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@sma,GBPUSD,M5,median,10,0“)
The indicator’s parameters are as follows:
2.3.5.2 @ema – Exponential Moving Average
You can calculate an exponential moving average using the @ema indicator. For example, the following formula does an average of the ranges of the last 21 bars on GBP/USD D1:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@ema,GBPUSD,1440,range,21,0“)
The indicator’s parameters are as follows:
2.3.5.4 @lwma – Linear-Weighted Moving Average
You can calculate a linear-weighted moving average using the @lwma indicator. For example, the following formula does an average of the ranges of the last 21 bars on GBP/USD D1:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@lwma,GBPUSD,1440,range,21,0“)
The indicator’s parameters are as follows:
2.3.5.5 @macd and @macdsig – MACD
You can calculate MACD (the difference between a “fast“ EMA and a “slow“ EMA) using the @macd indicator. You can also use @macdsig to get the smoothed “signal“ value of the MACD indicator.
For example, the following formula calculates MACD for GBP/USD M30, using the standard 12-bar fast EMA and a 26-bar slow EMA, and applying the calculation to the high price of each bar:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@macd,GBPUSD,30,high,12,26,9,0“)
The indicator’s parameters are as follows:
2.3.5.6 @atr – Average True Range
You can calculate average true range using the @atr indicator. For example, the following formula calculates the average true range of the last 21 bars on GBP/USD D1:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@atr,GBPUSD,D1,21,0“)
The indicator’s parameters are as follows:
2.3.5.7 @rsi – Relative Strength Index
You can calculate Relative Strength Index using the @rsi indicator. For example, the following formula calculates 14-bar RSI on USD/JPY M3:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@atr,USDJPY,3,14,0“)
The indicator’s parameters are as follows:
2.3.5.8 @stoch and @stochslow – Stochastic Oscillator
You can calculate the stochastic oscillator using the @stoch indicator. You can also calculate the slowed “signal“ value for the indicator using @stochslow.
For example, the following formula calculates the oscillator on GBP/USD H2 bars, using standard parameters of (5,3,3) – i.e. K period of 5, D period of 5, slowing value of 3.
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@stoch,GBPUSD,120,5,3,3,0“)
The indicator’s parameters are as follows:
2.3.5.9 @bbupper and @bblower – Bollinger bands
You can calculate “Bollinger“ bands – a simple moving average plus/minus a number of standard deviations – using the @bbupper and @bblower indicators.
For example, the following formula calculates the upper band on GBP/USD M10, using an average of the close prices on the last 30 bars, and 2 standard deviations:
=RTD(“FXBlueLabs.ExcelRTD“, , “156734“, “@bbupper,GBPUSD,10,close,30,2,0“)
The indicator’s parameters are as follows:
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.
3.1 Reading data in VBA code
You can read data programmatically using the FXBlueLabs.ExcelReader object. For example:
Set reader = CreateObject(“FXBlueLabs.ExcelReader“)
reader.Connect (“156734“)
MsgBox reader.Read(“balance“)
In other words: you create an instance of the XBlueLabs.ExcelReader object; you use the Connect() function to link it to a specific account number; and then you can use the Read() function to get data about the account.
The property names for the Read() function are the same as the property names for use with Excel’s RTD function.
3.1.1 Checking if a reader is successfully connected
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.
3.1.2 Data consistency across multiple reads
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:
For i = 1 To reader.Read(“tickets“)
strSymbol = reader.Read(“t“ i “s“)
vVolume = reader.Read(“t“ i “v“)
Next
It is possible for the following to happen:
• At outset there are 2 open tickets
• Between the two uses of Read(), i.e. between the execution of lines 2 and 3, one of the tickets is closed.
• Therefore, what used to be ticket 2 becomes ticket 1.
• As a result, at the end of the first loop, strSymbol will hold the symbol of the ticket which is now closed, and vVolume will hold the volume of the ticket which is still open.
To ensure consistency while reading multiple pieces of data, use Reader.ReaderLock(). This will suspend any changes to the data until you then use Reader.ReaderUnlock(). For example:
Reader.ReaderLock()
For i = 1 To reader.Read(“tickets“)
strSymbol = reader.Read(“t“ i “s“)
vVolume = reader.Read(“t“ i “v“)
Next
Reader.ReaderUnlock()
Don’t forget to call ReaderUnlock() after using ReaderLock()…
3.2 Sending trading commands from Excel
As a security measure, commands are turned off by default. You must turn on the “Accept commands“ setting in the RTD app in order to send commands successfully. If this option is turned off then all commands will return “ERR:Commands not allowed“.
You can send simple commands from Excel using the FXBlueLabs.ExcelCommand object.
For example:
Set cmd = CreateObject(“FXBlueLabs.ExcelCommand“)
strResult = cmd.SendCommand(“156734“, “BUY“, “s=EURUSD|v=10000“, 5)
The SendCommand() function has four parameters:
• The account number (e.g. 156734)
• The command, e.g. BUY
• Parameters for the command, e.g. symbol and volume to buy
• The number of seconds to wait for a response
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.
3.2.1 Differences between trading platforms
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
3.2.2 Commands and parameters
The parameters for a command are sent as a pipe-delimited string, consisting of a number of settings in the format name=value. The parameters can be listed in any order, and some parameters are optional.
cmd.SendCommand(“156734“, “BUY“, “s=EURUSD|v=10000“, 5)
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.
3.2.2.1 TEST command
Simply returns the text HELLO if successful.
3.2.2.2 BUY and SELL commands
Submits buy or sell market orders. If successful, it returns the ID of the new ticket in the form OKAY:ticket-number
3.2.2.3 BUYLIMIT, SELLLIMIT, BUYSTOP, and SELLSTOP commands
Submits a new pending order. If successful, it returns the ID of the new ticket in the form OKAY:ticket-number
3.2.2.4 CLOSE command
Closes an open position or deletes a pending order. Returns OKAY:okay if successful.
3.2.2.5 PARTIALCLOSE command
Does a partial-close of an open position. Returns OKAY:okay if successful. Volumes larger than the position size are simply treated as a full close (not as a close plus a reverse for the remaining amount). Cannot be used on pending orders.
3.2.2.6 REVERSE command
Reverses an open position, e.g. closing an open sell and replacing it with a buy. Returns OKAY:okay if successful.
3.2.2.7 CLOSESYMBOL command
Closes all open positions and pending orders for a specific symbol. Returns OKAY:okay if successful.
3.2.2.8 CLOSEALL command
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:
cmd.SendCommand(“156734“, “CLOSEALL“, ““, 20) ' 20-second timeout
3.2.2.9 ORDERSL command
Changes the stop-loss on an open trade or pending order. Returns OKAY:okay if successful.
3.2.2.11 ORDERMODIFY command
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.
3.2.3 Standard error messages
3.3 Asynchronous commands
It is also possible to send commands asynchronously rather than blocking execution of the VBA code until the command completes or times out. This works as follows:
• You use SendCommandAsync() instead of SendCommand().
• You periodically check the result of the asynchronous action using CheckAsyncResult().
• When finished (or when you have decided to give up) you free up the command memory using FreeAsyncCommand()
For example:
Set cmd = CreateObject(“FXBlueLabs.ExcelCommand“)
lCommandId = cmd.SendCommandAsync(“10915“, “BUY“, “s=EURUSD|v=10000“, 60)
strResult = ““
While strResult = ““
strResult = cmd.CheckAsyncResult(lCommandId)
If strResult = ““ Then MsgBox “Still waiting...“
Wend
cmd.FreeAsyncCommand (lCommandId)
SendCommandAsync uses the same four parameters as SendCommand(), but returns a “command ID“ for subsequent use with CheckAsyncResult() and FreeAsyncCommand(), instead of returning the command result. Please note that SendCommandAsync() still has a timeout value.
You must eventually call FreeAsyncCommand() after SendCommandAsync(), or else your code will leak memory, albeit in small amounts.
CheckAsyncResult() either returns a blank string if the command is still executing and has not reached its specified timeout or, if complete, it returns the same string response as SendCommand().
注册即表示您同意FP Markets的隐私政策,并同意未来接收FP Markets的营销材料。您可随时取消订阅。
工具和平台