
Chiến lược này dựa trên giá trị RSI của MACD để đánh giá tín hiệu mua và bán. Mua khi giá trị RSI vượt quá đường mua hoặc bán, dừng hoặc dừng khi giá trị RSI vượt quá bán.
Chiến lược này kết hợp những ưu điểm của MACD và RSI.
Đầu tiên, tính ba đường cong của MACD, bao gồm đường DIF, đường DEA và đường MACD. Sau đó, tính RSI trên đường MACD để tạo ra RSI của MACD.
Khi chỉ số RSI of MACD vượt quá 30 hoặc 35 trong phạm vi bán tháo, nó sẽ tạo ra tín hiệu mua, cho thấy đường MACD đã đi vào phạm vi bán tháo và xu hướng giá cổ phiếu bắt đầu đảo ngược lên. Khi chỉ số RSI of MACD lại giảm xuống 15 trong phạm vi bán tháo, nó sẽ tạo ra tín hiệu bán tháo, cho thấy xu hướng đảo ngược đã kết thúc.
Chiến lược này cũng đặt một phần dừng, bán một phần vị trí khóa một phần lợi nhuận khi chỉ số RSI of MACD vượt quá 80.
Giải pháp:
Chiến lược này cũng có thể được tối ưu hóa theo các hướng sau:
Chiến lược này được thiết kế rõ ràng, ý tưởng cốt lõi là sử dụng MACD đảo ngược kết hợp với bộ lọc RSI để xác định điểm mua và bán. Thông qua các phương tiện tối ưu hóa tham số, quản lý dừng lỗ, kiểm soát rủi ro, nó có thể trở thành một chiến lược giao dịch định lượng rất thực tế.
/*backtest
start: 2024-01-07 00:00:00
end: 2024-01-14 00:00:00
period: 3m
basePeriod: 1m
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="RSI of MACD Strategy[Long only]", shorttitle="RSIofMACD" , overlay=false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, currency=currency.USD) //default_qty_value=10, default_qty_type=strategy.fixed,
/////////////////////////////////////////////////////////////////////////////////
// MACD Inputs ///
fastLen = input(12, title="Fast Length")
slowLen = input(21, title="Slow Length")
sigLen = input(9, title="Signal Length")
rsiLength = input(14, title="RSI of MACD Length")
riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(3,title="Stop Loss",minval=1)
takeProfit=input(false, title="Take Profit")
[macdLine, signalLine, _] = macd(close, fastLen, slowLen, sigLen)
rsiOfMACD = rsi(macdLine, rsiLength)
emaSlow = ema(close, slowLen)
//drawings
/////////////////////////////////////////////////////////////////////////////////
obLevelPlot = hline(80, title="Overbought / Profit taking line", color=color.blue , linestyle=hline.style_dashed)
osLevelPlot = hline(30, title="Oversold / entry line", color=color.green, linestyle=hline.style_dashed)
exitLinePlot = hline(15, title="Exit line", color=color.red, linestyle=hline.style_dashed)
plot(rsiOfMACD, title = "rsiOfMACD" , color=color.purple)
//drawings
/////////////////////////////////////////////////////////////////////////////////
//Strategy Logic
/////////////////////////////////////////////////////////////////////////////////
//Entry--
//Echeck how many units can be purchased based on risk manage ment and stop loss
qty1 = (strategy.equity * riskCapital / 100 ) / (close*stopLoss/100)
//check if cash is sufficient to buy qty1 , if capital not available use the available capital only
qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1
strategy.entry(id="RSIofMACD", long=true, qty=qty1, when = ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35) ) and close>=emaSlow )
bgcolor(abs(strategy.position_size)>=1 ? color.blue : na , transp=70)
barcolor(abs(strategy.position_size)>=1 and ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35) ) ? color.purple : abs(strategy.position_size)>=1 ? color.blue : na )
//partial exit
strategy.close(id="RSIofMACD", comment="PExit Profit is "+tostring(close - strategy.position_avg_price, "###.##") , qty=strategy.position_size/3, when= takeProfit and abs(strategy.position_size)>=1 and close > strategy.position_avg_price and crossunder(rsiOfMACD,80) )
//Close All
strategy.close(id="RSIofMACD", comment="Close All Profit is "+tostring(close - strategy.position_avg_price, "###.##"), when=abs(strategy.position_size)>=1 and crossunder(rsiOfMACD,15) ) //and close > strategy.position_avg_price )
//Strategy Logic
/////////////////////////////////////////////////////////////////////////////////