Chiến lược củng cố trung bình động động

Tác giả:ChaoZhang, Ngày: 2024-01-25 11:39:00
Tags:

img

Tổng quan

Chiến lược này chủ yếu sử dụng sự củng cố được hình thành bởi các đường trung bình động HMA và EMA để xác định thời gian mua. Khi HMA vượt qua EMA, nó được coi là sự củng cố đã kết thúc và một xu hướng tăng mới được hình thành, vì vậy mua khi HMA vượt qua EMA cùng một lúc.

Chiến lược cũng kết hợp chỉ số RSI để phát hiện các điều kiện mua quá mức và bán quá mức. Nó cho phép mua khi RSI dưới 70 và xem xét lấy lợi nhuận một phần khi RSI trên 80.

Nguyên tắc chiến lược

Chiến lược này sử dụng một hệ thống trung bình động được xây dựng với EMA và HMA 200 giai đoạn. Trong số đó, chỉ số HMA là một chỉ số trung bình động nhạy cảm hơn được thiết kế dựa trên EMA. Khi HMA vượt qua trên EMA, điều đó có nghĩa là giai đoạn hợp nhất đã kết thúc và giá cổ phiếu bắt đầu tăng.

Trong trường hợp một vị trí hiện có, nếu giá cổ phiếu giảm trở lại và HMA vượt qua dưới EMA một lần nữa, cho thấy sự khởi đầu của một sự củng cố mới, toàn bộ vị trí sẽ được đóng.

Logic giao dịch của chiến lược này khá đơn giản, chủ yếu dựa trên các đường băng dài và ngắn của HMA và EMA, kết hợp với các điểm cao và thấp của RSI, để tạo thành một chiến lược giao dịch tương đối mạnh mẽ.

Phân tích lợi thế

Lợi thế lớn nhất của chiến lược này là bằng cách sử dụng mô hình giao dịch hợp nhất của EMA và HMA, hầu hết các Phạm vi Phạm vi có thể được lọc ra, do đó cải thiện tỷ lệ lợi nhuận.

Ngoài ra, chiến lược này chỉ sử dụng 3 chỉ số và logic đơn giản, giúp tối ưu hóa các tham số và kiểm tra hậu quả dễ dàng, điều này tạo điều kiện cho việc xác minh và cải thiện các chiến lược.

Phân tích rủi ro

Mặc dù chiến lược này có một số lợi thế, nhưng vẫn có một số rủi ro cần lưu ý. Ví dụ, thời gian nắm giữ có thể tương đối dài, đòi hỏi đủ tiền để hỗ trợ. Nếu nó gặp một giai đoạn củng cố bên, nó không thể thoát nhanh chóng với một mức dừng lỗ, dễ dàng dẫn đến tình huống mở rộng lỗ.

Ngoài ra, chiến lược này chủ yếu dựa trên các chỉ số trung bình động. Nếu có sự đột phá bất thường trong giá, các biện pháp dừng lỗ có thể không có hiệu lực, điều này sẽ mang lại rủi ro lớn hơn. Ngoài ra, cài đặt tham số cũng sẽ ảnh hưởng đến hiệu suất chiến lược và yêu cầu thử nghiệm rộng rãi để tìm các tham số tối ưu.

Hướng dẫn tối ưu hóa

Xem xét các rủi ro trên, chiến lược này có thể được tối ưu hóa trong các khía cạnh sau:

  1. Kết hợp các chỉ số biến động để điều chỉnh động các vị trí dựa trên biến động thị trường.

  2. Tăng đánh giá chỉ số xu hướng để tránh giao dịch đảo ngược không cần thiết.

  3. Tối ưu hóa các thông số trung bình động để làm cho chúng gần hơn với các đặc điểm thị trường hiện tại.

  4. Sử dụng thời gian dừng lại để tránh mất mát đơn quá lớn.

Tóm lại

Nhìn chung, đây là một chiến lược hợp nhất và biến động tương đối đơn giản. Nó chủ yếu được sử dụng cho giao dịch chỉ số chứng khoán ngắn hạn và trung hạn và cổ phiếu nóng, và có thể đạt được các giá trị alpha tương đối ổn định. Với việc tối ưu hóa các thông số và tăng cường các biện pháp kiểm soát rủi ro, hiệu suất của chiến lược này vẫn có nhiều chỗ để cải thiện.


/*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/
// © mohanee

//@version=4
strategy(title="EMA_HMA_RSI_Strategy", overlay=true, pyramiding=2,     default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed, 

//longCondition = crossover(sma(close, 14), sma(close, 28))
//if (longCondition)
    //strategy.entry("My Long Entry Id", strategy.long)

//shortCondition = crossunder(sma(close, 14), sma(close, 28))
//if (shortCondition)
  //  strategy.entry("My Short Entry Id", strategy.short)

//HMA
HMA(src1, length1) =>  wma(2 * wma(src1, length1/2) - wma(src1, length1), round(sqrt(length1)))

var stopLossVal=0.00

//variables BEGIN
length=input(200,title="EMA and HMA Length")   //square root of 13

rsiLength=input(13, title="RSI Length")

takePartialProfits = input(true, title="Take Partial Profits (if this selected, RSI 13 higher reading over 80 is considered for partial closing ) ")

stopLoss = input(title="Stop Loss%", defval=8, minval=1)
//variables  END

//RSI 
rsi13=rsi(close,rsiLength)


ema200=ema(close,length)
hma200=HMA(close,length)

//exitOnAroonOscCrossingDown = input(true, title="Exit when Aroon Osc cross down zero ")


// Drawings

//Aroon oscillator

arronUpper = 100 * (highestbars(high, length+1) + length)/length
aroonLower = 100 * (lowestbars(low, length+1) + length)/length

aroonOsc  = arronUpper - aroonLower

aroonMidpoint = 0
//oscPlot = plot(aroonOsc, color=color.green)
//midLine= plot(aroonMidpoint, color=color.green)
//topLine = plot(90,style=plot.style_circles, color=color.green)
//bottomLine = plot(-90,style=plot.style_circles, color=color.red)

//fill(oscPlot, midLine, color=aroonOsc>0?color.green:color.red, transp=50)
//fill(topLine,bottomLine, color=color.blue)
//fill(topLine,oscPlot, color=aroonOsc>90?color.purple:na, transp=25)


// RSI 
//plot(rsi13, title="RSI", linewidth=2, color=color.purple)
//hline(50, title="Middle Line", linestyle=hline.style_dotted)
//obLevel = hline(80, title="Overbought", linestyle=hline.style_dotted)
//osLevel = hline(30, title="Oversold", linestyle=hline.style_dotted)
//fill(obLevel, osLevel, title="Background", color=rsi13 >=30 ? color.green:color.purple, transp=65)  // longTermRSI >=50

hullColor = hma200 > hma200[2] ? #00ff00 : #ff0000

plot(hma200, title="HULL 200", color=hullColor,  transp=25)
plot(ema200, title="EMA 200", color=color.orange)

//Entry--
strategy.initial_capital = 50000
strategy.entry(id="Long Entry", comment="LE", qty=(strategy.initial_capital * 0.10)/close, long=true,  when=strategy.position_size<1 and hma200 < ema200   and  hma200 > hma200[2]  and rsi13<70 )     //  // aroonOsc<0

//Add
if(strategy.position_size>=1 and  close < strategy.position_avg_price and  ( crossover(rsi13,30) or  crossover(rsi13,40) ) )   // hma200 < ema200   and  hma200 > hma200[2]   and hma200[2] < hma200[3] )  //and crossover(rsi13,30)  aroonOsc<0    //and hma200 > hma200[2]  and hma200[2] <= hma200[3]  //crossover(rsi13,30)
    qty1=(strategy.initial_capital * 0.10)/close
    //stopLossVal:= abs(strategy.position_size)>1 ?  ( (close > close[1] and close > open and close>strategy.position_avg_price) ? close[1]*(1-stopLoss*0.01) : stopLossVal ) : 0.00 
    strategy.entry(id="Long Entry", comment="Add", qty=qty1, long=true )     //crossover(close,ema34)  //and close>ema34  //crossover(rsi5Val,rsiBuyLine)  --   SL="+tostring(stopLossVal, "####.##")


//stopLossVal:= abs(strategy.position_size)>1 ? strategy.position_avg_price*(1-0.5) : 0.00 

stopLossVal:= abs(strategy.position_size)>1 ?  ( (close > close[1] and close > open and close>strategy.position_avg_price) ? close[1]*(1-stopLoss*0.01) : stopLossVal ) : 0.00 
//stopLossVal:= abs(strategy.position_size)>1 ?  strategy.position_avg_price*(1-stopLoss*0.01) :  0.00

barcolor(color=strategy.position_size>=1? rsi13>80 ? color.purple: color.blue:na)

//close partial
if(takePartialProfits==true)
    strategy.close(id="Long Entry", comment="Partial X  points="+tostring(close - strategy.position_avg_price, "####.##"),  qty_percent=20 , when=abs(strategy.position_size)>=1 and crossunder(rsi13, 80)  and close > strategy.position_avg_price  )   //close<ema55 and rsi5Val<20 //ema34<ema55



//close All
//if(exitOnAroonOscCrossingDown)
  //  strategy.close(id="Long Entry", comment="Exit All points="+tostring(close - strategy.position_avg_price, "####.##"),  when=abs(strategy.position_size)>=1 and crossunder(aroonOsc, 0) )   //close<ema55 and rsi5Val<20 //ema34<ema55  //close<ema89

//close All on stop loss
strategy.close(id="Long Entry", comment="Stoploss X points="+tostring(close - strategy.position_avg_price, "####.##"),  when=abs(strategy.position_size)>=1 and close < stopLossVal  )  //close<ema55 and rsi5Val<20 //ema34<ema55  //close<ema89

strategy.close(id="Long Entry", comment="hmaXema X points="+tostring(close - strategy.position_avg_price, "####.##"),  when=abs(strategy.position_size)>=1 and close > strategy.position_avg_price  and  crossunder(hma200,ema200)  )  //close<ema55 and rsi5Val<20 //ema34<ema55  //close<ema89
    

Thêm nữa