资源加载中... loading...

Moving Average Trend Tracking Strategy

Author: ChaoZhang, Date: 2024-01-29 11:46:15
Tags:

img

Overview

This is a trend-based quantitative trading strategy. It mainly uses three moving average lines with different periods, combined with the ATR indicator, to track market trends and assist in determining entry and exit timing.

Principle

The strategy uses three moving average lines of 9 days (short-term), 15 days (medium-term), and 24 days (long-term). Among them, the 9-day and 15-day lines are used to determine the trend direction and entry timing, while the 24-day line is used to determine profit-taking and stop-loss. At the same time, the strategy also incorporates the ATR indicator to dynamically adjust the moving average lines to better adapt to market fluctuations.

Specifically, when the short-term moving average line crosses above the medium-term moving average line, and the closing price is greater than the short-term moving average line, it indicates that the trend is starting to emerge, and long positions can be established at this point. When the short-term moving average line crosses below the long-term moving average line, or the closing price is below the long-term moving average line, it signifies a trend reversal, so existing positions should be closed for stop loss or short positions can be initiated.

In addition, the strategy also uses the bar color to intuitively display the trend direction. The bars are colored green when the short-term line is above the medium-term line, and red when below the long-term line.

Advantages

  1. Using a combination of three moving average lines with different periods can judge the trend direction more accurately
  2. Applying ATR-based dynamic adjustment of moving average lines adapts better to volatile markets
  3. Setting long and short stop-loss/profit-taking mechanisms effectively manages risks
  4. Visual effects of the bar colors form effective pattern signals, making trading actions clearer

Risks and Optimization

  1. Prone to generating false signals in range-bound markets
  2. Improper parameter settings (e.g. period parameters) may lead to over-trading or missing good entry opportunities
  3. Consider incorporating other filters for entry signals, such as volume, MACD etc.
  4. Different parameter combinations can be tested to find the optimal parameters

Conclusion

Overall this is a relatively robust trend-following strategy. It can effectively capture medium to long term trends, while setting stop loss/profit taking mechanisms to control risks. But the strategy is sensitive to parameters and market conditions, requiring further optimization to adapt to more market environments.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
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/
// © ceyhun

//@version=4
strategy("Chaloke System Strategy",overlay=true)

P1=input(9,title="ShortTerm Period")
P2=input(15,title="MidTerm Period")
P3=input(24,title="LongTerm Period")
P4=input(5,title="Invesment Term")
P5=input(5,title="ATR Period")
Barcolor=input(true,title="Barcolor")

Sm=2*P5/10
ATRX=Sm*atr(P4)
S=ema(close,P1)-ATRX
M=ema(close,P2)-ATRX
Lg=ema(close,P3)-ATRX

Sht=iff(close==highest(close,3),S,ema(close[1],P1)-ATRX)
Mid=iff(close==highest(close,3),M,ema(close[1],P2)-ATRX)
Lng=iff(close==highest(close,3),Lg,ema(close[1],P3)-ATRX)

colors=iff(Sht>Mid and close > Sht ,color.green,iff(close < Lng or Sht<Lng,color.red,color.black))

plot(Sht,"Short",color=color.green,linewidth=2)
plot(Mid,"Middle",color=color.black,linewidth=2)
plot(Lng,"Long",color=color.red,linewidth=2)

barcolor(Barcolor ? colors :na)
   
long =  crossover(Sht,Mid) and close > Sht
short = crossunder(Sht,Lng) or close < Lng

if long
    strategy.entry("Long", strategy.long, comment="Long")
    
if short
    strategy.entry("Short", strategy.short, comment="Short")

alertcondition(long, title='Long', message='Chaloke System Alert Long')
alertcondition(short, title='Short', message='Chaloke System Alert Short')

More