
이것은 슈퍼 트렌드 지표와 ATR 지표에 기반한 전략이다. 이 전략의 주요 아이디어는: 슈퍼 트렌드 지표를 사용하여 현재 시장의 트렌드 방향을 판단하고, 슈퍼 트렌드 지표가 변할 때 거래를 한다. 동시에, 이 전략은 ATR 지표를 사용하여 중지 손실과 중지 가격을 계산하고, 계정 잔액의 일정한 비율에 따라 위치 크기를 계산하여 위험을 제어한다.
이 전략의 원리는 다음과 같습니다.
이 전략의 장점은 다음과 같습니다.
이 전략의 위험은 다음과 같습니다.
위와 같은 위험에 대해 다음과 같은 조치를 취할 수 있습니다.
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
이러한 최적화는 전략의 수익성과 안정성을 높이고, 동시에 전략의 위험을 낮추고, 전략을 다양한 시장 환경에 더 잘 적응시킬 수 있다.
이 전략은 슈퍼 트렌드 지표와 ATR 지표를 결합하여 트렌드를 효과적으로 포착하고 동시에 위험을 제어할 수 있습니다. 최적의 위치 크기를 계산하여 각 거래의 위험을 제어 할 수 있습니다. 그러나 이 전략은 불안한 시장에서 높은 거래 비용과 회수 효과를 가져올 수 있습니다. 더 많은 기술 지표, 최적화 매개 변수, 위험 제어 요소 및 스톱 전략을 추가하여 전략의 성능을 더욱 향상시킬 수 있습니다.
/*backtest
start: 2024-02-01 00:00:00
end: 2024-02-29 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradez99
//@version=5
strategy('Supertrend', overlay=true, format=format.price, precision=2)
Periods = input(title='ATR Period', defval=10)
src = input(hl2, title='Source')
Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=3.0)
changeATR = input(title='Change ATR Calculation Method ?', defval=true)
showsignals = input(title='Show Buy/Sell Signals ?', defval=true)
highlighting = input(title='Highlighter On/Off ?', defval=true)
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
up = src - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title='Up Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.green, 0))
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title='UpTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))
plotshape(buySignal and showsignals ? up : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0))
dnPlot = plot(trend == 1 ? na : dn, title='Down Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.red, 0))
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title='DownTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))
plotshape(sellSignal and showsignals ? dn : na, title='Sell', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))
mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? trend == 1 ? color.green : color.white : color.white
shortFillColor = highlighting ? trend == -1 ? color.red : color.white : color.white
//fill(mPlot, upPlot, title='UpTrend Highligter', color=longFillColor)
//fill(mPlot, dnPlot, title='DownTrend Highligter', color=shortFillColor)
multiplier = input.float(title="ATR multiplier", defval = 1.5)
rr = input.float(title="Risk:Reward", defval=1.0)
riskPerTrade = input.float(title="Risk Per Trade %", defval=1.0)
atr3 = ta.atr(14)
//calculate stops and targets
longstop = close - (atr3 * multiplier)
shortstop = close + (atr3 * multiplier)
longStopDistance = close - longstop
shortStopDistance = shortstop - close
longTarget = close + (longStopDistance * rr)
shortTarget = close - (shortStopDistance * rr)
// Save stops & targets
var t_stop = 0.0
var t_target = 0.0
longCondition = buySignal
if (longCondition)
t_stop := longstop
t_target := longTarget
positionSize = math.floor((strategy.equity * (riskPerTrade/100)) / (close - t_stop))
strategy.entry("Long", strategy.long, qty = positionSize)
shortCondition = sellSignal
if (shortCondition)
t_stop := shortstop
t_target := shortTarget
positionSize = math.floor((strategy.equity * (riskPerTrade/100)) / (t_stop - close))
strategy.entry("Short", strategy.short, qty = positionSize)
strategy.exit(id="Long Exit", from_entry="Long", limit=t_target, stop=t_stop)
strategy.exit(id="Short Exit", from_entry="Short", limit=t_target, stop=t_stop)