Type/to search

Moving Average Crossover Strategy

Cryptocurrency
Created: 2023-10-24 16:39:40
Last modified: 3 years ago
1
Follow
1781
Followers

img

Overview

This strategy is based on the moving average crossover principle. It goes long when the short-term moving average crosses above the long-term moving average from below, and goes short when the short-term moving average crosses below the long-term moving average from above. It's a typical trend following strategy.

Strategy Logic

The strategy mainly calculates the short-term and long-term simple moving averages, and determines the trend direction based on their crossover.

Specifically, it first calculates the short-term moving average xMA and the long-term moving average, where the short-term period is Len, and the long-term period is 2*Len.

Then it checks if the short-term MA crosses above the long-term MA, and generates a long signal if the crossover happens. It also checks if the short-term MA crosses below the long-term MA, and generates a short signal if the crossover happens.

Upon receiving a long signal, it opens a long position at market price if there is no position. Upon receiving a short signal, it opens a short position at market price if there is no position.

In addition, stop loss and take profit points are configured. For long trades, the stop loss is set at entry price - stop loss percentage * entry price, and take profit at entry price + take profit percentage * entry price. For short trades, the stop loss is set at entry price + stop loss percentage * entry price, and take profit at entry price - take profit percentage * entry price.

Finally, the moving averages are plotted for visualization to assist with trend determination.

Advantages

  • Simple and easy to understand, suitable for beginners.

  • Can effectively track market trends based on moving average crossovers.

  • Risks are controlled by configuring stop loss and take profit.

  • Visualization of moving averages intuitively reflects trend changes.

Risks

  • Moving averages have lagging effects, which may cause missing the best entry points.

  • Improper stop loss configuration may result in stops being too wide or too tight.

  • Prices whipsawing may generate false signals.

  • Optimizing solely based on the moving average periods may lead to overfitting.

These risks can be reduced by using looser stops, optimizing moving average period combinations, adding filter indicators etc.

Optimization Directions

  • Add other indicators like MACD, KDJ for filtering to avoid false signals.

  • Optimize combinations of short and long moving average periods to find optimum parameters.

  • Test different stop loss/take profit strategies like trailing stops.

  • Add position sizing to optimize capital utilization.

Summary

The strategy has a clear and simple logic, can track trends effectively based on moving average crossovers, and has controllable risks. It is suitable for beginners to learn from. But relying solely on moving averages may generate false signals. There is still much room for optimizating it in various aspects to make it more robust.

Source
Pine
/*backtest
start: 2023-09-23 00:00:00
end: 2023-10-23 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
//@strategy_alert_message {{strategy.order.alert_message}} 
////////////////////////////////////////////////////////////
//  Copyright by HPotter v2.0 19/09/2023
Strategy parameters
Strategy parameters
Len
Take Profit %
Stop Loss %
entry
Signal Token (Optional)
Order Type
Order Price Offset
Investment Type
Amount
Comment
All comments (0)
No data
No data
  • 1
iPhone Download
Forums
PINE Language
© 2015 - ∞ INVENTOR PTE LTD (SG)