admin

Understand Stop Loss Mechanism

Economy & Market


Basic Stop Loss

Stop loss is an order exit mechanism that is commonly used for downside protection. When we submit orders to a trading system, a stop loss level specifies the price level at which the long (short) position will be automatically and immediately unwound if the underlying price drops to or below (increase to or above) such level.

The setup of stop loss level should be

  • less than or equal to the current market bid price for opening a buy position
  • greater than or equal to the current market ask price for opening a sell position

The stop loss level is usually fixed at order opening, and will be continously monitored by trading system for market trigger. As market price changes discontinuously, a stop-loss order does not gurantee cutting loss exectly at the stop loss level, particularly during a highly volatile period.

Stop Buy Stop Sell

On ALGOGENE, it can be implemented as follows:

order = AlgoAPIUtil.OrderObject(
    instrument = 'BTCUSD',
    openclose = 'open', 
    buysell = 1,    #1 for buy, -1 for sell
    ordertype = 1,  #0 for market order, 1 for limit order
    volume = 0.1, 
    price = 40000,
    stopLossLevel = 39000
)
self.evt.sendOrder(order)


Trailing Stop Loss

Traders can enhance the mechanism with a trailing stop, where the stop level isn't fixed at a single point. Instead, trailing stop is set at a certain percentage/amount below the market price (or above for short position). When the price increases, it drags the trailing stop along with it. Then when the price stops rising, the new stop-loss price remains at the level it was previously dragged to. Thus, it automatically protects an investor's downside, while locking in profits when the price reaches new highs.

For example, we purchase a stock at $100, and set up a trailing amount = $2. The immediate effective stop-loss value will be $98. If the market price climbs to $110.7, your trailing stop value will rise to $108.7. If the last price now drops to $110.0, your stop value will remain intact at $108.7. If the price continues to drop, this time to $108.6, it will penetrate your stop-level, immediately triggering a market order. Your order would be submitted based on the last price of $108.6. Assuming that the bid price was $108.5 at the time, the position would be closed at this point. The net gain would be $8.5 per share.

Trailing Stop

On ALGOGENE, trailing stop can easily be implemented as follows:

order = AlgoAPIUtil.OrderObject(
    instrument = 'BTCUSD',
    openclose = 'open', 
    buysell = 1,    #1 for buy, -1 for sell
    ordertype = 1,  #0 for market order, 1 for limit order
    volume = 0.1, 
    price = 40000,
    trailingstop = 0.05    #as a percentage
)
self.evt.sendOrder(order)


Combining Both

When combining the basic stop-losses with trailing stops, it's important to calculate your maximum risk tolerance. For example, you could set a stop-loss at 5% below the current stock price and the trailing stop at 8% below the current stock price. As share price increases, the trailing stop will surpass the fixed stop-loss, rendering it redundant or obsolete. Any further price increases will mean further minimizing potential losses with each upward price tick. The added protection is that the trailing stop will only move up, during market hours, the trailing feature will consistently recalculate the stop's trigger point.

Similarly, we can attach the 2 parameters together in ALGOGENE API.

order = AlgoAPIUtil.OrderObject(
    instrument = 'BTCUSD',
    openclose = 'open', 
    buysell = 1,    #1 for buy, -1 for sell
    ordertype = 1,  #0 for market order, 1 for limit order
    volume = 0.1, 
    price = 40000,
    stopLossLevel = 39000,
    trailingstop = 0.05    #as a percentage
)
self.evt.sendOrder(order)