Type/to search

Trailing Stop Loss Dual Moving Average Strategy

Common strategy
Created: 2023-12-29 16:59:17
Last modified: 3 years ago
1
Follow
1802
Followers

img

Overview

This strategy uses fast and slow moving average crossovers to determine long and short positions. It goes long when the fast MA crosses over the slow MA and closes position when the fast MA crosses below the slow MA. To pursue higher profits, the strategy adopts a trailing stop loss mechanism. Instead of setting the stop loss price right below the entry price after opening long positions, it sets a trailing stop loss price which moves up following the price rise until the price drop hits the stop loss price limit.

How it works

The strategy uses fast and slow Simple Moving Average (SMA) lines to determine entries and exits. When the fast SMA crosses over the slow SMA, it signals an uptrend so the strategy goes long. When the fast SMA crosses below the slow SMA, it signals a trend reversal so the strategy prepares to close position.

To maximize profits, the strategy introduces a trailing stop loss mechanism. Instead of using a fixed stop loss price after opening long positions, it sets a trailing stop loss price which moves up following the price rise. Each time the price rises by a certain percentage, the trailing stop loss price adjusts up by a predefined percentage. When the price pulls back and hits the trailing stop loss price, it triggers the stop loss order to close position.

Specifically, the trailing stop loss price is calculated as:

Trailing Stop Loss Price = Price × (1 - Stop Loss Trailing Percentage)

The Stop Loss Trailing Percentage is defined by the strategy parameter “Deviation %”. The strategy recalculates the trailing stop loss price on every bar's close. The new trailing stop loss price cannot be lower than that of the previous bar, so as to ensure the stop loss price only moves up, not down.

When the price drops and hits the trailing stop loss price, it triggers the closing signal and the position will be closed by a market order.

Advantages

  • Use dual moving average to determine trend direction with good backtest results
  • Adopt trailing stop loss to pursue higher profits
  • Customizable moving average periods and stop loss trailing percentage
  • Stop loss line keeps moving up when trend goes up, locking in most profits
  • Quick stop loss when trend reverses to avoid further losses

Risks and Solutions

  • Improper moving average crossover timing may cause false signals. Test different parameters to find the optimal MA combination
  • Overly aggressive trailing stop loss may get stopped out prematurely. Adjust the stop loss trailing percentage parameter properly
  • Price gaps may directly penetrate the stop loss price. Consider combining other indicators to judge trend and avoid trading during ranging periods

Optimization Directions

  • Test different moving average period parameters to find the optimal combination
  • Test different stop loss trailing percentage parameters to find the optimal stop loss level
  • Add other indicators to suspend trading during ranging periods to avoid being affected by sporadic events

Conclusion

This strategy combines moving average indicators to judge trend direction and trailing stop loss mechanism to lock in profits, performing well on training data. By optimizing parameters and controlling risks, it has the potential to achieve steady profits. However, no strategy can completely avoid losses. It's recommended to adjust position sizing, test different products, and diversify risks.

Source
Pine
/*backtest
start: 2022-12-22 00:00:00
end: 2023-12-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 
//  -----------------------------------------------------------------------------
Strategy parameters
Strategy parameters
Filters
From
fromDate
To 
toDate
Strategy
Fast/Slow SMA Length
slowMALen
Exit
Enable Trailing
Deviation %
Source Exit Control
Comment
All comments (0)
No data
No data
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)