Type/to search

Trend Following Strategy Based on Moving Average

Common strategy
Created: 2024-01-24 14:24:36
Last modified: 3 years ago
1
Follow
1802
Followers

img

Overview

This is a simple trend following strategy based on moving average. It judges the current trend direction and duration by comparing the size relationship between moving averages of different cycles. It goes long when the short cycle moving average crosses above the long cycle one, and goes short when the opposite happens. At the same time, stop loss and take profit points are set to control risks.

Strategy Logic

The strategy uses 4 moving averages with different cycles: 5-day, 10-day, 15-day and 25-day lines. They are called MA1, MA2, MA3 and MA4. Among them, MA1 is the shortest and MA4 is the longest.

When MA1>MA2>MA3>MA4, it indicates an upward trend and goes long. When MA1<MA2<MA3<MA4, it indicates a downward trend and goes short.

The open position conditions for both long and short need to satisfy the ATR stop loss filter at the same time, that is, the ATR value should be greater than the 40-day SMA of ATR. This avoids generating wrong signals when the price fluctuation is too small.

Advantage Analysis

The strategy has the following advantages:

  1. The logic is simple and easy to implement.
  2. Using multiple moving averages to determine the trend direction is reliable.
  3. Setting stop loss and take profit points can effectively control the maximum loss per trade.
  4. The ATR stop loss filter avoids wrong signals when the price fluctuation is small.

Risk Analysis

The strategy also has the following risks:

  1. It is easy to generate wrong signals in a largely shock market.
  2. Improper parameter settings (cycle of moving average, etc) may lead to poor strategy performance.
  3. It does not consider the impact of fundamentals and significant news on prices.

To reduce these risks, parameters can be optimized appropriately, or additional filter conditions can be added to improve strategy stability.

Optimization Directions

The optimization directions of the strategy include:

  1. Test different combinations of moving average cycle parameters to find the optimal parameters.
  2. Add other technical indicators filters such as MACD and KDJ to judge the reliability of signals.
  3. Add trading volume filter, only trade when trading volume expands.
  4. Fine-tune parameters based on differences between varieties.
  5. Add machine learning algorithms to judge signals.

Conclusion

In general, this is a relatively simple trend following strategy. It judges the trend direction through moving averages and sets reasonable stop loss and take profit to control risk levels. There is still much room for optimization, such as adjusting parameters, adding filters etc. to further improve the stability and profitability of the strategy.

Source
Pine
/*backtest
start: 2023-01-17 00:00:00
end: 2024-01-23 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/
// © fpemehd
// @version=5
Strategy parameters
Strategy parameters
Time
Start Date
End Date
Long / Short
Long?
Short?
Filters
ATR Filter On?
SMA Length for ATR SMA
Shared Inputs
Enable SL & TP?
Enable Trailing SL?
Stop Loss Type
ATR Length
Take Profit Type
Take Profit Quantity %
Long Stop Loss / Take Profit
SL Percent
TP Percent
SL ATR Multiplier
TP ATR Multiplier
R:R Ratio
Short Stop Loss / Take Profit
SL Percent
TP Percent
SL ATR Multiplier
TP ATR Multiplier
R:R Ratio
Strategy
MA Type
MA 1 Length
MA 2 Length
MA 3 Length
MA 4 Length
ALMA Offset Value
ALMA Sigma Value
Comment
All comments (0)
No data
No data
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)