Original (English)
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)
Selects an asset and optionally updates its parameters in the
INITRUN. If the asset was not yet in the
asset list, it is added and also appears in the [Asset]
scrollbox. Unlike asset(), the asset history is not yet loaded
and the asset is not yet subscribed. For creating a dummy asset for test purposes, let Name
begin with a '#' hash - this will generate 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 or its Symbol, price
source, or assigned account has to be set up by script.
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, e.g., "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, e.g.,
"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 number, it is identified as an index.
Parameters:
Returns:
0 when the type can not be identified; otherwise FOREX
(1) or INDEX (2).
Remarks:
- The place of an asset call (if any) in the script
matters. All variables and flags that affect the creation of bars, such as
BarPeriod,
BarZone, LookBack,
Detrend, StartDate,
EndDate,
TICKS, BarMode,
UpdateDays, AssetList,
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
INITRUN.
- 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
market hours.
- 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
parameters.
- 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 broker symbols
and 3 different sources for trading, for retrieving live prices, and for
downloading historical prices.
The symbols can be given in the Symbol field in the
asset list, or by script in the
SymbolTrade, SymbolLive,
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 assets without
loop call, use for(used_assets)
or for(listed_assets).
- The trading time zone of an asset can be set up with
AssetMarketZone and
AssetFrameZone. 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).
- When the asset name is an empty string or begins with a hash - like
asset("") or asset("#USD") - a
dummy asset is created with default
parameters and flat price history (usually with all prices at 50). This is useful when a real asset is not needed,
like for
testing filters or indicators with artificial price curves. The price
history can be modified with priceSet or
priceQuote. For viewing the price curve of a dummy
asset, use assetAdd() for adding it to the scrollbox.
- When loading price data, the prices are checked for plausibility dependent
on the Outlier parameter. Invalid prices,
such as extreme outliers, are automatically corrected or removed. Setting
Detrend = NOPRICE; before calling
asset() prevents that asset and price data is checked and outliers
are removed.
- 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 determines the
price in the [Status] window and 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 allocates computer memory (see also
memory). This is normally uncritical in training or
live trading, which is restricted to single assets and short lookback
periods. But it can become critical in high resolution backtests with large
portfolios. The memory requirement
per asset
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 and asset. When the total
memory requirement for backtesting large time periods exceeds ~3 GB, use
Zorro64 with a C++ script for the
backtest. Alternatively, split the portfolio in separate
smaller sub-portfolios, or split the time period in separate shorter tests.
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();
}
// set all asset symbols to a new source
if(Init) {
assetList("MyAssetList.csv");
for(listed_assets)
assetAdd(Asset,strf("MyNewSource:%s",SymbolLive));
}
// Basket trading - generate a synthetic 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
|
Übersetzung (Deutsch)
Wählt ein Asset aus der Asset-Liste aus und lädt dessen Preis-
verlauf beim ersten Durchlauf vom Broker oder aus historischen Daten.
Preis und Handelsfunktionen sowie alle assetbezogenen Variablen (Spread,
Symbol, AssetVar usw.) werden automatisch
auf das neue Asset umgeschaltet. Setzt AssetPrev auf den
vorherigen Assetnamen. Muss beim ersten Durchlauf (INITRUN)
für jedes im Skript verwendete Asset aufgerufen werden.
Parameter:
Name |
Der Name des Assets, wie in der Asset-Liste
oder dem [Asset]-Selektor. Ein leerer String
"" oder ein Name, der mit
'#' beginnt, erstellt ein Dummy-Asset mit flacher Preisgeschichte. Bis zu 15 Zeichen,
Großbuchstaben, ohne Leerzeichen und ohne Sonderzeichen außer Schrägstrich '/' und Unterstrich
'_'. |
Rückgabe:
0, wenn die Name-Zeichenkette NULL
oder leer ist, oder wenn das Asset oder seine Preise nicht verfügbar sind; andernfalls ungleich null.
Verwendung:
asset("EUR/USD"); wählt das EUR/USD-Paar aus.
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)
Wählt ein Asset aus und aktualisiert optional dessen Parameter im
INITRUN. Wenn das Asset noch nicht in der
Asset-Liste vorhanden war, wird es hinzugefügt und erscheint auch im [Asset]
Scrollbox. Im Gegensatz zu asset() wird die Asset-Geschichte noch nicht geladen
und das Asset ist noch nicht abonniert. Um ein Dummy-Asset zu Testzwecken zu erstellen, lassen Sie Name
mit einem '#' Hash beginnen - dies generiert künstliche Bars mit einer flachen
Preisgeschichte. Das Auswählen eines Assets vor dem Laden seiner Preisgeschichte kann nützlich sein,
wenn assetspezifische Parameter wie Centage den
nachfolgenden Geschichtendownload oder dessen Symbol, Preisquelle
oder zugewiesenes Konto durch das Skript festgelegt werden müssen.
Parameter:
Name |
Name des Assets. Ein Name, der mit
'#' beginnt, erstellt ein Dummy-Asset, das auch im
Scrollbox erscheint. |
Symbol |
Symbol des Assets, mit optionaler Quelle, im unter
Asset-Liste beschriebenen Format. |
Price, ... |
Optionale Asset-Parameter, wie unter Asset
Liste beschrieben. Wenn auf 0, wird der Parameter nicht geändert. |
Verwendung:
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
Lädt eine alternative Asset-Liste, fügt deren Assets zur
[Asset] Scrollbox hinzu und wählt ein Asset aus der
neuen Liste aus. Jedes im Skript verwendete Asset muss entweder in dieser Liste sein oder
durch das Skript mit assetAdd hinzugefügt werden. Die Asset-Liste muss im ersten
Durchlauf (INITRUN) des Skripts geladen werden, bevor ihre Assets
ausgewählt werden können. Wenn diese Funktion nicht aufgerufen wird, wird die Standardliste des
aktuell ausgewählten Kontos verwendet; wenn keine solche Liste
existiert, ist es die
AssetsFix.csv Liste mit einigen Forex-Paaren und CFDs. Wenn Select weggelassen
oder 0 ist, wird ein Standard-Asset - normalerweise das erste Asset in der Liste - ausgewählt.
Parameter:
FileName |
Dateiname der Asset-Liste, z.B. "AssetsIB".
Die .csv Erweiterung und der Pfad können für Asset
Listen im History Ordner weggelassen werden. |
Select |
Name des Assets, das beim ersten Durchlauf im Scrollbox ausgewählt werden soll, z.B.
"EUR/USD". 0 zum Auswählen
eines Standard-Assets. |
Rückgabe:
Anzahl der geladenen Assets oder 0, wenn keine Assets geladen wurden. Die Anzahl
der Assets ist auch über NumAssetsListed verfügbar.
Verwendung:
assetList("Strategy\\MyNewAssets.csv",0);
assetSelect ()
Setzt die [Asset] Scrollbox auf das aktuelle Asset.
assetType (string Name) : int
Versucht, den Typ eines Assets anhand seines Namens zu bestimmen. Wenn der Name mit der
3-Buchstaben-Abkürzung einer Währung beginnt und endet, wird er als Forex identifiziert;
endet er mit einer Zahl, wird er als Index identifiziert.
Parameter:
Rückgabe:
0 , wenn der Typ nicht identifiziert werden kann; andernfalls FOREX
(1) oder INDEX (2).
Anmerkungen:
- Der Ort eines asset Aufrufs (falls vorhanden) im Skript
zählt. Alle Variablen und Flags, die die Erstellung von Bars beeinflussen, wie
BarPeriod,
BarZone, LookBack,
Detrend, StartDate,
EndDate,
TICKS, BarMode,
UpdateDays, AssetList,
History usw. müssen vor
dem Aufruf von asset() gesetzt werden. Andernfalls ist der Simulationszeitraum
bei der Asset-Ladung unbekannt und es wird entweder ein Standardzeitraum verwendet oder das Skript
ergibt eine Error 030 Meldung. Alle spezifischen Parameter eines
Assets, wie Spread,
Commission usw., sowie alle Funktionen, die Asset-Parameter oder
Preise verwenden, wie price(),
optimize(), advise() usw.,
müssen nach dem Aufruf von asset() verwendet werden.
- Das Aufrufen von asset durch das Skript ist nicht
gleich dem Auswählen des Assets mit der Asset
Scrollbox. Wenn das Skript keinen asset Aufruf enthält, wird das Scrollbox-Asset
_nach_ dem INITRUN ausgewählt, und sein Name wird den training
Dateien hinzugefügt, um verschiedene Assets separat trainieren zu können. Rufen Sie asset(Asset) auf, um
das vom Scrollbox bereits im INITRUN ausgewählte Asset zu laden.
- In Multi-Asset-Skripten ist die Reihenfolge der asset()
Aufrufe entscheidend. Bars werden aus den historischen Ticks des ersten Assets erstellt.
Lücken in der Preisgeschichte des ersten Assets spiegeln sich daher in den Preisdaten aller weiteren Assets wider.
Wenn BR_FLAT nicht gesetzt ist, haben Preisgeschichten normalerweise Lücken während
Wochenenden, Feiertagen oder außerhalb der Marktzeiten. Wählen Sie daher zuerst das Asset mit der vollständigsten
Preisgeschichte (zum Beispiel ein Währungspaar, das 24 Stunden gehandelt wird). Wenn ein nachfolgendes Asset
eine Lücke hat, wo das erste Asset keine hat, wird die Lücke aus den Preisdaten der vorherigen Bar gefüllt.
Dies erzeugt eine andere Preiskurve und kann dazu führen, dass Indikatoren in Multi-Asset-Portfolios
abhängig von der Asset-Reihenfolge unterschiedlich reagieren.
Verwenden Sie andernfalls BR_FLAT oder kombinieren Sie keine Assets mit unterschiedlichen
Marktzeiten.
- Jeder asset Aufruf wechselt die Asset
Parameter, Asset-Variablen,
Handelsstatistiken und OptimalF
Faktoren zu den Werten des ausgewählten Assets. Zu Beginn der Simulation
wird Asset-Parameter aus der
Asset-Liste geladen. Wenn das Asset nicht in der Liste gefunden wird,
wird eine Fehlermeldung angezeigt und Standardwerte für die Asset-Parameter verwendet.
- Wenn ein asset Aufruf fehlschlägt, wird das fehlgeschlagene Asset nicht
ausgewählt und 0 zurückgegeben. Überprüfen Sie den Rückgabewert, um sicherzustellen,
dass nur gültige und verfügbare Assets gehandelt werden.
- Jedes Asset kann bis zu 3 verschiedene Broker-Symbole
und 3 verschiedene Quellen für den Handel, das Abrufen von Live-Preisen und das Herunterladen historischer Preise haben.
Die Symbole können im Symbol Feld in der
Asset-Liste angegeben werden oder durch das Skript in den
SymbolTrade, SymbolLive,
SymbolHist Parametern. Der aktuelle Asset-Name wird
im Asset String gespeichert.
- Das Assets Array enthält die Namen aller verfügbaren
Assets. Zum Auswählen aller Assets der
Asset-Liste in einer Schleife, verwenden Sie
while(asset(loop(Assets))). Zum Auflisten von Assets ohne
loop Aufruf, verwenden Sie for(used_assets)
oder for(listed_assets).
- Die Handelszeitzone eines Assets kann mit
AssetMarketZone und
AssetFrameZone eingerichtet werden. Der Handel kann auf die Marktzeiten
mit dem BR_LEISURE Flag beschränkt werden.
- Künstliche Assets können erstellt werden, indem
die Preise aus einem 'Basket' mehrerer realer Assets kombiniert werden (siehe Beispiel).
- Wenn der Asset-Name ein leerer String ist oder mit einem Hash beginnt - wie
asset("") oder asset("#USD") - wird ein
Dummy-Asset mit Standard
Parametern und flacher Preisgeschichte erstellt (normalerweise mit allen Preisen auf 50). Dies ist nützlich, wenn ein reales Asset nicht benötigt wird,
z.B. zum
Testen von Filtern oder Indikatoren mit künstlichen Preiskurven. Die Preis-
Geschichte kann mit priceSet oder
priceQuote geändert werden. Um die Preiskurve eines Dummy
Assets anzuzeigen, verwenden Sie assetAdd(), um es zur Scrollbox hinzuzufügen.
- Beim Laden von Preisdaten werden die Preise auf Plausibilität überprüft, abhängig
von dem Outlier Parameter. Ungültige Preise,
wie extreme Ausreißer, werden automatisch korrigiert oder entfernt. Das Setzen
Detrend = NOPRICE; vor dem Aufruf
asset() verhindert, dass das Asset und die Preisdaten überprüft und Ausreißer
entfernt werden.
- Wenn im Skript nur ein einzelnes Asset ausgewählt ist, wird die [Asset]
Scrollbox automatisch auf dieses Asset gesetzt. Wenn mehrere Assets ausgewählt sind,
bleibt die [Asset] Scrollbox unverändert und bestimmt den
Preis im [Status] Fenster und die Preiskurve im resultierenden Diagramm.
- Zum Hinzufügen neuer Assets zum verfügbaren Asset
Set, siehe die Beschreibung unter Asset List.
- Assets müssen abonniert werden, bevor ihre Preise verfügbar sind. Die
asset Funktion abonniert das Asset automatisch, aber einige Broker
haben eine Begrenzung für die Anzahl der abonnierten Assets. Einige Plattformen, z.B.
MT4, benötigen nach dem Abonnieren eines Assets
eine lange Zeit, bevor Preise verfügbar sind.
- Jedes Asset belegt Computer-RAM (siehe auch
memory). Dies ist normalerweise unkritisch beim Training oder
live Trading, das auf einzelne Assets und kurze Lookback
Perioden beschränkt ist. Kann aber bei hochauflösenden Backtests mit großen
Portfolios kritisch werden. Die Speicheranforderung
pro Asset
in Bytes kann mit der Formel Years / BarPeriod * 15 MB geschätzt werden,
wobei Years die Anzahl der Backtest-Jahre ist (verwenden Sie 1
für live Trading). Die LEAN und LEANER
Flags reduzieren die Speicheranforderung um etwa 50%, das TICKS
Flag erhöht sie um 32 Bytes pro historischem Preisangebot.
plot Befehle reservieren 8..24 Bytes pro Bar und Asset. Wenn die gesamte
Speicheranforderung für Backtests über große Zeiträume ~3 GB überschreitet, verwenden Sie
Zorro64 mit einem C++ Skript für den
Backtest. Alternativ teilen Sie das Portfolio in separate
kleinere Sub-Portfolios auf oder teilen Sie den Zeitraum in separate kürzere Tests.
Beispiele:
// 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();
}
// set all asset symbols to a new source
if(Init) {
assetList("MyAssetList.csv");
for(listed_assets)
assetAdd(Asset,strf("MyNewSource:%s",SymbolLive));
}
// Basket trading - generate a synthetic 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);
}
Siehe auch:
enterLong/Short,
loop, algo, Asset,
AssetZone, AssetVar,
Detrend, assetHistory,
price
►
latest version online
|