
이 전략은 현재 K선과 이전 K선의 종결 가격을 비교하여 구매 또는 판매 신호를 유발하는지 판단합니다.
구체적으로, 만약 현재 K 라인 닫기 가격이 상위 K 라인 최고 가격보다 높다면, 구매 신호를 유발한다; 만약 현재 K 라인 닫기 가격이 상위 K 라인 최저 가격보다 낮다면, 판매 신호를 유발한다.
이 전략의 기본 거래 논리는 다음과 같습니다.
이 전략의 전체적인 아이디어는 간단하고 명확하며, K 라인 종결 가격 정보를 사용하여 트렌드 방향을 판단하고, 동시에 스톱 스톱 제어 위험을 설정할 수 있으며, 주식, 디지털 통화 거래의 기본 전략으로 사용할 수 있다. 그러나 단 하나의 시간 주기 K 라인 형태를 기반으로만 거짓 신호를 생성할 수 있으며, 최적화 공간은 여전히 넓으며, 더 많은 요소와 파라미터 조정과 결합하여 전략 효과를 개선하기 위해 추가적인 고려가 필요합니다.
/*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")