brokerCommand (int Command, int Parameter): var

brokerCommand (int Command, string Text)

brokerCommand (int Command, var* Parameters)

Sets various broker plugin parameters or retrieves asset specific data for special purposes in a script. The functions can be optionally provided by the broker plugin; they return 0 when they are not supported or no broker connection is established. The number and types of parameters depend on Command. The following commands are predefined:
GET_TIME 0 Last incoming quote time in the server time zone, OLE DATE format.
GET_DIGITS Symbol   Number of relevant digits after decimal point in the price quotes.
GET_STOPLEVEL Symbol   The 'safety net' stop level of the last order (non-NFA accounts only).
GET_TRADEALLOWED Symbol   Trade is allowed for the asset.
GET_MINLOT Symbol   Minimum permitted amount of a lot.
GET_LOTSTEP Symbol   Step for changing lots.
GET_MAXLOT Symbol   Maximum permitted amount of a lot.
GET_MARGININIT Symbol   Initial margin requirements for 1 lot.


Symbol   Margin to maintain open positions calculated for 1 lot.
GET_MARGINHEDGED Symbol   Hedged margin calculated for 1 lot.
GET_COMPLIANCE 0   Account restrictions, a combination of the following flags: 1 - no partial closing; 2 - no hedging; 4 - FIFO compliance; 8 - no closing of trades; 15 - full NFA compliant account.
GET_SERVERSTATE 0   State of the broker server: 1 - server connected; 2 - server disconnected; 3 - server was temporarily disconnected since the last GET_SERVERSTATE command.
GET_NTRADES 0   Number of all open trades in this account.
GET_POSITION Symbol Net open contracts of the given symbol; negative values for short positions.
GET_ACCOUNT String   Fills the string with the account name.
GET_BOOK T2* Fill the T2 array with current quotes from the order book. The asset is set with SET_SYMBOL; bid prices are negative, the time field is optional. The last T2 element is set to 0 for indicating the end of the array. Returns the number of quotes.
GET_OPTIONS CONTRACT* Get the option chain of the underlying set with SET_SYMBOL (see remarks).
GET_FUTURES CONTRACT* Get the futures chain of the underlying set with SET_SYMBOL (see remarks).
GET_FOP CONTRACT* Get the options of futures chain of the underlying set with SET_SYMBOL (see remarks).
GET_UNDERLYING 0 Get the underlying price for the previous BrokerAsset call when the asset was an option.
GET_GREEKS Parameters   Get the greeks for the previous BrokerAsset or contractPrice call. Fills the Parameters array with P[0] = Implied Volatility; P[1] = Delta; P[2] = Gamma; P[3] = Vega; P[4] = Theta. Greeks cannot be retrieved with fast price type.
GET_DELAY 0   Return delay in ms between commands sent to the broker.
SET_DELAY Time in ms   Set delay in ms between commands sent to the broker.
GET_WAIT 0   Return maximum wait time for confirmation after a command was sent to the broker, in ms.
SET_WAIT Time in ms   Set maximum wait time in ms for confirmation after a command was sent to the broker. Default depends on the broker plugin; normally 60000. Increase the time when trades need longer than 1 minute to open.
GET_MAXTICKS 0 Return the maximum number of ticks to be filled by BrokerHistory2. If this command is not supported, it's 300 ticks.
GET_MAXREQUESTS 0 Return the maximum number of requests per second allowed by the broker API. Sets up MaxRequests if supported.
SET_DIAGNOSTICS 0, 1   1 to enable, 0 to disable diagnostics output. When enabled, communication between plugin and API and other plugin messages will be recorded in the log for diagnostic purposes.
GET_LOCK 0   Returns 1 if broker API calls must be locked for synchonizing them among several connected Zorros; returns -1 if broker API need not be locked. In this case the NOLOCK flag is automatically set.
SET_LOCK 0, 1   Set (1) or release (0) a lock for synchonizing commands among several connected Zorros (see remarks). Returns 0 if the lock was already set, otherwise 1.
SET_SLIPPAGE Pips   Set the maximum allowed slippage (default = 5 pips) in adverse direction for subsequently opening or closing trades. Higher allowed slippage causes less requotes, but allows trades to be entered at a worse price. Note that the allowed slippage is not guaranteed; trades can be still entered at higher slippage dependent on the brokerm, market access method, and server setup.
SET_SYMBOL Symbol Set the symbol for subsequent commands.
SET_MAGIC Number   Set a "magic number" for identifying trades opened by the current script.
SET_MULTIPLIER Number Set the multiplier for retrieving option and future chains.
SET_CLASS Name   Set the name of the trading class. Call this before setting the symbol for option and future chains; use an empty string ("") for retrieving all trading classes.
SET_AMOUNT Amount* pointer Sets the size of 1 contract for buy/sell orders; for assets with arbitrary order sizes.
SET_ORDERTEXT Text   Set an order comment (255 characters max). Often required for special MTR4 orders, f.i. for trading binary options.
SET_PATCH Patch value   Work around broker API issues that cause wrong account or asset parameters. Retrieve the following parameters not from the broker API, but from the asset list or by calculating them on the Zorro side (numbers can be combined by addition):
1  - Balance and Equity;
2  - TradeProfit of open trades;
4  - TradeProfit of all trades;
8  - Server time;
16 - Rollover and Commission;
32 - Leverage and MarginCost;
64 - PIP, PIPCost, LotAmount.
SET_HWND HWND Set Zorro's window handle; automatically called after login. The window handle can be used to trigger asynchronous events and send messages to Zorro with the PostMessage function.
SET_COMMENT Text   Display the given text (255 characters max) in the broker platform, usually at the top of the chart window.
SET_COMBO_LEGS 2, 3, 4 Declares the given number of following option trades as a combo order. Most brokers offer reduced margin and commission on combos. To use, set the combo leg number and immediately call the enter commands for the contracts. The order will be processed after the last enter command is received. If the order fails, the last enter will return 0. The script must then cancel the prior trades. All combo trades must have matching expiration dates  and underlying symbols; otherwise the order will not be accepted.
SET_ORDERTYPE 0, 1, 2. 8, 9, 10 Switches between order types when supported by the broker plugin:
0  - FOK (fill-or-kill, default)
1  - IOC (immedate-or-cancel)
2  - GTC (good-till-cancelled)
+8 - add a STOP order at distance Stop*StopFactor on NFA accounts (see remarks). 
GET_PRICETYPE 1, 2, 3, ...   Returns the type of prices returned by BrokerAsset and BrokerHistory2. 1 - ask/bid quotes; 2 - trades; 3 - special; 4 - no price available. The spread is normally only updated when ask/bid quotes are selected.
SET_PRICETYPE 1, 2, 3, ...   Determines the type of prices returned by BrokerAsset and BrokerHistory2, if applicable. 1 - ask/bid quotes; 2 - trades; 3 - special; 4 - no price requests; 8 - fast price requests.
GET_VOLTYPE 1, 2, 3, ...   Returns the type of volume data returned by BrokerAsset and BrokerHistory2. 1 - no volume; 2 - tick frequency; 3 - quote size; 4 - trade volume. 
SET_VOLTYPE 1, 2, 3, ...   Determines the type of volume data returned by BrokerAsset and BrokerHistory2, if applicable.
GET_VALTYPE 1, 2, 3, ...   Returns the type of marketVal data returned by BrokerAsset and BrokerHistory2. 1 - no data, 2 - spread; 3 - WAP.
SET_VALTYPE 1, 2, 3, ...   Determines the type of marketVal data returned by BrokerAsset and BrokerHistory2, if applicable.
GET_UUID String Copies the UUID of the last opened trade to the string.
SET_UUID String Sets the UUID for the next order from the string.
DO_EXERCISE Lots Exercise the given number of contracts of the option type set with SET_SYMBOL.
DO_CANCEL Trade ID Cancel the remaining amount of the order.
PLOT_HLINE Parameters   Place a horizontal line at a given price in the chart window of the broker platform. 5 parameters are used: P[0] = always 0; P[1] = price position; P[2] = line color; P[3] = line width; P[4] = line style. Return the identfier number of the line.
PLOT_TEXT Parameters   Place a text element at a price position at the right border of the chart window. 5 parameters are used: P[0] = always 0; P[1] = price position; P[2] = text color; P[3] = text size in points. Return the identfier number of the text element.
PLOT_MOVE Parameters   Move the graphical element with the identifier given by P[0] to the horizontal position given by P[1] and the vertical position given by P[2].
PLOT_STRING Text   Set or modify the text content for the last created or moved text element.
PLOT_REMOVE Identifier   Delete the graphical element with the given identifier.
PLOT_REMOVEALL 0   Remove all graphical elements from the chart.
2000..2999 var   User supplied command with a single numerical parameter.
3000..3999 var[8]   User supplied command with an array of 8 var parameters..
4000..5999 char*   User supplied command with a text string.


Command Input, one of the commands from the list above.
Parameter Input, parameter or data to the command.
Parameters Input, array of up to 8 vars for commands that set or retrieve multiple parameters.
Symbol Broker symbol of an asset (see Symbol). Complex symbols, as for selected option contracts, can have the underlying, exchange, expiry, and other parameters coded in the name as described under IB Bridge.
Text Input, for commands that require a text string.


0 when the command is not supported by the broker plugin, otherwise the data to be retrieved.

brokerAsset(string Name, var* pPrice, var* pSpread, var *pVol)

Call the BrokerAsset function with the symbol given by Name and return the price, spread, and volume.

brokerAccount(string Name, string Account, var *pBalance, var *pTradeVal, var *pMarginVal);

Call the BrokerAccount function for the account list entry given by Name and an optional subaccount identifer, and return the balance, open trade value, and allocated margin. Can be used to retrieve account information when trading with several brokers simultaneously.



brokerCommand(SET_COMMENT,strf("Algo %s",Algo));

See also:

Brokers, broker plugin, MTR4 bridge, FXCM plugin, IB plugin, Oanda plugin

► latest version online