
마지막 K선 전략은 트렌드 추적 전략으로, 마지막 K선의 종결 가격과 개시 가격의 관계를 분석하여 시장 트렌드 방향을 판단하여 거래 신호를 생성한다.
이 전략의 핵심 논리는 다음과 같습니다.
구체적으로, 전략에서 마지막 K 라인의 개시 가격과 종료 가격 데이터를 요청하여 가격 비교 결과에 따라 트렌드 방향을 판단한다. 상승 추세인 경우, K 라인이 종료될 때 시장 가격으로 더 많은 상장을 한다. 하락 추세인 경우, K 라인이 종료될 때 시장 가격으로 더 많은 상장을 한다.
그 다음으로 스톱로스 및 스톱스톱 가격을 설정한다. 다중 거래의 스톱로스 가격은 해당 K 라인의 개시 가격에 1 인수를 곱하며, 스톱스톱 가격은 현재 폐시 가격이다. 공표는 그 반대이다. 가격이 스톱로스 또는 스톱을 유발하면, 해당 포지션은 평점으로 퇴출된다.
트렌드 지표 확인과 최적화된 스톱 스톱 논리, 재검토 주기와 시장 환경을 확장하여 위험을 줄일 수 있다.
마지막 K선 전략은 간단한 트렌드 추적 전략이다. 그것은 마지막 K선으로 트렌드 방향을 빠르게 판단하고 거래한다. 전략 논리는 간단하고, 구현하기 쉽으며, 트렌드 추적의 사고방식에 부합한다. 동시에 위험을 제어하기 위해 스톱과 스톱을 설정한다. 그러나 마지막 K선에만 의존하는 것은 쉽게 뒤집어 놓을 수 있으며, 트렌드 지표와 결합되어야 한다.
/*backtest
start: 2022-12-14 00:00:00
end: 2023-12-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Last Candle Strategy with Date Range", overlay=true)
// Define the start and end dates for the backtest
startDate = timestamp(2015, 01, 01, 00, 00)
endDate = timestamp(2023, 11, 24, 23, 59)
// Check if the current bar is within the specified date range
withinDateRange = time >= startDate and time <= endDate
// If outside the date range, skip the strategy logic
if (not withinDateRange)
strategy.close_all()
// Calculate the opening and closing values for the last candle
lastCandleOpen = request.security(syminfo.tickerid, "D", open[1], lookahead=barmerge.lookahead_on)
lastCandleClose = request.security(syminfo.tickerid, "D", close[1], lookahead=barmerge.lookahead_on)
// Determine the trade direction based on the last candle
tradeDirection = lastCandleOpen < lastCandleClose ? 1 : -1 // 1 for buy, -1 for sell
// Plot the last candle's opening and closing values on the chart
plot(lastCandleOpen, color=color.blue, title="Last Candle Open")
plot(lastCandleClose, color=color.red, title="Last Candle Close")
// Execute strategy orders
if (withinDateRange)
if (tradeDirection == 1)
strategy.entry("Buy", strategy.long)
if (tradeDirection == -1)
strategy.entry("Sell", strategy.short)
// Set stop loss and take profit
stopLoss = 0.01 * lastCandleOpen
takeProfit = close
// Exit strategy
strategy.exit("StopLoss/Profit", from_entry="Buy", loss=stopLoss, profit=takeProfit)
strategy.exit("StopLoss/Profit", from_entry="Sell", loss=stopLoss, profit=takeProfit)