asset (string Name) : int
Selects an asset from the asset list, and loads its price
history in the initial run from the broker or historical data.
Price and trade functions, and asset related variables (Spread,
Symbol, AssetVar etc.) are automatically
switched to the new asset. This way different assets can be compared for arbitraging
or correlation indicators, or a script can trade multiple assets simultaneously.
Must be called in the first run (INITRUN)
of the script.
||The name of the asset, as in the asset list
or the [Asset] selector. An empty string
"" creates a dummy asset, a name beginning with
'#' prevents loading price history. Up to 15 characters,
with no blanks and no special characters except for slash '/' and underline
0 when the Name string is NULL
or empty, or when the asset or its prices are not available; otherwise nonzero.
asset("EUR/USD"); switches to the EUR/USD pair.
assetAdd (string Name)
assetAdd (string Name, string Symbol)
assetAdd (string Name, var Price, var Spread, var RollLong, var RollShort, var
PipVal, var PipCost, var MarginCost, var Leverage, var LotAmount, var Commission,
Adds a new asset to the asset list and to the [Asset]
scrollbox. The asset is selected, but its history is not yet loaded. If the
asset already exists in the list, its parameters are updated when
assetAdd was called in
the INITRUN of the script; afterwards the
parameters are ignored. For creating a dummy asset for test purposes, set Name to
"DUMMY" - this generates artificial bars with a flat
price history. Selecting an asset before loading its price history can be useful
f.i. when asset specific parameters like Centage must
be set that affect the history download.
||Name of the asset
||Symbol of the asset, with optional source, in the format described under
||Optional asset parameters as described under asset
list. When at 0, the parameter is not changed.
assetList (string Filename, string Select): int
Loads an alternative asset list and adds its assets to
the [Asset] scrollbox. Sets the optional Select
asset in the scrollbox on the first run; on subsequent runs the user can select
different assets. Assets used in the script must be either in that list or added
by script with assetAdd. The asset list must be loaded in the first
run (INITRUN) of the script.before its assets
can be selected. If this function is not called, the default asset list given in
Zorro.ini is used.
||File name of the asset list, f.i. "AssetsIB".
The .csv extension and the path can be omitted for asset
lists in the History folder.
||Name of the asset to be selected in the scrollbox at first run, f.i.
"EUR/USD". 0 for not selecting
Number of loaded assets, or 0 when no assets were loaded. The number
of assets is also available through NumAssetsListed.
Sets the [Asset] scrollbox to the current asset.
assetType (string Name) : int
Attempts to determine the type of an asset from its name. If the name begins with
the 3-letter abbreviation of a currency, it is identified as Forex; if it ends with
a 2- or 3-digt number, it is identified as an index.
0 when the type can not be identified; otherwise FOREX
(1) or INDEX (2).
- The place of an asset call (if any) in the script
matters. All variables and flags that affect the creation of bars, such as
History etc. must be set before
calling asset(). Otherwise the simulation period is unknown at
asset loading and either a default period is used, or the script will produce
an Error 030 message. All parameters specific to an
asset, such as Spread,
Commission, etc., as well as all functions that use asset parameters or
prices, such as price(),
optimize(), advise(), etc.
must be used after calling asset().
- Calling asset by script is not
the same as selecting the asset with the Asset
scroll box. If the script contains no asset call, the scroll
box asset is selected _after_ the INITRUN, and its name
is appended to the training files for being able
to train different assets separately. Call asset(Asset) for
loading the asset selected by the Scrollbox already in the
- In multi-asset scripts the order of asset()
calls matters. Bars are created from the historical ticks of the first asset.
Gaps in the price history of the first asset are therefore reflected in the price
data of all further assets. When BR_FLAT is not
set, price histories have normally gaps during weekends, holidays, or outside market hours. Therefore
select first the asset with the most complete price history (for
instance, a currency pair that is traded 24 hours). When a subsequent asset
has a gap where the first asset has none, the gap is filled from the price
data of previous bar. This produces a different price curve and can cause indicators
to behave differently in multi-asset portfolios, dependent on asset order.
Otherwise use BR_FLAT or don't combine assets with different
- Every asset call switches the asset
parameters, asset variables,
trade statistics and OptimalF
factors to the values of the selected asset. At begin of the simulation,
asset parameters are loaded from the
asset list. If the asset is not found in the list,
an error message will be displayed and defaults are substituted for the asset
- If an asset call fails, the failed asset is not
selected and 0 is returned. Check the return value to make
sure that only valid and available assets are traded.
- Any asset can have up to 3 different symbols
and 3 different sources for trading, for live prices, and for historical prices.
The symbols can be given in the Symbol field in the
asset list, or by script in the
SymbolHist parameters. The current asset name is stored
in the Asset string.
- The Assets array contains the names of all available
assets. For selecting all assets of the
asset list in a loop, use
while(asset(loop(Assets))). For enumerating them without
loop call, use for(used_assets)
- The trading time of an asset can be set up with
AssetZone, AssetMarket, and
AssetFrame. Trading can be restricted to market
times with the BR_LEISURE flag.
- Artificial assets can be created by combining
the prices from a 'basket' of several real assets (see example).
- By passing an empty string (asset("")), a
dummy asset is created with all prices at
1. This is useful when a real asset is not needed, f.i. for
testing filters or indicators with artificial price curves.
- When loading price data, the prices are checked for plausibility dependent
on the Outlier parameter. If a bar has invalid data,
such as extreme outliers or prices at zero, it is automatically corrected. Setting
Detrend = NOPRICE; before calling
asset() prevents that asset and price data is checked and outliers
- If only a single asset is selected in the script, the [Asset]
scrollbox is automatically set to that asset. If multiple assets are selected,
the [Asset] scrollbox is unchanged and can be used
to determine the price curve in the resulting chart.
- For adding new assets to the available asset
set, see the description under Asset List.
- Assets must be subscribed before their prices are available. The
asset function subscribes the asset automatically, but some brokers
have a limit to the number of subscribed assets. Some platforms, for instance
MT4, need a long time after subscribing an asset
before prices are available.
- Any asset requires memory. The memory requirement
in bytes can be estimated with the formula Years / BarPeriod * 15 MB,
where Years is the number of backtest years (use 1
for live trading). The LEAN and LEANER
flags reduce the memory requirement by about 50%, the TICKS
flag increases it by 32 bytes per historical price quote.
plot commands allocate 8..24 bytes per bar.
- When backtesting large time periods with multiple assets and high
resolution data, the memory requirement for all assets can exceed the
available memory. In that case NumTotalCycles
can be used for testing any asset separately in its own cycle, and exporting
or summing up the separate results.
// trade multiple strategies and assets in a single script
BarPeriod = 240;
StartDate = 2010;
set(TICKS); // set relevant variables and flags before calling asset()
// call different strategy functions with different assets
// For adding a new asset to the [Assets] scrollbox,
// click [Trade] with the script below.
// Then edit History\AssetsFix.csv and copy the line
// beginning with "Copper" over from History\Assets.csv.
asset("Copper"); // add "Copper" to assets.csv
// Basket trading - generate a snythetic asset "USD"
// combined from the USD value of EUR, GBP, and AUD
var p = 0;
asset("GBP/USD"); p += price();
asset("AUD/USD"); p += price();
asset("EUR/USD"); p += price();
// basket trade function with stop limit
int tradeUSD(var StopUSD)
if((TradeIsLong && priceUSD() <= StopUSD)
or (TradeIsShort && priceUSD() >= StopUSD))
return 1; // exit the trade
else return 0; // continue the trade
// open a trade with the synthetic asset and a stop loss
void enterLongUSD(var StopDistUSD)
var StopUSD = priceUSD()-StopDistUSD;
void enterShortUSD(var StopDistUSD)
var StopUSD = priceUSD()+StopDistUSD;
// plot a price curve of the synthetic asset
// (the plot command is linked to the last used asset -
// so "EUR/USD" must be selected in the scrollbox)
loop, algo, Asset,
latest version online