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 all asset related variables (Spread, Symbol, AssetVar etc.) are automatically switched to the new asset. Sets AssetPrev to the previous asset name. Must be called in the first run (INITRUN) for any asset used of the script.

Parameters:

Name The name of the asset, as in the asset list or the [Asset] selector. An empty string "" or a name beginning with '#' creates a dummy asset with flat price history. Up to 15 characters, uppercase, with no blanks and no special characters except for slash '/' and underline '_'.

Returns:

0 when the Name string is NULL or empty, or when the asset or its prices are not available; otherwise nonzero.

Usage:

asset("EUR/USD"); selects 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, string Symbol)

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, let Name begin with a '#' hash - this generates artificial bars with a flat price history. Selecting an asset before loading its price history can be useful when asset specific parameters like Centage affect the subsequent history download.

Parameters:

Name Name of the asset. A name beginning with '#' creates a dummy asset that will also appear in the scrollbox.
Symbol Symbol of the asset, with optional source, in the format described under asset list.
Price, ... Optional asset parameters as described under asset list. When at 0, the parameter is not changed.

Usage:

assetAdd("AAPL",150,0.01,0,0,0.01,0.01,0,2,1,0.02,"STOOQ:AAPL.US");
 

assetList (string Filename, string Select): int

Loads an alternative asset list, adds its assets to the [Asset] scrollbox, and selects an asset from the new list. Any asset 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 list of the currently selected account is used; if no such list exists, it's the AssetsFix.csv list with some Forex pairs and CFDs. If Select is omitted or 0, a default asset - usually the first asset in the list - is selected.

Parameters:

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, f.i. "EUR/USD". 0 for selecting a default asset.

Returns:

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

Usage:

assetList("Strategy\\MyNewAssets.csv",0); 
 

assetSelect ()

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 and ends 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.

Parameters:

Name Name of the asset

Returns:

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

Remarks:

Examples:

// 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() 
{
  set(PLOTNOW);
  plot("USD",priceUSD(),0,RED);
}

See also:

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

► latest version online