이 전략은 중심점 (Pivot Points) 을 기반으로 시장의 역전점을 식별하고, 이를 기반으로 거래한다. 시장이 좌측 4K선 안의 중심점 고점 (Pivot High) 을 나타낼 때, 전략은 더 많은 포지션을 열고, 시장이 좌측 4K선 안의 중심점 저점 (Pivot Low) 을 나타낼 때, 전략은 빈 포지션을 열는다. 전략의 정지는 포지션 가격의 상하의 최소 가격 변동 단위 (syminfo.mintick) 에 설정된다. 전략의 탈퇴 조건은 두 가지이다.
이 전략은 축점 지표를 기반으로 한 양방향 거래 시스템을 구축하여 축점 고점에서 더 많이 하고, 낮은 점에서 공백을 가하여 시장 역전 기회를 포착한다. 전략은 이론적 기초와 실용적인 가치가 있지만, 축점 지표 자체의 한계로 인해 전략은 실제 운영에서 몇 가지 위험과 도전에 직면 할 수 있다. 축점 지표 유형, 매개 변수, 필터링 조건, 스톱 손실 등을 최적화함으로써 전략의 안정성과 수익성을 더욱 향상시킬 수 있다.
/*backtest
start: 2023-04-24 00:00:00
end: 2024-04-29 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Pivot Reversal Strategy with Pivot Exit", overlay=true)
leftBars = input(4)
rightBars = input(2)
var float dailyEquity = na
// Reset equity to $10,000 at the beginning of each day
isNewDay = ta.change(time("D")) != 0
if (isNewDay)
dailyEquity := 10000
// Calculate pivot highs and lows
swh = ta.pivothigh(leftBars, rightBars)
swl = ta.pivotlow(leftBars, rightBars)
// Define long entry condition
swh_cond = not na(swh)
hprice = 0.0
hprice := swh_cond ? swh : hprice[1]
le = false
le := swh_cond ? true : (le[1] and high > hprice ? false : le[1])
// Enter long position if long entry condition is met
if (le)
strategy.entry("PivRevLE", strategy.long, comment="EnterLong", stop=hprice + syminfo.mintick)
// Define short entry condition
swl_cond = not na(swl)
lprice = 0.0
lprice := swl_cond ? swl : lprice[1]
se = false
se := swl_cond ? true : (se[1] and low < lprice ? false : se[1])
// Enter short position if short entry condition is met
if (se)
strategy.entry("PivRevSE", strategy.short, comment="EnterShort", stop=lprice - syminfo.mintick)
// Exit condition: Exit at the next pivot point
exitAtNextPivot() =>
if strategy.opentrades > 0
if strategy.position_size > 0
// Exiting long position at next pivot low
if not na(swl)
strategy.exit("ExitLong", "PivRevLE", stop=swl - syminfo.mintick)
else
// Exiting short position at next pivot high
if not na(swh)
strategy.exit("ExitShort", "PivRevSE", stop=swh + syminfo.mintick)
// Call exitAtNextPivot function
exitAtNextPivot()
// Exit condition: Exit if profit is less than 30%
exitIfProfitLessThanThirtyPercent() =>
if strategy.opentrades > 0
if strategy.position_size > 0
// Calculate profit percentage for long position
profit_percentage_long = (close - strategy.position_avg_price) / strategy.position_avg_price * 100
// Exiting long position if profit is less than 30%
if profit_percentage_long < -30
strategy.close("PivRevLE")
else
// Calculate profit percentage for short position
profit_percentage_short = (strategy.position_avg_price - close) / strategy.position_avg_price * 100
// Exiting short position if profit is less than 30%
if profit_percentage_short < -30
strategy.close("PivRevSE")
// Call exitIfProfitLessThanThirtyPercent function
exitIfProfitLessThanThirtyPercent()