
이 전략은 평균 실제 파장 (ATR) 과 가격 돌파구를 기반으로 한 ETF 자동 거래 전략이다. ATR을 사용하여 스톱로스 및 스톱오피스를 계산하고, 가격이 일정한 주기 최고 가격 또는 최저 가격을 돌파할 때 포지션을 상장하거나 상쇄한다.
이 전략은 다음과 같은 원칙에 기초하고 있습니다.
특정 주기 (예: 20 K선) 의 최고 가격과 최저 가격을 사용하여 가격의 움직임과 방향을 판단하십시오. 가격이 주기 최고 가격을 돌파 할 때, 더 많이하십시오. 가격이 주기 최저 가격을 돌파 할 때, 공백하십시오.
ATR을 사용하여 동적으로 스톱로스를 계산한다. 스톱로스가 입시 가격에서 1 ATR 주기의 ATR 값을 계수 ((예: 2)) 로 곱한다.
ATR을 사용하여 정지를 계산한다. 정지 거리는 입시 가격으로 한 ATR 주기의 ATR 값을 계수로 곱한다 (예: 1) [2].
ATRtrailer 다중 인자를 사용하여 스톱을 추적하십시오. 가격이 불리한 방향으로 트레일러 스톱을 돌파 할 때, 평점 스톱.
이 전략은 간단하고 신뢰할 수 있으며, 가격 추세의 방향을 고려하여 가격 추세를 적시에 잡는 데 도움이되며, 수익 기회를 잡고 위험을 제어하는 데 도움이되는 중지 및 중지 위치를 설정합니다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
전략은 간단하고 명확하며 이해하기 쉽고 실행이 가능합니다.
ATR을 사용하여 스톱 스톱 손실을 계산하여 포지션 규모를 동적으로 조정하고 위험을 유연하게 제어 할 수 있습니다.
주기를 깨는 판단 전략은 가격 추세를 쉽게 포착하고 수익이 더 좋다.
트레일러의 손해는 적시에 막을 수 있고, 너무 큰 위험을 감수하지 않을 수 있다.
트렌드가 뚜렷한 품종, 예를 들어 ETF, 주식 등에 적용됩니다.
이 전략에는 다음과 같은 위험도 있습니다.
가격 변동이 있을 때, 잘못된 신호와 반전 거래가 발생할 수 있다.
사이클 파라미터를 잘못 설정하면 가격 트렌드를 놓치거나 너무 많은 환상 거래가 발생할 수 있습니다.
인수 변수 설정이 잘못되어 손실이나 정지기가 너무 급진적이거나 보수적이어서 수익에 영향을 미칠 수 있습니다.
ETF 자체의 위험, 정책 위험, 프리미엄 위험 등도 전략에 영향을 미칩니다.
대응방법:
이 전략은 다음의 몇 가지 측면에서 더 개선될 수 있습니다.
이동평균 등과 결합된 지표로 가짜 신호를 필터링한다.
적응성 매개 변수 최적화 모듈을 추가하여 다른 주기 및 품종에 따라 매개 변수를 자동으로 최적화한다.
다음 K 선의 높고 낮은 점을 예측하는 기계 학습 모델을 추가하여 돌파 신호를 판단합니다.
거래량 오버플레잉과 같은 지표들을 고려하고, 가짜 브레이크를 방지한다.
포지션 크기와 비율을 최적화하고, 다양한 품종과 시장 환경에 적응하여 포지션을 열 수 있습니다.
이 전략의 전체적인 아이디어는 명확하고 간결하며, 핵심 메커니즘의 돌파구와 ATR의 동적 중지 중지 손실은 위험을 효과적으로 제어하고 수익을 잠금 할 수 있습니다. 파라미터를 최적화하고 더 많은 필터링 지표와 결합하여 전략의 수익 요소와 위험 제어 능력을 더욱 강화 할 수 있습니다.
/*backtest
start: 2023-12-18 00:00:00
end: 2023-12-21 03:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FX_minds
//@version=4
strategy("ETF tradedr", overlay=true, pyramiding=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
//------------------------------ get user input
lookback = input(title="HH LL lookback", type=input.integer, defval=20)
ATR_periode = input(title="ATR period", type=input.integer, defval=14)
ATR_SL_multiplier = input(title="ATR SL multiplier", type=input.float, defval=2)
ATR_TP_multiplier = input(title="ATR TP multiplier", type=input.float, defval=1)
trailing_SL_ATR_multiplier = input(title="ATR trailing SL multiplier", type=input.float, defval=3.5)
lookback_trailing_SL = input(title="trailing SL lookback", type=input.integer, defval=4)
max_sequel_trades = input(title="max sequel trades", type=input.float, defval=1)
trade_long = input(title= "trade long ?", type=input.bool, defval=true)
trade_short = input(title= "trade short ?", type=input.bool, defval=false)
//------------------------------ determine entry conditions
long_condition = barstate.isconfirmed and crossover(high, highest(high, lookback)[1])
short_condition = barstate.isconfirmed and crossunder(low, lowest(low, lookback)[1])
//------------------------------ count open long trades
count_open_longs = 0
count_open_longs := nz(count_open_longs[1])
if (long_condition)
count_open_longs := count_open_longs +1
//label.new(bar_index, low, tostring(count_open_longs, "#"), xloc.bar_index, yloc.belowbar, color.green, label.style_none, color.green, size.large)
if (short_condition)
count_open_longs := 0
//------------------------------ count open short trades
count_open_shorts = 0
count_open_shorts := nz(count_open_shorts[1])
if (short_condition)
count_open_shorts := count_open_shorts +1
//label.new(bar_index, low, tostring(count_open_shorts, "#"), xloc.bar_index, yloc.belowbar, color.red, label.style_none, color.red, size.large)
if (long_condition)
count_open_shorts := 0
//------------------------------ calculate entryprice
entryprice_long = long_condition ? close : na
entryprice_short = short_condition ? close : na
//------------------------------ calculate SL & TP
SL_distance = atr(ATR_periode) * ATR_SL_multiplier
TP_distance = atr(ATR_periode) * ATR_TP_multiplier
trailing_SL_distance = atr(ATR_periode) * trailing_SL_ATR_multiplier
SL_long = entryprice_long - SL_distance
SL_short = entryprice_short + SL_distance
trailing_SL_short = lowest(close, lookback_trailing_SL) + trailing_SL_distance
trailing_SL_long = highest(close, lookback_trailing_SL) - trailing_SL_distance
trailing_SL_short_signal = crossover(high, trailing_SL_short[1])
trailing_SL_long_signal = crossunder(low, trailing_SL_long[1])
//------------------------------ plot entry price & SL
plot(entryprice_long, style=plot.style_linebr, color=color.white)
plot(SL_long, style=plot.style_linebr, color=color.red)
plot(SL_short, style=plot.style_linebr, color=color.green)
plot(trailing_SL_short, style=plot.style_linebr, color=color.red)
plot(trailing_SL_long, style=plot.style_linebr, color=color.green)
//------------------------------ submit entry orders
if (long_condition) and (count_open_longs <= max_sequel_trades) and (trade_long == true)
strategy.entry("Long" + tostring(count_open_longs, "#"), strategy.long)
strategy.exit("SL Long"+ tostring(count_open_longs, "#"),
from_entry="Long" + tostring(count_open_longs, "#"), stop=SL_long)
if (short_condition) and (count_open_shorts <= max_sequel_trades) and (trade_short == true)
strategy.entry("Short" + tostring(count_open_shorts, "#"), strategy.short)
strategy.exit("SL Short" + tostring(count_open_shorts, "#"),
from_entry="Short" + tostring(count_open_shorts, "#"), stop=SL_short)
//------------------------------ submit exit conditions
if (trailing_SL_long_signal)
strategy.close("Long" + tostring(count_open_longs, "#"))
strategy.close("Long" + tostring(count_open_longs-1, "#"))
strategy.close("Long" + tostring(count_open_longs-2, "#"))
strategy.close("Long" + tostring(count_open_longs-4, "#"))
strategy.close("Long" + tostring(count_open_longs-5, "#"))
strategy.close("Long" + tostring(count_open_longs-6, "#"))
strategy.close("Long" + tostring(count_open_longs-7, "#"))
strategy.close("Long" + tostring(count_open_longs-8, "#"))
strategy.close("Long" + tostring(count_open_longs-9, "#"))
if (trailing_SL_short_signal)
strategy.close("Short" + tostring(count_open_shorts, "#"))
strategy.close("Short" + tostring(count_open_shorts-1, "#"))
strategy.close("Short" + tostring(count_open_shorts-2, "#"))
strategy.close("Short" + tostring(count_open_shorts-3, "#"))
strategy.close("Short" + tostring(count_open_shorts-4, "#"))
strategy.close("Short" + tostring(count_open_shorts-5, "#"))
strategy.close("Short" + tostring(count_open_shorts-6, "#"))
strategy.close("Short" + tostring(count_open_shorts-7, "#"))
strategy.close("Short" + tostring(count_open_shorts-8, "#"))
strategy.close("Short" + tostring(count_open_shorts-9, "#"))