asset (string Name) : int

Selects an asset, and opens its price history in the initial run. Price and trade functions, and asset related variables (Spread, Symbol, AssetVar etc.) are automatically adapted to the new asset. This way different assets can be compared for arbitraging or correlation indicators, or a script can trade multiple assets simultaneously. For loading price history the asset function must be called in the initial run of the strategy.

Parameters:

Name The name of the asset, as in the [Asset] selector; or an empty string "" for creating a dummy asset. Up to 15 characters, with no blanks and no special characters except for slash '/' and underline '_'.

Returns:

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

Usage:

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

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, or modifies parameters of an existing asset. Must be called in the initial run of the strategy before the asset is selected. Assets contained in the asset list are automatically added.

Parameters:

Name Name of the asset
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,0);
 

assetList (string Filename): 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. Must be called before any of the new assets can be selected.

Parameters:

FileName File name of the asset .csv file. The path can be omitted for asset lists in the History folder.

Returns:

Number of the loaded assets, or 0 when no assets were loaded.

Usage:

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

assetType (string Name) : int

Attempts to determine the type of an asset from its name; f.i. if the 3-letter abbreviation of a currency appears in the asset name, it is identified as Forex.

Parameters:

Name Name of the asset

Returns:

0 when the type can not be identified, f.i. stock; otherwise FOREX (1), INDEX (2), CMDTY (3), or BOND (5).
 

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