유연한 스톱 로스로 스토카스틱 인디케이터에 기반한 단기 거래 전략

저자:차오장, 날짜: 2023-09-28 10:45:41
태그:

전반적인 설명

이 전략은 스토카스틱 오시일레이터 지표를 사용하여 단기 거래에 대한 과잉 구매 및 과잉 판매 시장 조건을 결정합니다. 스토카스틱 지표에 황금 십자가가있을 때 길어지고, 위험을 통제하면서 수익을 확보하기 위해 이전 피보트 포인트에 기반한 탄력적인 스톱 로스로 죽음의 십자가에 짧습니다.

전략 논리

엔트리 로직

스토카스틱 오시일레이터 지표는 %K 라인과 %D 라인으로 구성됩니다. %K 라인이 %D 라인의 위를 넘을 때 황금 십자 구매 신호가 생성됩니다. %K 라인이 %D 라인의 아래를 넘을 때 죽음의 십자 판매 신호가 유발됩니다. 이 전략은 단순히 엔트리를 결정하기 위해 스토카스틱 지표의 크로스오버를 따릅니다.

특히, 스토카스틱 지표에 황금 십자점이 있을 때, %K 값이 80보다 작다면 (가장 구매되지 않은 경우), 긴 포지션이 취해질 것입니다. 스토카스틱 죽음의 십자점에, %K 값이 20보다 크다면 (가장 판매되지 않은 경우), 짧은 포지션이 시작됩니다.

GoLong=crossover(k,d) and k<80
GoShort=crossunder(k,d) and k>20

손실 논리를 멈추세요

이 전략은 유연한 스톱 로스 접근법을 사용하며, 아래와 같이 이전 피워트 포인트에 기초한 스톱 가격을 설정합니다.

piv_high = pivothigh(high,1,1)
piv_low = pivotlow(low,1,1)

stoploss_long=valuewhen(piv_low,piv_low,0)
stoploss_short=valuewhen(piv_high,piv_high,0) 

피보트는 중요한 지지 및 저항 수준을 나타냅니다. 가격이 피보트 수준을 넘으면 포지션은 닫히고 스톱 로스 가격은 변화하는 피보트 포인트를 따라 러스틱하게 따라갈 것입니다.

또한, 정지 가격은 추가 최적화를 위해 현재 기간의 가장 높은 가격과 가장 낮은 가격을 고려합니다.

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

장점

  1. 스토카스틱을 사용해서 상위와 하위까지 추격하는 것을 피합니다.

  2. 유연한 스톱 손실은 시장 변화에 따라 스톱 가격을 최적화합니다.

  3. 주전점 파업에 기반한 스톱 손실은 더 효과적입니다.

  4. 현재 가장 높은 가격과 가장 낮은 가격을 사용하여 정지 가격 최적화는 정지를 더 정확하게 만듭니다.

위험 과 해결책

  1. 스토카스틱에서 나오는 잘못된 신호의 위험

    • 해결책: 잘못된 신호를 피하기 위해 신호를 다른 표시기로 확인합니다.
  2. 스톱 로즈가 발생하고 손실이 증가하는 위험

    • 해결책: 정차 거리를 줄이거나 Chandelier Exit 같은 방법을 사용하십시오.
  3. 높은 거래 빈도 및 수수료의 위험

    • 해결책: 거래 수를 줄이기 위해 진입 규칙을 완화

최적화 방향

  1. 캔들리어 출구, 후속 정지, 오스실레이션 정지 손실 등과 같은 방법을 사용하여 손실을 중지 최적화

  2. 스토카스틱 잘못된 신호를 피하기 위해 다른 지표와 입력 규칙을 최적화하십시오.

  3. 수익률을 높이기 위해 후속 수익 목표, 변동 수익 목표 등을 사용하여 수익을 최적화하십시오.

  4. 거래당 고정량, 고정 위험 비율 등과 같은 포지션 크기를 거래별 리스크에 추가합니다.

  5. 다른 시장에 기반 K, D 기간, 평형 등과 같은 매개 변수를 최적화

요약

이 전략은 스토카스틱 오버카운트/오버셀드 (Stochastic overbought/oversold) 를 기반으로 입력하고 탄력적인 스톱 로스로 위험을 관리합니다. 이 전략은 추진력을 추격하는 것, 효과적인 스톱을 피하는 장점을 가지고 있지만 일부 잘못된 신호 위험을 가지고 있습니다. 엔트리, 스톱, 출구, 리스크 관리 등에 대한 미래 개선이 가능합니다.


/*backtest
start: 2023-08-28 00:00:00
end: 2023-09-27 00:00:00
period: 2h
basePeriod: 15m
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="TradingView Alerts to MT4 MT5 example with cancelling pending orders", commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=true, default_qty_value=100000, initial_capital=1000)

// This script was created for educational purposes only.
// It is showing how to create pending orders and cancel them
// Together with syntax to send these events through TradingView alerts system
// All the way to brokers for execution

TakeProfitLevel=input(400)

// **** Entries logic **** {
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)
// plot(k, title="%K", color=color.blue)
// plot(d, title="%D", color=color.orange)
// h0 = hline(80)
// h1 = hline(20)
// fill(h0, h1, color=color.purple, transp=75)

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.lime, title="stoploss_long")
plot(stoploss_short, color=color.red, title="stoploss_short")
// } End of Pivot-points and stop-loss logic

CancelLong=crossunder(low,stoploss_long) and strategy.position_size[1]<=0 and strategy.position_size<=0
CancelShort=crossover(high,stoploss_short) and strategy.position_size[1]>=0 and strategy.position_size>=0
entry_distance=input(10, title="Entry distance for stop orders")

plotshape(CancelLong ? stoploss_long[1]-10*syminfo.mintick : na, location=location.absolute, style=shape.labelup, color=color.gray, textcolor=color.white, text="cancel\nlong", size=size.tiny)
plotshape(CancelShort ? stoploss_short[1]+10*syminfo.mintick : na, location=location.absolute, style=shape.labeldown, color=color.gray, textcolor=color.white, text="cancel\nshort", size=size.tiny)

strategy.entry("Long", strategy.long, when=GoLong, stop=close+entry_distance*syminfo.mintick)
strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)
strategy.cancel("Long", when = CancelLong)
strategy.entry("Short", strategy.short, when=GoShort, stop=close-entry_distance*syminfo.mintick)
strategy.exit("XShort", from_entry="Short", stop=stoploss_short, profit=TakeProfitLevel)
strategy.cancel("Short", when = CancelShort)

if GoLong
    alertsyntax_golong='long offset=' + tostring(entry_distance) + ' slprice=' + tostring(stoploss_long) + ' tp=' + tostring(TakeProfitLevel)
    alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)
if GoShort
    alertsyntax_goshort='short offset=' + tostring(-entry_distance) + ' slprice=' + tostring(stoploss_short) + ' tp=' + tostring(TakeProfitLevel)
    alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)
if CancelLong
    alertsyntax_cancellong='cancel long'
    alert(message=alertsyntax_cancellong, freq=alert.freq_once_per_bar_close)
if CancelShort
    alertsyntax_cancelshort='cancel short'
    alert(message=alertsyntax_cancelshort, freq=alert.freq_once_per_bar_close)
    


더 많은