
Strategi ini membandingkan harga penutupan K-Line semasa dengan harga penutupan K-Line terdahulu untuk menentukan sama ada ia akan mencetuskan isyarat beli atau jual.
Khususnya, jika harga penutupan K semasa lebih tinggi daripada harga tertinggi K sebelumnya, ia akan mencetuskan isyarat beli; jika harga penutupan K semasa lebih rendah daripada harga terendah K sebelumnya, ia akan mencetuskan isyarat jual.
Ini adalah logik dasar dalam strategi ini.
Strategi ini secara keseluruhannya mudah dan jelas, menggunakan maklumat harga penutupan K untuk menentukan arah trend, sambil menetapkan risiko kawalan hentian berhenti, boleh digunakan sebagai strategi asas untuk perdagangan saham, mata wang digital. Tetapi hanya berdasarkan bentuk garis K untuk tempoh masa tunggal, mudah menghasilkan isyarat palsu, ruang pengoptimuman masih besar, perlu dipertimbangkan lebih lanjut untuk menggabungkan lebih banyak faktor dan penyesuaian parameter, untuk meningkatkan keberkesanan strategi.
/*backtest
start: 2023-12-08 00:00:00
end: 2024-01-07 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Buy/Sell on Candle Close", overlay=true)
var float prevLowest = na
var float prevHighest = na
var float slDistance = na
var float tpDistance = na
// Specify the desired timeframe here (e.g., "D" for daily, "H" for hourly, etc.)
timeframe = "D"
// Fetching historical data for the specified timeframe
pastLow = request.security(syminfo.tickerid, timeframe, low, lookahead=barmerge.lookahead_on)
pastHigh = request.security(syminfo.tickerid, timeframe, high, lookahead=barmerge.lookahead_on)
if bar_index > 0
prevLowest := pastLow[1]
prevHighest := pastHigh[1]
currentClose = close
if not na(prevLowest) and not na(prevHighest)
slDistance := prevHighest - prevLowest
tpDistance := 3 * slDistance // Adjusted for 1:3 risk-reward ratio
// Buy trigger when current close is higher than previous highest
if not na(prevLowest) and not na(prevHighest) and currentClose > prevHighest
strategy.entry("Buy", strategy.long)
strategy.exit("Buy TP/SL", "Buy", stop=prevLowest - slDistance, limit=prevHighest + tpDistance)
// Sell trigger when current close is lower than previous lowest
if not na(prevLowest) and not na(prevHighest) and currentClose < prevLowest
strategy.entry("Sell", strategy.short)
strategy.exit("Sell TP/SL", "Sell", stop=prevHighest + slDistance, limit=prevLowest - tpDistance)
plot(prevLowest, color=color.blue, title="Previous Lowest")
plot(prevHighest, color=color.red, title="Previous Highest")