
이 전략은 지점 ((PivotHigh와 PivotLow) 을 사용하여 가격의 변동적 고점과 낮은 점을 식별하고, 이를 기반으로 상향과 하향의 트렌드 라인을 그리는 것이다. 트렌드 라인의 기울기는 ATR ((Average True Range)), 표준차 또는 선형 회귀와 같은 방법으로 계산되고, 기울기 인자에 의해 조정된다. 가격이 트렌드 라인을 뚫을 때 이 전략은 구매 또는 판매 신호를 발생시킨다.
이 전략은 지점과 트렌드 라인 슬라이드를 활용하여 실시간 트렌드 라인 거래 시스템을 구축한다. 트렌드 라인 돌파 사건을 포착함으로써 전략은 트렌드 형성 초기 단계에서 거래 할 수 있다. 이 전략은 장점이 있기는 하지만, 흔들리는 시장에서의 위험을 주의해야 하며, 더 많은 정보를 도입하고, 신호 필터링과 포지션 관리 등을 최적화함으로써 전략의 안정성과 수익성을 더욱 향상시킬 필요가 있다.
/*backtest
start: 2023-04-20 00:00:00
end: 2024-04-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(" only Ajay ", overlay=true)
//------------------------------------------------------------------------------
//Settings
//------------------------------------------------------------------------------{
length = input.int(14, 'Swing Detection Lookback')
mult = input.float(1., 'Slope', minval = 0, step = .1)
calcMethod = input.string('Atr', 'Slope Calculation Method', options = ['Atr','Stdev','Linreg'])
backpaint = input(true, tooltip = 'Backpainting offset displayed elements in the past. Disable backpainting to see real time information returned by the indicator.')
//Style
upCss = input.color(color.teal, 'Up Trendline Color', group = 'Style')
dnCss = input.color(color.red, 'Down Trendline Color', group = 'Style')
showExt = input(true, 'Show Extended Lines')
//------------------------------------------------------------------------------}
//Calculations
//------------------------------------------------------------------------------{
var upper = 0.
var lower = 0.
var slope_ph = 0.
var slope_pl = 0.
var offset = backpaint ? length : 0
n = bar_index
src = close
ph = ta.pivothigh(length, length)
pl = ta.pivotlow(length, length)
//Slope Calculation Method
slope = switch calcMethod
'Atr' => ta.atr(length) / length * mult
'Stdev' => ta.stdev(src,length) / length * mult
'Linreg' => math.abs(ta.sma(src * n, length) - ta.sma(src, length) * ta.sma(n, length)) / ta.variance(n, length) / 2 * mult
//Get slopes and calculate trendlines
slope_ph := ph ? slope : slope_ph
slope_pl := pl ? slope : slope_pl
upper := ph ? ph : upper - slope_ph
lower := pl ? pl : lower + slope_pl
var upos = 0
var dnos = 0
upos := ph ? 0 : close > upper - slope_ph * length ? 1 : upos
dnos := pl ? 0 : close < lower + slope_pl * length ? 1 : dnos
//------------------------------------------------------------------------------}
//Extended Lines
//------------------------------------------------------------------------------{
// var uptl = line.new(na,na,na,na, color = upCss, style = line.style_dashed, extend = extend.right)
// var dntl = line.new(na,na,na,na, color = dnCss, style = line.style_dashed, extend = extend.right)
// if ph and showExt
// uptl.set_xy1(n-offset, backpaint ? ph : upper - slope_ph * length)
// uptl.set_xy2(n-offset+1, backpaint ? ph - slope : upper - slope_ph * (length+1))
// if pl and showExt
// dntl.set_xy1(n-offset, backpaint ? pl : lower + slope_pl * length)
// dntl.set_xy2(n-offset+1, backpaint ? pl + slope : lower + slope_pl * (length+1))
//------------------------------------------------------------------------------}
//Plots
//------------------------------------------------------------------------------{
plot(backpaint ? upper : upper - slope_ph * length, 'Upper', color = ph ? na : upCss, offset = -offset)
plot(backpaint ? lower : lower + slope_pl * length, 'Lower', color = pl ? na : dnCss, offset = -offset)
//Breakouts
upBreakout = upos > upos[1]
dnBreakout = dnos > dnos[1]
if (upBreakout)
strategy.entry("Up Breakout", strategy.long)
if (dnBreakout)
strategy.entry("Down Breakout", strategy.short)
//------------------------------------------------------------------------------}
//Alerts
//------------------------------------------------------------------------------{
alertcondition(upos > upos[1], 'Upward Breakout', 'Price broke the down-trendline upward')
alertcondition(dnos > dnos[1], 'Downward Breakout', 'Price broke the up-trendline downward')
//------------------------------------------------------------------------------}