asset (string Name) : int

Selects an asset, and loads its price history in the initial run. 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. The asset function must be called in the initial run of the strategy.


Name 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 no prices are available for the asset; otherwise nonzero.


asset("EUR/USD"); switches to the EUR/USD pair.

assetAdd (string Name, var Price, var Spread, var RollLong, var RollShort, var PipVal, var PipCost, var MarginCost, var Leverage, var LotAmount, var Commission, string Symbol)

Adds a new asset to the current strategy and selects it, or modifies parameters of an existing asset. The asset is also added to the [Asset] scrollbox. To be called in the initial run of the strategy. Assets contained in the asset list are automatically added. For creating a dummy asset for test purposes, set Name to "DUMMY" - this generates artificial bars with a flat price history. Can also be used for selecting an asset before loading its price history, f.i. when asset specific parameters like Centage must be set that affect the history download.


Name Name of the asset
Price, ... Optional asset parameters as described under asset list. When at 0, the parameter is not changed.



assetList (string Filename, string Select): int

Loads a new asset list in the first run of the script, and adds all assets to the [Asset] scrollbox and to the current strategy. Sets the optional Select asset in the scrollbox on the first run; on subsequent runs the user can select different assets. Must be called before any of the new assets can be selected in the script.


FileName 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.
Select Name of the asset to be selected in the scrollbox at first run. 0 for not selecting an asset.


Number of loaded assets, or 0 when no assets were loaded. The number of assets is also available through NumAssetsListed.



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.


Name Name of the asset


0 when the type can not be identified; otherwise FOREX (1) or INDEX (2).



// trade multiple strategies and assets in a single script
function run()
  BarPeriod = 240;
  StartDate = 2010;
  set(TICKS); // set relevant variables and flags before calling asset()
// call different strategy functions with different assets asset("EUR/USD"); tradeLowpass(); tradeFisher(); asset("GBP/USD"); tradeAverage(); asset("SPX500"); tradeBollinger(); }
// 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.
function run() { 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 priceUSD()
  var p = 0;
  asset("GBP/USD"); p += price();
  asset("AUD/USD"); p += price();
  asset("EUR/USD"); p += price();
  return p;

// 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;
  asset("GBP/USD"); enterLong(tradeUSD,StopUSD);
  asset("AUD/USD"); enterLong(tradeUSD,StopUSD);
  asset("EUR/USD"); enterLong(tradeUSD,StopUSD);

void enterShortUSD(var StopDistUSD)
  var StopUSD = priceUSD()+StopDistUSD;
  asset("GBP/USD"); enterShort(tradeUSD,StopUSD);
  asset("AUD/USD"); enterShort(tradeUSD,StopUSD);
  asset("EUR/USD"); enterShort(tradeUSD,StopUSD);
// 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)
function run() 

See also:

enterLong/Short, loop, algo, Asset, AssetZone, AssetVar, Detrend, assetHistory, price

► latest version online