이동 중지 손실 추적 전략

저자:차오장, 날짜: 2024-01-03 16:15:29
태그:

img

전반적인 설명

이 전략은 엔트리 신호를 생성하기 위해 스톡 지표를 사용합니다. 포지션을 입력 한 후, 정지 손실을 동적으로 조정하기 위해 실시간으로 새로운 최고 또는 최저치를 추적합니다. 동시에 전략은 실제 거래에서 포지션을 조정하기 위해 알림 기능을 통해 MT4/MT5에 정지 손실 수정 정보를 전송합니다.

전략 원칙

  1. 이 전략은 스톡 지표를 기반으로 구매 및 판매 신호를 생성합니다. 스톡 K 라인이 아래에서 D 라인의 위를 넘을 때 구매 신호가 생성됩니다. K 라인이 위에서 D 라인의 아래를 넘을 때 판매 신호가 생성됩니다.

  2. 포지션을 입력한 후, 전략은 역동적 스톱 로스 레벨로 가장 낮은 가격의 최신 최저와 가장 높은 가격의 최신 최고를 실시간으로 추적합니다. 구체적으로, 긴 포지션에서는 가장 낮은 가격의 가장 최근의 최저점이 스톱 로스 레벨로 추적됩니다. 짧은 포지션에서는 가장 높은 가격의 가장 최근의 높은점이 스톱 로스 레벨로 추적됩니다.

  3. 스톱 로스 레벨의 변화가 감지되면 전략은 알림 기능을 통해 스톱 로스 오더 수정 명령을 생성하고 실제 거래의 스톱 로스 수준을 실시간으로 조정하기 위해 MT4/MT5로 전송합니다. 또한 스톱 로스 변경 사항을 직관적으로 표시하기 위해 그래픽 해설이 그려집니다.

  4. 이 전략은 동적 스톱 손실 메커니즘을 활성화 여부를 수동으로 제어하는 것을 지원합니다. 활성화되면 시장 변동에 따라 실시간으로 스톱 손실을 조정할 수 있습니다.

이점 분석

  1. 역동적인 트레일링 스톱 로스 메커니즘은 시장 변동에 따라 스톱 로스 수준을 유연하게 조정하여 위험을 효과적으로 제어 할 수 있습니다.

  2. 알림 기능은 자동 관리를 위해 MT4/MT5에 실시간으로 스톱 로스 조정 정보를 전송할 수 있습니다.

  3. 차트에 있는 스톱 로스 조정의 시각적 설명은 후속 스톱 로스 효과를 보거나 확인하는 것을 용이하게 합니다.

  4. 스톱 로스 트레일 메커니즘을 수동으로 제어할 수 있는 지원은 다양한 시장 조건에 유연하게 적응할 수 있습니다.

  5. 기회를 결정하기 위해 스톡 지표와 결합하면 전략은 가짜 브레이크를 효과적으로 필터링하고 안정성을 향상시킬 수 있습니다.

위험 분석

  1. 스톡 지표는 빈번한 크로스오버 신호를 생성하여 더 비효율적인 작업의 위험을 도입 할 수 있습니다. 매개 변수는 필터 신호에 조정 할 수 있습니다.

  2. 극심한 시장 조건에서, 엄청난 손실을 완전히 피할 수 없는 스톱 손실이 침투될 수 있습니다. 포지션 리스크는 적시에 모니터링되어야 합니다.

  3. 중단 및 지연과 같은 경고 연결 문제가 발생할 수 있으며, 조정의 실시간 피드백을 방지합니다. 적절한 오류 관용 조치가 필요합니다.

  4. 동적 트레일링 스톱 로스는 비교적 빈번한 조정이 필요하며, 잠재적으로 더 높은 거래 비용을 발생시킬 수 있습니다. 조정 범위는 비용과 균형을 잡아야합니다.

최적화 방향

  1. 다른 매개 변수 조합을 테스트하여 더 나은 신호 품질과 전략 성능을 위해 스토크 지표를 최적화 할 수 있습니다.

  2. 다른 지표들은 신호를 필터링하거나 전략의 안정성을 향상시키기 위해 조정 범위를 결정하기 위해 결합될 수 있습니다.

  3. 다른 추적 알고리즘을 연구하여 정비 빈도를 줄이는 동시에 스톱 손실 효과를 보장 할 수 있습니다.

  4. MT4 / MT5에 연결하는 방법은 신속하고 효율적인 알림을 보장하고 지연을 최소화하기 위해 향상 될 수 있습니다.

  5. 자동 및 수동 중지 손실 모드는 다른 시장 조건에서 다른 메커니즘을 사용하기 위해 도입 할 수 있습니다.

요약

이 전략은 먼저 스톡 지표를 기반으로 거래 기회를 결정하고, 그 다음 지점 동안 가격 변동을 추적하여 동적으로 스톱 손실을 조정하고 알림 명령을 통해 자동으로 조정 정보를 발행합니다. 이러한 동적 메커니즘은 수동 개입이 적은 시장 변화에 따라 적극적인 위치 리스크 관리를 가능하게합니다. 한편, 직관적인 스톱 손실 주석 또한 모니터링을 촉진합니다. 신호 필터링 및 트레일링 알고리즘에 대한 추가 최적화는 수익성을 향상시킬 수 있습니다. 전반적으로, 동적 트레일링 스톱 손실 전략은 변동성 시장 및 자동화 된 위치 리스크 관리를 추적하는 데 적합합니다.


/*backtest
start: 2022-12-27 00:00:00
end: 2024-01-02 00:00:00
period: 1d
basePeriod: 1h
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/
// © Peter_O

//@version=4
strategy(title="Moving Stop-Loss mechanism", overlay=true)

// This script was created for educational purposes only and it is a spin-off of my previous script:
// https://www.tradingview.com/script/9MJO3AgE-TradingView-Alerts-to-MT4-MT5-dynamic-variables-NON-REPAINTING/
// This spin-off adds very often requested Moving Stop-Loss Mechanism - the logic here moves the stop-loss each time 
// a new pivot is detected.
//
// Last lines of the script include alert() function calls, with a syntax compatible with TradingConnector
// for execution in Forex/indices/commodities/crypto markets via MetaTrader.
// Please note that "tradeid=" variable must be passed with each alert, so that MetaTrader knows which
// trade to modify.

TakeProfitLevel=input(400)

// **** Entries logic, based on Stoch **** {
periodK = 13 //input(13, title="K", minval=1)
periodD = 3 //input(3, title="D", minval=1)
smoothK = 4 //input(4, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)

GoLong=crossover(k,d) and k<80
GoShort=crossunder(k,d) and k>20
// } End of entries logic

// **** Pivot-points and stop-loss logic **** {
piv_high = pivothigh(high,1,1)
piv_low = pivotlow(low,1,1)
var float stoploss_long=low
var float stoploss_short=high

pl=valuewhen(piv_low,piv_low,0)
ph=valuewhen(piv_high,piv_high,0)

if GoLong 
    stoploss_long := low<pl ? low : pl
if GoShort 
    stoploss_short := high>ph ? high : ph

plot(stoploss_long, color=color.red, title="stoploss_long")
plot(stoploss_short, color=color.lime, title="stoploss_short")

// Stop-Loss Updating mechanism
enable_stoploss_mechanism=input(true, title="Enable Stoploss Modification Mechanism")
UpdateLongStopLoss = strategy.position_size>0 and strategy.position_size[1]>0 and piv_low and pl!=stoploss_long and not GoLong and enable_stoploss_mechanism
UpdateShortStopLoss = strategy.position_size<0 and strategy.position_size[1]<0 and piv_high and ph!=stoploss_short and not GoShort and enable_stoploss_mechanism
if UpdateLongStopLoss
    stoploss_long := pl
if UpdateShortStopLoss
    stoploss_short := ph

plotshape(UpdateLongStopLoss ? stoploss_long[1]-300*syminfo.mintick : na, location=location.absolute, style=shape.labelup, color=color.lime, textcolor=color.white, text="SL\nmove")
plotshape(UpdateShortStopLoss ? stoploss_short[1]+300*syminfo.mintick : na, location=location.absolute, style=shape.labeldown, color=color.red, textcolor=color.black, text="SL\nmove")
// } End of Pivot-points and stop-loss logic

// **** Trade counter **** {
var int trade_id=0
if GoLong or GoShort
    trade_id:=trade_id+1
// } End of Trade counter

strategy.entry("Long", strategy.long, when=GoLong)
strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)
strategy.entry("Short", strategy.short, when=GoShort)
strategy.exit("XShort", from_entry="Short", stop=stoploss_short, profit=TakeProfitLevel)

if GoLong
    alertsyntax_golong='long slprice=' + tostring(stoploss_long) + ' tradeid=' + tostring(trade_id) + ' tp=' + tostring(TakeProfitLevel)
    alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)
if GoShort
    alertsyntax_goshort='short slprice=' + tostring(stoploss_short) + ' tradeid=' + tostring(trade_id) + ' tp=' + tostring(TakeProfitLevel)
    alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)
if UpdateLongStopLoss
    alertsyntax_updatelongstoploss='slmod slprice=' + tostring(stoploss_long) + ' tradeid=' + tostring(trade_id)
    alert(message=alertsyntax_updatelongstoploss, freq=alert.freq_once_per_bar_close)
if UpdateShortStopLoss
    alertsyntax_updateshortstoploss='slmod slprice=' + tostring(stoploss_short) + ' tradeid=' + tostring(trade_id)
    alert(message=alertsyntax_updateshortstoploss, freq=alert.freq_once_per_bar_close)


더 많은