Type/to search

MACD Moving Average Crossover Trend Following Strategy with Trailing Stop Loss

Cryptocurrency
Created: 2023-11-06 11:56:14
Last modified: 3 years ago
1
Follow
1779
Followers

img

Overview

This strategy uses MACD to determine the trend direction, combined with EMA and SMA crossover as confirmation. The entry signal is when MACD histogram crosses above signal line and the trend is up. The stop loss is set at the price level below the floating ATR trailing stop. The strategy also exits partially to take profit, exits more on larger price surge, and holds some position with trailing stop until stop loss is hit.

Logic

Entry Signal

When faster EMA crosses above slower EMA, it indicates the short term trend is better than long term trend, signaling a buy. Meanwhile, faster SMA crossing above slower SMA also suggests stronger upside momentum in short term. So the combination of MACD line crossing above signal and uptrend based on EMA&SMA crossover helps identify stronger entry signals.

Stop Loss

ATR is used to calculate the stop loss level. ATR can effectively measure the price fluctuation range. When price breaks below this range, the stop loss is triggered. The ATR period can be adjusted - smaller period allows more precise stop but easier to get stopped out, while larger period gives wider stop but more robust. The stop level also trails the price upside, achieving trend following effect.

Exit Signals

Exits partially on small price surge to take profit. Exits more on large price spike to lock in profit. Keeps some position with trailing stop until stop loss is hit. This helps lock in profit, while still be able to hold position for some period.

Advantages

  • MACD judging trend combined with EMA/SMA crossover confirms entry timing
  • ATR trailing stop allows effective stop loss while following trend
  • Partial exits help take profit, lock in profit and hold for duration

Risks & Solutions

  • Risk of wrong signal from MACD and trend indicators. Fine tune parameters or add other indicators.

  • Risk of ATR stop loss being hit. Can increase ATR period or stop loss multiplier.

  • Risk of trailing position being trapped. Reduce trailing position size and cut loss in time.

Enhancement Opportunities

  • Optimize MACD parameters for better trend judgment

  • Optimize ATR period for better stop loss level

  • Optimize exit ratios and position sizing to reduce trapped risk

  • Consider adding moving take profit or volatility index to improve stop loss

Summary

The strategy combines MACD, EMA/SMA and other indicators to determine trend and entry timing accurately. The floating ATR stop loss helps lock in profit while following the trend. Exits are staggered to take profit, ensure gain and hold position for duration. Overall it is stable with decent result. But parameters and exits can be further optimized for better return.

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Deobald

//@version=4
Strategy parameters
Strategy parameters
Period
Fast Length
Slow Length
Source
Signal Smoothing
Simple MA(Oscillator)
Simple MA(Signal Line)
Long Take Profit 1 %
Long Take Profit 1 Qty
Long Take Profit 2%
Long Take Profit 2 Qty
SL Mutiplier
ATR period
Backtest Start Year
Backtest Start Month
Backtest Start Day
Backtest Stop Year
Backtest Stop Month
Backtest Stop Day
Comment
All comments (0)
No data
No data
  • 1
iPhone Download
Forums
PINE Language
© 2015 - ∞ INVENTOR PTE LTD (SG)