Original (English)

enterLong (int Lots, var Entry, var Stop, var TakeProfit, var Trail, var TrailSlope, var TrailLock, var TrailStep): TRADE*

enterShort (int Lots, var Entry, var Stop, var TakeProfit, var Trail, var TrailSlope, var TrailLock, var TrailStep): TRADE*

Enters a long or short trade with optional parameters. Entry and exit conditions are handled by Zorro.

enterLong (function, var V0, ... var V7): TRADE*

enterShort (function, var V0, ... var V7): TRADE*

Enters a long or short script-managed trade with optional user-defined parameters. Entry and exit conditions are handled by a user-provided algorithm in the given trade management function (TMF) dependent on the variables v0 .. v7.

enterTrade (TRADE*): TRADE*

Enters an open, pending, or closed trade from a TRADE struct. Inserts the trade only in the internal trade list; does not send any order to the broker. The asset name can be given through TradeStr[0] resp. the Skill element of the TRADE struct; if it is not set, the current asset is used. The position size (nLots) and the TR_SHORT and TR_OPEN flags must be set in the TRADE struct; other elements are optional. The algo identifier is taken from the TRADE struct; if it has none, it is set to the current algo. This function can be used for running backtests from a list of trades (see Simulate script) or for reading positions from the broker API and converting them to trades. 
 

Parameters:

Lots Optional number of lots when nonzero; overrides the global Lots, Amount, Margin, and Risk variables. A negative number reverses the trade direction: enterLong then opens a short trade and enterShort opens a long trade.
Entry Optional entry stop when > 0, entry limit when < 0 (overrides the global Entry).
Stop Optional stop loss when nonzero (overrides the global Stop).
TakeProfit Optional profit target when nonzero (overrides the global TakeProfit).
Trail Optional trail limit when nonzero (overrides the global Trail).
TrailSlope Optional trailing speed when nonzero (overrides the global TrailSlope).
TrailLock Optional profit lock percentage when nonzero (overrides the global TrailLock).
TrailStep Optional autotrailing step width when nonzero (overrides the global TrailStep).
function Optional pointer of an int function for micro-managing the trade (see TMF).
V0 ... V7 Up to 8 optional numerical variables as further arguments to the TMF.

Returns:

TRADE* - a pointer to the created trade struct (see include\trading.h for the definition of the TRADE struct), or 0 when no trade could be entered because the trade volume was zero, trading was disabled (f.i. weekend, time frame, or lookback period), or the trade was rejected by the broker. For pending trades a nonzero pointer is always returned.

Remarks:

  • In the backtest, the result of entering a trade can be either a pending trade, an opened trade, or a skipped trade. If no Entry limit is given, trades are opened at the current price or at the next open price, dependent on Fill mode. If a trade is pending, Zorro continues to attempt opening the trade within the time period given by EntryTime.
  • In live trading, order filling depends on the broker API and the market situation. Normally the order is cancelled when not filled within a wait time given by SET_WAIT (default: about 30-60 seconds dependent on broker API). This behavior can be changed with the SET_ORDERTYPE command. Partial fills are allowed for IOC ("immediate-or-cancel") or GTC ("good-till-cancelled") orders. A GTC order stays active in the background until it is either complete, or is cancelled by expiration or by an exit command.
  • Long trades open at the best ask price, short trades at the best bid price from the order book or the historical data. But the real fill price - the price at which the trade is entered - normally differs to the current ask or bid price. The difference is the slippage. It can be simulated in the backtest with the Slippage variable. To prevent an unfavorable fill price in live trading, you can use limit orders instead of market orders. Some broker plugins, f.i. the IB plugin, support limit orders. They are normally guaranteed to be filled at the price set up through the OrderLimit variable.
  • When function parameters are 0 or omitted in the parameter list, global trade parameters are used. When no trade management function and only global parameters are used, the parentheses can be empty.
  • If a contract is selected and the Multiplier is set, the function opens an option or future position instead of a position of the underlying.
  • Trades are automatically skipped during weekends or outside market hours, during the LookBack period, in the inactive period of SKIP or DataSplit, or when the current bar is not the end of a TimeFrame. For trading inside a time frame, set TimeFrame = 1, enter the trade, then set TimeFrame back to its previous value.
  • Trades are also not opened when Lots is 0, or Margin or Risk are too low, or the MaxLong / MaxShort limits are reached in [Test] and [Trade] mode, or when the Algo name ends with "L" for short trades or with "S" for long trades. However reverse positions are then still closed and the stop limits, profit targets, and life times of open trades with the same asset and algo are updated to the current values. This way, already open trades behave as if they were just opened by the recent signal. If this mechanism is not desired, limit the number of trades with negative MaxLong / MaxShort limits.
  • If a trade is rejected by the broker, the reason by the broker API - such as "Outside market hours" - normally printed to the log. When trading with the MT4/5 bridge, the reason can be seen in the MT4/5 Experts Log. The number of rejected orders is stored in the NumRejected variable. There can be many reasons for the broker API to reject a trade, for instance not enough capital on the account, not enough free margin, a wrong asset name, a closed or illiquid market, an asset that cannot be shorted, or a stop loss that is too tight, too far, or not an integer multiple of a pip. Zorro will not attempt to open the trade again unless either enforced by script, or when it's a pool trade. Pool trades will be rebalanced at any bar until they match the virtual trades.
  • A returned nonzero TRADE* pointer means that the trade is processed, but is no guarantee that the position is really opened - it could still be pending or is rejected later by the broker. This is indicated by flags in the TRADE struct. The returned TRADE* pointer can be assigned to ThisTrade (f.i. ThisTrade = enterLong();). If ThisTrade is nonzero, all its trade variables - for instance, TradeIsOpen - are available for checking the state of the trade.
  • A trade management function (TMF) is automatically called every tick - i.e. whenever the price changes - with the the optional variables (V0 .. V7) as arguments. It can evaluate the current price and other trade variables for managing the position or adjusting stop and profit limits. Note that V0 .. V7 are for numbers only; they internally stored as float variables with 32-bit precision.
  • Open, pending, and closed trades can be enumerated with the for(open_trades) and for(all_trades) macros.
  • Every trade is linked to an algorithm identifier that can be set up through the Algo string. Identifiers are useful when the script trades with several different algorithms; they are then used for selecting strategy parameters or capital allocation factors belonging to a certain trade algorithm, or to exit or identifiy particular trades. The performance report lists strategy results separated by their algorithm identifiers.
  • Entry and exit conditions can be either set individually per trade, or set up globally through the Entry, Stop, TakeProfit, and Trail variables for all subsequent trades. If the stop loss is too close, too far, to or on the wrong side of the price, the trade can be rejected by the broker. Make sure that the stop loss has sufficient distance to the current price (priceClose()). A timed exit can be set up with LifeTime.
  • If TICKS is not set and the price hits the entry limit, the profit target, and/or the stop loss in the same bar, the simulation assumes a pessimistic outcome. The limits are evaluated in the order entry - stop - profit target. If TICKS is set, the price curve inside the bar is evaluated for determining which limit is met first.
  • Opening a trade automatically closes opposite trades when Hedge is 0 or 1 (i.e. enterLong can automatically close short positions and enterShort can automatically close long positions). If the trade was not opened because the Entry limit was not met within EntryTime, opposite trades are not closed; if the trade was not opened because Lots is 0 or Margin or Risk are too low, opposite trades are still closed.
  • The trade size is determined by the Margin, Risk, Amount, or Lots variables.
  • The TR_PHANTOM flag causes the trade to be executed in "phantom mode". Phantom trades are not sent to the broker and do not contribute to the Total statistics, but their projected wins and losses contribute to the Short and Long statistics. This can be used to filter trades based on the current win/loss situation ("equity curve trading").
  • If an order function is defined in the script, it is called with 1 for the first argument and the TRADE* pointer for the second argument at the moment when the buy order is sent to the broker. This function can f.i. open a message box for manually entering the trade, or control another broker's user interface.
  • When converting scripts from other trading software, keep in mind that other trading programs use sometimes different names for trade functions. For instance, TradeStation® uses "Sell Short" for entering a short position and "Buy To Cover" for exiting a short position.
  • In [Trade] mode, all open trades are stored in a .trd file in the Data folder. The stored trades are automatically continued when the strategy is started again, for instance after a computer crash.

Example 1: Simple SMA crossing

function run()
{
  vars Price = series(priceClose());
  vars SMA100 = series(SMA(Price,100));
  vars SMA30 = series(SMA(Price,30));
 
  if(crossOver(SMA30,SMA100))
    enterLong();
  else if(crossUnder(SMA30,SMA100))
    enterShort();
}

Example 2: Grid trading script

// helper function for finding trades at a grid line
bool noTradeAt(var Price,var Grid,bool IsShort) 
{
  for(open_trades)
    if((TradeIsShort == IsShort)
      and between(TradeEntryLimit,Price-Grid/2,Price+Grid/2))
        return false; // trade found
  return true; // no open/pending trade at that price
}
  
function run() 
{
  BarPeriod = 1440;
  Hedge = 2; 
  EntryTime = ExitTime = 500;  
  var Price;
  var Grid = 100*PIP; // grid spacing
  var Current = priceClose();
// place pending trades at 5 grid lines above and below the current price
  for(Price = 0; Price < Current+5*Grid; Price += Grid) {
    if(Price < Current-5*Grid)
      continue;
    if(Price < Current && noTradeAt(Price,Grid,true))
      enterShort(0,Price,0,Grid);      
    else if(Price > Current && noTradeAt(Price,Grid,false))
      enterLong(0,Price,0,Grid);
  }
}

Example 3: Using a trade management function

// TMF that adjusts the stop in a special way
int TrailingStop()
{
// adjust the stop only when the trade is in profit
  if(TradeProfit > 0)
// place the stop at the lowest bottom of the previous 3 candles
    TradeStopLimit = max(TradeStopLimit,LL(3));
// plot a line to make the stop limit visible in the chart
  plot("Stop",TradeStopLimit,MINV,BLACK);

// return 0 for checking the limits
  return 0;
}

// using the trade function
function run()
{
  ...
  Lots = 1;
  Stop = 10*PIP;
  Algo = "SIG";
  if(crossOver(MySignal,MyThreshold))
    enterLong(TrailingStop);
  ...
}

See also:

exitLong/Short, tradeUpdate, Lots, Risk, Entry, Stop, EntryTime, ExitTime, BarMode, TMF, Fill, Hedge

► latest version online

Übersetzung (Deutsch)

enterLong (int Lots, var Entry, var Stop, var TakeProfit, var Trail, var TrailSlope, var TrailLock, var TrailStep): TRADE*

enterShort (int Lots, var Entry, var Stop, var TakeProfit, var Trail, var TrailSlope, var TrailLock, var TrailStep): TRADE*

Eröffnet eine Long- oder Short-Position mit optionalen Parametern. Einstieg und Ausstiegsbedingungen werden von Zorro gesteuert.

enterLong (function, var V0, ... var V7): TRADE*

enterShort (function, var V0, ... var V7): TRADE*

Eröffnet eine Long- oder Short-Position, die durch ein Skript verwaltet wird und optionale, benutzerdefinierte Parameter enthält. Einstieg und Ausstiegsbedingungen werden von einer vom Anwender bereitgestellten Funktion (TMF) anhand der Variablen v0 .. v7 geregelt.

enterTrade (TRADE*): TRADE*

Übernimmt einen offenen, wartenden oder geschlossenen Trade aus einer TRADE-Struktur. Fügt den Trade nur in die interne Trades-Liste ein; sendet keinerlei Order an den Broker. Der Asset-Name kann über TradeStr[0] bzw. das Skill-Element der TRADE-Struktur übergeben werden; ist dieses nicht gesetzt, wird das aktuelle Asset verwendet. Die Positionsgröße (nLots) sowie die Flags TR_SHORT und TR_OPEN müssen in der TRADE-Struktur gesetzt sein; andere Elemente sind optional. Die Algo-ID wird aus der TRADE-Struktur übernommen; falls dort keine gesetzt ist, wird sie auf den aktuellen Algo-Namen gesetzt. Diese Funktion kann genutzt werden, um Backtests aus einer Tradeliste zu betreiben (siehe Simulate-Skript) oder um Positionen aus einer Broker-API einzulesen und in Trades umzuwandeln.
 

Parameter:

Lots Optionale Lot-Anzahl, falls ungleich Null; überschreibt die globalen Variablen Lots, Amount, Margin und Risk. Ein negativer Wert kehrt die Handelsrichtung um: enterLong eröffnet dann eine Short-Position und enterShort eröffnet eine Long-Position.
Entry Optionaler Einstiegs-Stopp bei > 0, Limit bei < 0 (überschreibt die globale Variable Entry).
Stop Optionaler Stop Loss, falls ungleich Null (überschreibt die globale Variable Stop).
TakeProfit Optionaler Take-Profit, falls ungleich Null (überschreibt die globale Variable TakeProfit).
Trail Optionale Trailing-Grenze, falls ungleich Null (überschreibt die globale Variable Trail).
TrailSlope Optionale Trailing-Geschwindigkeit, falls ungleich Null (überschreibt die globale Variable TrailSlope).
TrailLock Optionaler zu sichernder Gewinn in Prozent, falls ungleich Null (überschreibt die globale Variable TrailLock).
TrailStep Optionale Schrittweite für automatisches Trailing, falls ungleich Null (überschreibt die globale Variable TrailStep).
function Optionaler Funktionszeiger auf eine int-Funktion zur Mikromanagement-Steuerung des Trades (siehe TMF).
V0 ... V7 Bis zu 8 optionale numerische Variablen als zusätzliche Parameter für die TMF.

Rückgabewert:

TRADE* - ein Zeiger auf die erstellte Trade-Struktur (siehe include\trading.h für die Definition der TRADE-Struktur) oder 0, wenn kein Trade eröffnet werden konnte, weil z.B. das Handelsvolumen Null war, das Trading deaktiviert ist (z.B. Wochenende, Zeitfenster oder Lookback-Periode) oder der Trade vom Broker abgelehnt wurde. Für wartende (pending) Trades wird immer ein ungleich Null-Zeiger zurückgegeben.

Bemerkungen:

  • Im Backtest kann das Ergebnis eines Einstiegsversuchs entweder ein wartender (pending) Trade, ein geöffneter Trade oder ein übersprungener (skipped) Trade sein. Ohne Entry-Limit wird der Trade entweder zum aktuellen Kurs oder zum nächsten Eröffnungskurs eröffnet, abhängig vom Fill-Modus. Ist ein Trade wartend (pending), versucht Zorro innerhalb des EntryTime-Zeitraums weiterhin, den Trade zu eröffnen.
  • Im Live-Trading hängt die Order-Ausführung von der Broker-API und der Marktsituation ab. Normalerweise wird eine Order storniert, wenn sie innerhalb einer durch SET_WAIT definierten Wartezeit (Standard: etwa 30-60 Sekunden, brokerabhängig) nicht ausgeführt wurde. Dieses Verhalten kann mit SET_ORDERTYPE geändert werden. Teilfüllungen sind bei IOC ("immediate-or-cancel") oder GTC ("good-till-cancelled") erlaubt. Eine GTC-Order bleibt so lange aktiv, bis sie komplett ausgeführt oder manuell (z.B. durch Ablauf oder exit) storniert wird.
  • Long-Trades öffnen zum besten Ask-Preis, Short-Trades zum besten Bid-Preis aus dem Orderbuch oder aus historischen Daten. Der tatsächliche Fill-Preis - also der Preis, zu dem die Position eröffnet wird - kann jedoch vom aktuellen Ask- oder Bid-Preis abweichen. Diese Abweichung heißt Slippage. Im Backtest kann man die Slippage über die Variable Slippage simulieren. Um ungünstige Ausführungskurse im Live-Trading zu vermeiden, kann man Limit-Orders anstelle von Market-Orders verwenden. Manche Broker-Plugins, z.B. das IB-Plugin, unterstützen Limit-Orders. Sie werden in der Regel zum durch OrderLimit festgelegten Preis ausgeführt.
  • Sind Funktionsparameter 0 oder nicht angegeben, werden globale Handelsparameter verwendet. Wenn keine Trade-Management-Funktion und nur globale Parameter genutzt werden, können die Klammern auch leer bleiben.
  • Wenn ein Kontrakt ausgewählt ist und der Multiplier gesetzt ist, öffnet die Funktion eine Option- oder Future-Position anstatt einer Position des Basiswerts.
  • Trades werden während Wochenenden, außerhalb der Handelszeiten, während der LookBack-Periode, in der inaktiven Zeit von SKIP oder DataSplit oder wenn der aktuelle Bar nicht das Ende eines TimeFrame ist, automatisch übersprungen. Fürs Handeln innerhalb eines TimeFrames kann man TimeFrame = 1 setzen, dann den Trade eröffnen und anschließend TimeFrame wieder auf den alten Wert zurücksetzen.
  • Trades werden ebenfalls nicht eröffnet, wenn Lots = 0 sind oder Margin/Risk zu niedrig sind, wenn MaxLong / MaxShort-Grenzen im [Test] und [Trade] Modus erreicht wurden oder wenn der Algo-Name mit "L" für Short-Trades oder mit "S" für Long-Trades endet. Gegengeschäfte (Reverse Positions) werden dann dennoch geschlossen, und Stop-Limits, Take-Profits und Laufzeiten offener Trades mit gleichem Asset und Algo werden aktualisiert, sodass diese offenen Trades so behandelt werden, als wären sie gerade durch das aktuelle Signal eingestiegen. Ist dieses Verhalten unerwünscht, kann man die Anzahl Trades durch negative MaxLong / MaxShort-Limits begrenzen.
  • Wird ein Trade vom Broker abgelehnt, ist der Grund seitens Broker-API (z.B. "Außerhalb der Handelszeiten") normalerweise im Log ersichtlich. Handelt man mit der MT4/5-Bridge, steht der Grund im MT4/5-Experts-Log. Die Anzahl abgelehnter Orders ist in der Variable NumRejected gespeichert. Gründe für eine Broker-Ablehnung sind z.B. zu geringes Kontoguthaben, fehlende freie Margin, falscher Asset-Name, geschlossener oder illiquider Markt, ein nicht leerverkaufbares Asset oder ein Stop Loss, der zu eng, zu weit oder nicht ein Vielfaches eines ganzen Pips ist. Zorro versucht nicht erneut, den Trade zu eröffnen, außer es wird durch das Skript erzwungen oder wenn es sich um einen Pool Trade handelt. Pool Trades werden an jedem Bar rebalanciert, bis sie mit den virtuellen Trades übereinstimmen.
  • Ein zurückgegebener ungleich Null TRADE*-Zeiger bedeutet, dass der Trade verarbeitet wird, garantiert jedoch nicht, dass eine Position tatsächlich eröffnet wird - sie kann weiterhin wartend sein oder auch später vom Broker abgelehnt werden. Das erkennt man an den Flags in der TRADE-Struktur. Der zurückgegebene TRADE*-Zeiger kann bspw. ThisTrade zugewiesen werden (ThisTrade = enterLong();). Ist ThisTrade ungleich Null, stehen alle zugehörigen Trade-Variablen - etwa TradeIsOpen - zur Abfrage bereit.
  • Eine Trade-Management-Funktion (TMF) wird automatisch bei jedem Tick - also bei jeder Preisänderung - aufgerufen und erhält die optionalen Variablen (V0 .. V7) als Argumente. Die Funktion kann dann den aktuellen Preis und andere Trade-Variablen auswerten, um die Position zu managen oder Stop- und Take-Profit-Grenzen anzupassen. Zu beachten ist, dass V0 .. V7 nur Zahlen enthalten können; intern werden sie als float (32-Bit) gespeichert.
  • Offene, wartende und geschlossene Trades können mit den Makros durchlaufen, etwa for(open_trades) und for(all_trades).
  • Jeder Trade ist mit einer Algorithmus-ID verknüpft, die über den Algo-String gesetzt werden kann. Diese Kennung ist sinnvoll, wenn im Skript mehrere Strategien gehandelt werden; sie dient zum Selektieren optimierter Parameter oder Kapitalallokationen für eine bestimmte Strategie bzw. zum gezielten Schließen oder Identifizieren bestimmter Trades. Im Performance-Bericht werden die Strategieresultate nach den Algorithmus-Kennungen getrennt aufgelistet.
  • Einstiegs- und Ausstiegsbedingungen können entweder pro Trade individuell festgelegt oder global über die Variablen Entry, Stop, TakeProfit und Trail für alle folgenden Trades gesetzt werden. Wenn der Stop Loss zu nah, zu weit oder auf der falschen Seite des aktuellen Kurses liegt, kann der Broker den Trade ablehnen. Achte darauf, dass der Stop Loss ausreichend Abstand zum aktuellen Kurs (priceClose()) hat. Ein zeitgesteuertes Schließen lässt sich über LifeTime einrichten.
  • Ist TICKS nicht gesetzt und der Kurs erreicht in derselben Bar sowohl das Einstiegs-Limit, den Take-Profit als auch den Stop, nimmt die Simulation das pessimistischste Szenario an. Die Reihenfolge der Prüfung lautet: Einstieg - Stop - TakeProfit. Ist TICKS gesetzt, wertet die Simulation den Kursverlauf innerhalb der Bar aus, um festzustellen, welcher Grenzwert zuerst erfüllt wird.
  • Das Öffnen eines Trades schließt automatisch Gegenpositionen, wenn Hedge = 0 oder 1 ist (d.h. enterLong schließt ggf. Short-Positionen und enterShort schließt ggf. Long-Positionen). Wurde der Trade nicht eröffnet, weil das Entry-Limit innerhalb von EntryTime nicht erreicht wurde, werden entgegengesetzte Positionen nicht geschlossen; wurde der Trade nicht eröffnet, weil Lots = 0 sind oder Margin / Risk zu gering sind, werden Gegenpositionen dennoch geschlossen.
  • Die Positionsgröße wird durch die Variablen Margin, Risk, Amount oder Lots bestimmt.
  • Das Flag TR_PHANTOM bewirkt, dass der Trade im "Phantom-Modus" ausgeführt wird. Phantom-Trades werden nicht an den Broker gesendet und fließen nicht in die Total-Statistiken ein; ihre prognostizierten Gewinne und Verluste zählen jedoch in die Short- und Long-Statistiken. Das kann man nutzen, um Trades basierend auf der aktuellen Gewinn-/Verlustsituation zu filtern ("Equity Curve Trading").
  • Ist im Skript eine order-Funktion definiert, wird diese beim Senden der Kauforder an den Broker mit 1 als erstem und dem TRADE*-Zeiger als zweitem Parameter aufgerufen. Diese Funktion kann z.B. eine Message-Box öffnen, um den Trade manuell einzugeben, oder eine andere Broker-Oberfläche steuern.
  • Beim Umsetzen von Skripten aus anderer Trading-Software ist zu beachten, dass dort oft unterschiedliche Namen für Trade-Funktionen verwendet werden. Beispielsweise nennt TradeStation® das Eingehen einer Short-Position "Sell Short" und das Schließen einer Short-Position "Buy To Cover".
  • Im [Trade]-Modus werden alle offenen Trades in einer .trd-Datei im Ordner Data abgelegt. Diese gespeicherten Trades werden beim nächsten Start der Strategie, z.B. nach einem Rechner-Neustart, automatisch fortgeführt.

Beispiel 1: Einfaches SMA-Crossover

function run()
{
  vars Price = series(priceClose());
  vars SMA100 = series(SMA(Price,100));
  vars SMA30 = series(SMA(Price,30));

  if(crossOver(SMA30,SMA100))
    enterLong();
  else if(crossUnder(SMA30,SMA100))
    enterShort();
}

Beispiel 2: Grid-Trading-Skript

// Hilfsfunktion, um Trades an einer Grid-Linie zu finden
bool noTradeAt(var Price,var Grid,bool IsShort) 
{
  for(open_trades)
    if((TradeIsShort == IsShort)
      and between(TradeEntryLimit,Price-Grid/2,Price+Grid/2))
        return false; // Trade gefunden
  return true; // kein offener/wartender Trade an diesem Preis
}
  
function run() 
{
  BarPeriod = 1440;
  Hedge = 2;
  EntryTime = ExitTime = 500;
  var Price;
  var Grid = 100*PIP; // Grid-Abstand
  var Current = priceClose();
// setze wartende Trades bei 5 Grid-Linien über und unter dem aktuellen Preis
  for(Price = 0; Price < Current+5*Grid; Price += Grid) {
    if(Price < Current-5*Grid)
      continue;
    if(Price < Current && noTradeAt(Price,Grid,true))
      enterShort(0,Price,0,Grid);
    else if(Price > Current && noTradeAt(Price,Grid,false))
      enterLong(0,Price,0,Grid);
  }
}

Beispiel 3: Verwendung einer Trade-Management-Funktion

// TMF, die den Stop auf eine besondere Weise anpasst
int TrailingStop()
{
  // Stop nur anpassen, wenn der Trade im Gewinn ist
  if(TradeProfit > 0)
    // Stop auf das tiefste Tief der vorherigen 3 Kerzen setzen
    TradeStopLimit = max(TradeStopLimit,LL(3));
  // zeichne eine Linie für den Stop im Chart
  plot("Stop",TradeStopLimit,MINV,BLACK);

  // return 0 für die weitere Limit-Prüfung
  return 0;
}

// Nutzung der Trade-Funktion
function run()
{
  ...
  Lots = 1;
  Stop = 10*PIP;
  Algo = "SIG";
  if(crossOver(MySignal,MyThreshold))
    enterLong(TrailingStop);
  ...
}

Siehe auch:

exitLong/Short, tradeUpdate, Lots, Risk, Entry, Stop, EntryTime, ExitTime, BarMode, TMF, Fill, Hedge

► latest version online