
이 정책은SMA와 ATR을 기반으로 한 추세 추종 전략。
이 전략은 SMA 지표를 사용하여 가격 트렌드 방향을 판단하고 ATR 지표를 사용하여 중지 손실 위치를 설정하여 트렌드를 추적합니다. 가격이 상승 추세를 넘어섰을 때 공백을 만들고, 가격이 하락 추세를 넘어섰을 때 더 많이하고, 추세 거래를 수행합니다.
(1) 마감가격이 상승하고 SMA보다 높을 때 더 많이 한다. (2) 마감가격이 하락하고 SMA보다 낮을 때 적자를 다.
ATR 지표의 수치를 사용하여 설정된 스톱 로즈 배수를 스톱 로즈 위치로 곱한다.
매 K선 닫기 후에 스톱로드를 확인하고 현재 가격에 가까운 스톱로드로 업데이트한다.
가격이 스톱로스 라인을 만지면 적극적으로 스톱로스를 탈퇴한다.
ATR 지표의 동적 스톱로스 설정은 트렌드를 자동으로 추적할 수 있습니다.
엄격한 스톱 로즈 규칙은 단일 거래의 최대 인출을 통제하는 데 도움이 됩니다.
3개의 변수만 있어 편리하게 조정하고 최적화할 수 있습니다.
만약 스톱 로저 배수가 너무 커 설정되면, 스톱 로저 위치가 너무 느슨해져서 회수량이 증가할 수 있다.
가격의 가짜 돌파구가 발생하면, 트렌드 방향이 틀릴 수 있으며, 다른 지표와 함께 필터링 신호를 제공해야 한다.
과잉 의존적인 매개 변수 최적화는 곡선 최적화를 초래할 수 있다. 매개 변수 안정성은 신중하게 평가해야 한다.
다른 종류의 중지 알고리즘을 테스트 할 수 있습니다. 이동 중지, 비율 중지 등.
다른 지표에 필터링 가짜 돌파구를 추가할 수 있다. 예를 들어, 거래량 조건을 증가시키는 등이다.
역사 회귀를 통해 다양한 품종과 주기에 대한 파라미터의 적응성을 평가한다.
이 전략은 전체적인 생각이 명확하고, SMA를 통해 트렌드 방향을 판단하고, ATR을 사용하여 트렌드 추적, 회수 제어 능력이 좋으며, 중장기 트렌드 거래에 적합하다. 그러나 실물에서는 여전히 적절한 매개 변수를 조정하고, 과도한 최적화 위험을 예방할 필요가 있다.
/*backtest
start: 2024-01-16 00:00:00
end: 2024-01-16 17:00:00
period: 1m
basePeriod: 1m
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/
// © omererkan
//@version=5
strategy(title="SMA with ATR", overlay=true)
smaLen = input.int(100, title="SMA Length")
atrLen = input.int(10, title="ATR Length")
stopOffset = input.float(4, title="Stop Offset Multiple", step=0.25)
smaValue = ta.sma(close, smaLen)
stopValue = ta.atr(atrLen) * stopOffset
lowerCloses = close < close[1] and
close[1] < close[2] and
close[2] < close[3]
enterLong = close > smaValue and
lowerCloses
longStop = 0.0
longStop := if enterLong and strategy.position_size < 1
close - stopValue
else
math.max(close - stopValue, longStop[1])
higherCloses = close > close[1] and
close[1] > close[2] and
close[2] > close[3]
enterShort = close < smaValue and
higherCloses
shortStop = 0.0
shortStop := if enterShort and strategy.position_size > -1
close + stopValue
else
math.min(close + stopValue, shortStop[1])
plot(smaValue, color=#4169e1, linewidth=2, title="SMA")
plot(strategy.position_size > 0 ? longStop : na, color=color.lime,
style=plot.style_linebr, title="Long stop", linewidth=2)
plot(strategy.position_size < 0 ? shortStop : na, color=color.red,
style=plot.style_linebr, title="Short stop", linewidth=2)
if enterLong
strategy.entry("EL", strategy.long)
if enterShort
strategy.entry("ES", strategy.short)
if strategy.position_size > 0
strategy.exit("SL Long", from_entry="EL", stop=longStop)
if strategy.position_size < 0
strategy.exit("SL Short", from_entry="ES", stop=shortStop)
if enterLong
strategy.cancel("Exit Short")
if enterShort
strategy.cancel("Exit Long")