동적 손절매 추적 전략


생성 날짜: 2024-01-03 16:15:29 마지막으로 수정됨: 2024-01-03 16:15:29
복사: 0 클릭수: 596
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

동적 손절매 추적 전략

개요

이 전략은 스토흐 지표를 사용하여 입시 신호를 판단하고, 입시 후 실시간으로 가격의 새로운 높은 또는 새로운 낮은 것을 추적하여 중지 지점을 동적으로 조정한다. 또한, 전략은 알 기능을 통해 중지 변경 정보를 MT4/MT5에 전송하여 실제 거래의 위치를 실시간으로 조정한다.

전략 원칙

  1. 이 전략은 스토흐 지표에 기초하여 구매 및 판매 신호를 생성하며, 스토흐의 K 라인이 아래쪽에서 D 라인을 돌파할 때 구매 신호를 생성하고, 스토흐의 K 라인이 위쪽에서 아래쪽에서 D 라인을 돌파할 때 판매 신호를 생성한다.

  2. 진입 후, 전략은 가장 낮은 가격의 최신 최저점과 가장 높은 가격의 최신 최고점을 실시간으로 추적합니다. 동적인 중단 지점으로. 구체적으로, 더 많은 주문을 할 경우 가장 낮은 가격의 최신 최저점을 중지 지점으로 추적합니다.

  3. 스톱 리스 변화가 감지되면, 전략은 알 기능을 통해 수정 스톱 명령어를 생성하고, MT4/MT5에 실시간으로 실제 거래의 스톱 리스를 조정하기 위해 전송한다. 동시에 스톱 리스 변화를 직관적으로 표시하기 위해 그래픽 표기법을 그리는 것이다.

  4. 이 전략은 동적 스톱 메커니즘이 활성화되었는지 여부를 수동으로 제어하는 것을 지원한다. 활성화되면, 시장의 변동에 따라 실시간으로 스톱 트래킹 가격을 조정할 수 있다.

우위 분석

  1. 다이내믹 트래킹 스톱 메커니즘을 적용하여 시장의 변동에 따라 스톱 지점을 유연하게 조정하여 스톱 트래킹을 구현하고 위험을 효과적으로 제어 할 수 있습니다.

  2. 알레르트 기능을 사용하여 정지 조정 정보를 실시간으로 MT4/MT5에 전송할 수 있으며, 인적 개입 없이 자동 관리가 가능합니다.

  3. 지각적으로 그래픽 상에 표시된 스톱 로즈 조정 정보는 스톱 로즈 추적 효과를 확인하고 검증하는 데 도움이됩니다.

  4. 수동으로 제어할 수 있도록 지원하고, 다양한 시장 조건에 따라 유연하게 조정할 수 있습니다.

  5. 스토흐 지표와 함께 시기를 판단하면 가짜 돌파구를 효과적으로 필터링하여 전략의 안정성을 높일 수 있다.

위험 분석

  1. 스토치 지표는 자주 교차 신호가 발생할 수 있으며, 더 많은 무효 동작의 위험을 초래할 수 있다. 신호를 필터링하기 위해 파라미터를 적절히 조정할 수 있다.

  2. 극단적인 상황에서는, 정지 손실이 뚫릴 수 있으며, 거대한 손실을 완전히 피할 수 없습니다. 적절한 시기에 포지션 위험을 모니터링하십시오.

  3. alert 연결이 중단되거나 지연되는 등의 문제가 발생할 수 있으며, 실시간 피드백으로 결과를 조정할 수 없으며, 오류 관리가 필요합니다.

  4. 동적 추적 중지 손실은 비교적 밀도 높은 조정이 필요하며, 더 많은 거래 비용을 초래할 수 있다. 조정이 대폭과 비용을 균형을 잡아야 한다.

최적화 방향

  1. 다양한 변수 조합을 테스트하여 Stoch 지표를 최적화하여 더 나은 신호 품질과 전략 효과를 얻을 수 있습니다.

  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)