Trade parameters 1 - entry and exit limits
Enter the trade when the price reaches a certain value (default = 0 = enter
immediately at market). The value can be given either directly as an Ask price, or as a distance to the current close price. A positive price or distance constitutes an entry stop, a negative price or distance an entry limit. An entry limit buys when the price moves against the trade direction and reaches or crosses the limit. It increases the profit as it buys at a price that went in opposite direction to the trade. An entry stop buys when the price moves in trade direction and reaches or crosses the limit; it reduces the profit, but enters only when the price moved in favorable direction, and thus acts as an additional trade filter.
For a long trade, an entry limit must be below and an entry stop must be above the current price. If the entry price is not reached within the allowed time period (set through EntryTime), the trade is cancelled and a "Missed Entry" message is printed to the log file.
Send a limit order at the given limit price, instead of a market order, to the broker at the next enterLong
or enterShort call. This is different to an
Entry limit. It does not produce a pending trade, but cancels the order
if it is not filled within a few seconds, dependent on broker API. If the broker
API supports limit orders with the SET_LIMIT
command, this guarantees a fill price at or better than the
limit. The price limit must be the real limit, i.e. an ask price for
enterLong and a bid price (subtract Spread) for enterShort.
The script must take care to round the limit to an
integer number of pips if required by the broker API. Unlike
normal orders, not filling a limit order does not produce a "Can't open trade"
error message in the log.
OrderLimit can be used or adapted in a tick or
tmf function for filling an order at the best price
within a certain time period when the precise time of entry or exit does not
Stop loss value or stop loss distance in price units (default = 0 = no stop loss). The trade is closed when the price reaches the limit or the trade loss reaches the distance.
When a new trade cannot be entered due to the MaxLong/MaxShort
limit, open trades of the same component are automatically updated to the stop
that the new trade would have. A good value for Stop is derived from the ATR, f.i. 3*ATR(20). Setting a stop loss is recommended for risk control.
Stop loss distance sent to the broker to act as a 'safety net' in case of a computer crash,
in units of the real stop loss distance. At the default value 1.5 the stop sent to the broker is 50% more distant, thus preventing 'stop hunting' or similar broker practices. At 0, the stop is only controlled by software; at 1.0 the broker stop is identical to the real stop.
If StopFactor is set to a negative value or if a BrokerStop function is not available in the broker plugin, the broker stop is only placed at opening the trade, but not updated afterwards. StopFactor has no effect on pool trades in Virtual Hedging Mode.
Stop orders on NFA compliant accounts must be
explicitely enabled with the SET_ORDERTYPE
Broker stop loss distance for pool trades in Virtual Hedging Mode. At the default value
0.25 any pool trade sends a stop to the broker at 25% distance from the
initial price (non-NFA mode only). When set to
0, pool trades have no stop loss.
Profit target value or profit target distance in price units (default = 0 = no profit target). The trade is closed when the trade profit has reached this amount.
When a new trade cannot be entered due to the MaxLong/MaxShort
limit, open trades of the same component are automatically updated to the profit
target that the new trade would have.A profit target takes profits early, which increases the number of winning trades, but normally reduces the overall profit of a strategy. It is preferable to use TrailLock instead of setting a profit target.
Raise the stop loss value as soon as the price reaches the given value, or goes in favorable direction by the given distance in price units (default = 0 = no trailing). Has only an effect when a Stop is set. The stop loss is increased in a long position, and decreased in a short position so that it normally follows the price at the distance given by the sum of the Stop and Trail distance.
For instance, Stop = 10*PIP and Trail = 5*PIP
lets the stop follow the price at 15 pips distance. A slower or faster 'movement speed' of the stop loss can be set through TrailSlope.
Trailing 'speed' in percent of the asset price change (default = 100%); has only an effect when Stop and Trail are set and the profit is above the trail distance. Example: The asset price of a long position
was above the Trail limit and goes up by more 10 pips. TrailSlope = 50 would then raise the stop loss by 5 pips. TrailSlope = 200 would raise the stop loss by 20 pips.
'Locks' a percentage of the profit (default = 0 = no profit locking); has only an effect when Stop and Trail are set and the price has exceeded the trail distance. A stop loss is then automatically placed at the given percentage of the current price excursion. Example: A long position is currently in profit by 20 pips above the entry price. TrailLock = 80 would then place the stop loss at 16 pips above entry, thus locking 80% of the profit (without trading costs). TrailLock = 1 (or any small number) would set the stop loss at the entry price when the current price reaches the Trail value. Using TrailLock is in most cases preferable to setting a profit target.
Automatically raise the stop loss every bar by a percentage of the difference between current asset price and current stop loss (default = 0 = no automatic trailing); has only an effect when Stop and Trail are set and the profit is above the trail distance. Example: A long position has a stop at USD 0.98 and the price is currently at USD 1.01. TrailStep = 10 will increase the stop loss by 0.003 (30 pips) at the next bar. TrailStep reduces the trade time dependent on the profit situation, and is often preferable to a fixed exit time with ExitTime.
Stopping and restarting a strategy counts as a step and will raise the stop loss
as if a bar had passed.
Speed factor for faster raising the stop loss before break even, in percent (default = 100%). Has only an effect when Stop and Trail are set and the profit is above the trail distance. Example: TrailSpeed = 300 will trail the stop loss with triple speed until the entry price plus spread is reached, then continue trailing with normal speed given by TrailSlope and TrailStep. Has no effect on TrailLock. This parameter can prevent that a winning trade with a slow rising stop turns into a loser.
- All parameters above must be set after selecting the asset and before calling enterLong / enterShort. They have no effect on different assets or on already entered trades, except when open trades are updated
by an enter call that did not lead to a new trade
due to MaxLong/Short
or a margin or risk limit. For changing a stop or profit target of a particular trade after it has already been opened, use either a TMF, or call exit with the new price limit (see example).
- Except for OrderLimit, all prices are Ask prices, regardless of whether they are intended for entry or exit, or for a long or a short trade. A trade is opened or closed when the Ask price reaches the given target. Zorro automatically handles the conversion from Ask to Bid: long trades are filled at the Ask price and closed at the Bid price, short trades are filled at the Bid price and closed at the Ask price. The Bid price is the Ask price minus the Spread.
- Price distances and limits need normally not be rounded, unless they are
directly sent to the broker, such as OrderLimit. Directly
sent prices are
automatically rounded to the next 1/10 pip for currencies, and to the next
pip for all other assets. If a different rounding step is needed, use the
- Some brokers reject limit orders when OrderLimit is too
close to the current price. Some broker APIs (f.i. MTR4)
do not support limit orders, but use a pending order
instead. It is not recommended to use OrderLimit
when limit orders are not properly supported by the broker.
- Either an (absolute) price, or a (relative) distance to the trade opening price (TradePriceOpen) can be used for Stop, TakeProfit, Trail, and Entry. If the value is less than half the asset price, Zorro assumes that it's a distance, otherwise it's a price.
For options the prices are always distances, f.i.
Stop = 0.7 * contractPrice(ThisContract) sets a stop limit at
70% loss. For an entry limit the given price must be negative; "buy at 10 pips below the current Low" is in code:
Entry = -(priceLow()-10*PIP);. If Stop or
TakeProfit are at the wrong side of the price, no trade is entered, but a "Skipped" message is printed in the log file.
- For setting prices or distances in pip units, multiply the pip amount with the
PIP variable (f.i. Stop = 5*PIP;). For adapting distances to the price volatility, set them not to fixed pip values, but use a multiple of
ATR(..) - this often improves the performance.
- Dependent on price data resolution, intrabar entries and exits are based
on an simulated price curve inside the bar or the tick. Intrabar fill and exit
prices are therefore normally different to the entry/exit limits and to the
close price, even when no slippage is simulated. In the simulated curve,
Stop is always triggered earlier inside the bar than
TakeProfit. This leads to a pessimistic result when
Stop and Takeprofit are triggered
within the same bar. Use TICKS mode for better precision,
especially when the trade profit depends on intrabar entry and exit limits.
- When absolute price limits are given for Trail, TakeProfit,
Entry, or Stop, they should be at the correct side of the current market price with sufficient distance. Limits at the wrong side of the price
cause error messages or unfavorable trades. When the
Entry condition is already met at entering (f.i. a long trade is entered with the market price already below the entry limit), the trade will be opened immediately at either the market price or the entry price, whatever is worse. When the
Stop limit is already met at entering, the trade will be
opened and immediately closed, losing slippage and spread. If a trade lasts only one or a few
ticks, the result by stop or trailing can become inaccurate by a large factor due to the limited resolution of the price history.
- TrailSlope, TrailStep, and TrailLock
can be set simultaneously. The stop loss limit is then trailed by their
largest movement inside a tick or bar. On a long
trade, the stop limit is trailed by the High and limited by the Low; on a
short trade it's the other way around. When the
Stop is moved inside the price range of the current bar or
tick, the trade will be immediately closed. If a more complex stop loss / take profit
/ trailing behavior is required, use a TMF. The TMF runs at every price quote - or every
tick - and can trail and check stop and profit limits.
- All stop, profit, trail, or entry limits are normally handled by software and controlled at each
tick. They are not sent to the broker's server (except for
OrderLimit and the 'fake' stop given by StopFactor) and thus not visible to the broker, this way preventing "stop hunting" or similar practices. This also steps around
NFA Compliance Rule 2-43(b) that does not allow US citizens to place stop or profit targets.
- A stop loss - regardless if it is handled by software or sent to the broker - is no guarantee to limit losses. In the case of price shocks (such as the EUR/CHF price cap removal in January 2015) trades can sometimes not be closed at the stop loss limit. The loss of the trade can then be remarkably higher.
- Stop limits updated to the broker can appear to temporarily move in 'wrong' direction by a small distance. This can happen when the spread changes at the same time, but in opposite direction as the price.
- When Zorro runs unobserved, stop loss limits are recommended, even when they appear to reduce the strategy performance. They protect against price shocks. The trade engine also uses them for calculating the risk per trade; without a stop, the capital exposure is not available and the performance statistics are less precise.
- The win rate ("accuracy") of a system mostly depends on the
Stop/Takeprofit ratio (also called risk/reward ratio).
Stop = 0.01*priceClose(); // set stop at 1% distance
bar, enterLong/Short, exitLong/Short, EntryTime, ExitTime, Lots, TMF
► latest version online