
Chiến lược này dựa trên hai đường trung bình và chỉ số cường độ tương đối, kết hợp với biến động lịch sử của cổ phiếu, để thực hiện mua và bán cổ phiếu tự động. Ưu điểm của chiến lược là thực hiện kết hợp đường dài và đường ngắn, có thể kiểm soát rủi ro hiệu quả.
Chiến lược sử dụng hệ thống hai đường bằng nhau bao gồm đường trung bình linea 150 tuần và đường trung bình nhanh 50 ngày, và đường trung bình nhanh nhất 20 ngày. Khi giá vượt qua đường 150 tuần, giá được coi là bắt đầu đi lên, và khi giá vượt qua đường 50 ngày, giá được coi là bắt đầu đi xuống.
Ngoài ra, chiến lược này cũng sử dụng giá cao nhất của biến động hàng năm và chỉ số cường độ tương đối để xác định thời điểm mua cụ thể. Chỉ khi giá đóng cửa vượt quá giá cao nhất tính toán của biến động hàng năm và chỉ số cường độ tương đối là tích cực, tín hiệu mua sẽ được phát đi.
Để giải quyết rủi ro, bạn có thể đặt mức dừng lỗ hoặc sử dụng số nhân của chỉ số ATR làm mức dừng lỗ. Ngoài ra, bạn có thể tối ưu hóa các tham số bằng cách đo lại nghiêm ngặt hơn.
Chiến lược này nói chung là một chiến lược đầu tư cổ phiếu tương đối bảo thủ. Sử dụng hai đường trung bình để đánh giá xu hướng chính, và kết hợp với dao động và cường độ của các chỉ số tham gia, có thể lọc hiệu quả phá vỡ giả mạo. Việc thêm đường trung bình nhanh cũng làm cho việc dừng lỗ nhanh hơn.
/*backtest
start: 2023-12-12 00:00:00
end: 2023-12-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//Relative Strength
strategy("Stan my man", overlay=true)
comparativeTickerId = input("BTC_USDT:swap", title="Comparative Symbol")
l = input(50, type=input.integer, minval=1, title="Period")
baseSymbol = security(syminfo.tickerid, timeframe.period, close)
comparativeSymbol = security(comparativeTickerId, timeframe.period, close)
hline(0, color=color.black, linestyle=hline.style_dotted)
res = baseSymbol / baseSymbol[l] /(comparativeSymbol / comparativeSymbol[l]) - 1
plot(res, title="RS", color=#1155CC)
//volume ma
vol1 = sma(volume,20)
// 30 week ma
ema1 = ema(close, 150)
//consolidation
h1 = highest(high[1],365)
fastPeriod = input(title="Fast MA", type=input.integer, defval=50)
slowPeriod = input(title="Slow MA", type=input.integer, defval=150)
fastestperiod = input(title="Fastest MA", type=input.integer, defval=20)
fastEMA = ema(close, fastPeriod)
slowEMA = ema(close, slowPeriod)
fastestEMA = ema(close, fastestperiod)
monitorStrategy = close < close[20]
// trade conditions
buytradecondition1 = close >ema1 and res>0 and volume> 1.5*vol1 and close > h1
buytradecondition2 = close > fastEMA and volume> 1.5* vol1
selltradecondition1 = close< 0.95 * fastEMA
selltradecondition2 = close< 0.90 * open
if (buytradecondition1)
strategy.entry("long",strategy.long,alert_message ="Seems ready to Buy")
alert("Buy Alert Price (" + tostring(close) + ") crossed over Slow moving average",alert.freq_all)
if (buytradecondition2)
strategy.entry("long",strategy.long,alert_message ="Seems ready to Buy")
alert("Buy Alert Price (" + tostring(close) + ") crossed over fast moving average",alert.freq_all)
if (selltradecondition1)
strategy.close("long",alert_message ="Seems ready to Sell")
alert("Sell Alert Price (" + tostring(close) + ") crossed down fast moving average",alert.freq_all)
if (selltradecondition2)
strategy.close("long",alert_message ="Seems ready to Sell")
alert("Sell Alert Price (" + tostring(close) + ") crossed down 10% below open price ",alert.freq_all)
//alertcondition(buytradecondition1,title ="BuySignal", message ="Price Crossed Slow Moving EMA ")
plot(fastEMA, color=color.navy)
plot(slowEMA, color=color.fuchsia)
plot(fastestEMA, color=color.green)