Trade parameters 1 - entry and exit limits


Enter the trade only when the price reaches a certain value at the next bar (default = 0 = enter 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.


Causes a limit order at the given ask or bid price, instead of a market order, to be sent to the broker at the next enterLong, enterShort or exitTrade call. If the order is not filled, the function call returns 0. Can be used in a tick function for filling an order at the best price within a certain time period when the precise time of entry or exit does not matter. Works only in trade mode and only when the SET_LIMIT command is supported by the broker API.


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 resp. the trade loss reaches the distance. A good value for Stop is derived from the ATR, f.i. 3*ATR(20). Setting a stop loss is recommended for risk control.


Distance of the stop loss sent to the broker to act as a 'safety net' in case of a computer crash, in relation to the real stop loss. 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, or if the NFA flag is set, the stop loss 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 trades that have no stop, such as pool trades in Virtual Hedging Mode.


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. 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, resp. 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 . 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 goes up by 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.


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.





Stop = 0.01*priceClose(); // set stop at 1% distance 

See also:

bar, enterLong/Short, exitLong/Short, EntryTime, ExitTime, Lots, TMF


► latest version online