동적 손절매 트레이딩 뷰 전략


생성 날짜: 2023-09-18 17:20:06 마지막으로 수정됨: 2023-09-18 17:20:06
복사: 0 클릭수: 901
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 TradingView의 동적 변수를 사용하여 경보에서 중지 가격을 전달하고 TradingConnector를 통해 MT4/5 플랫폼에서 거래를 수행하는 방법을 보여줍니다. 이 전략은 Stochastic 지표를 사용하여 입시 시기를 판단하고, 동적으로 최신 지원 저항을 중단 지점으로 설정하고, 부분적으로 중단 할 수 있습니다.

전략 원칙

스토카스틱 지표의 K선과 D선 금포는 더하고, 사포는 빈이다. 가장 가까운 지지 저항 지점을 중지 가격으로 계산한다. 입문 후, 중지 가격은 동적 변수를 통해 실시간으로 브로커에게 전달된다. 일부 중지 설정은 중지 거리의 일정한 비율이다.

우위 분석

  • 동적 스톱 로즈는 스톱 로즈 가격을 정밀하게 설정할 수 있습니다.
  • 부분적으로 자금 사용 효율을 높여
  • 실시간으로 브로커 계정으로 스톱로스 전송
  • 리얼 디스크에 가까운 스톱 손실 가격을 감지하고, 모의 현실 시뮬레이션

위험 분석

  • 스토카스틱 지표의 지연
  • 일부 지연이 포지션 유지에 너무 자주 영향을 미칩니다.
  • 동적 변수는 다른 시간 프레임에 따라 다른 효과를 나타냅니다.
  • 부분적으로 차단되는 비율을 최적화해야 합니다.

스토카스틱의 파라미터 사이클을 적절히 단축하고, 부분 정지 비율을 조정하여 위험을 제어할 수 있다.

최적화 방향

  • 다른 Stochastic 변수 조합을 테스트합니다.
  • 부분 정지 비율을 최적화
  • 이동식 상쇄와 같은 다른 상쇄 방법을 시도하십시오.
  • 다 시장 다 품종 테스트

요약하다

이 전략은 TradingView의 새로운 기능을 사용하여 MT4/5에서 동적 중지 손실 거래를 수행하는 방법을 보여줍니다. 추가 백테스팅의 기본 프레임 워크로 사용할 수 있습니다. 특정 품종에 대한 최적화 조정이 여전히 필요합니다.

전략 소스 코드
/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// strategy(title="TradingView Alerts to MT4 MT5 Strategy example", commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=false, default_qty_value=100000, initial_capital=1000)
// study(title="TradingView Alerts to MT4 MT5 Strategy example")  //uncomment this line and comment previous one to make it a study producing alerts
//
// This script was created for educational purposes only.
// It is showing how to use dynamic variables in TradingView alerts.
// And how to execute them in Forex, indices and commodities markets
// thanks to www.tradingconnector.com

TakeProfitLevel=input(400)
TakePartialProfitLevel=input(150)

// **** Entries logic **** {
periodK = input(14, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = 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
// } End of Pivot-points and stop-loss logic

// **** Trade counter and partial closing mechanism **** {
var int trade_id=0
if GoLong or GoShort
    trade_id:=trade_id[1]+1

TakePartialProfitLong = barssince(GoLong)<barssince(GoShort) and crossover(high,(valuewhen(GoLong,close,0)+TakePartialProfitLevel*syminfo.mintick))
TakePartialProfitShort = barssince(GoLong)>barssince(GoShort) and crossunder(low,(valuewhen(GoShort,close,0)-TakePartialProfitLevel*syminfo.mintick))
// } End of Trade counter and partial closing mechanism


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


// alertcondition("Long", when=GoLong, message="long slprice={{stoploss_long}} tradeid={{trade_id}} tp=TakeProfitLevel")
// alertcondition("Short", when=GoShort, message="short slprice={{stoploss_short}} tradeid={{trade_id}} tp=TakeProfitLevel")
// alertcondition("ClosePartLong", when=TakePartialProfitLong, message="closepart tradeit={{trade_id}} part=0.5")
// alertcondition("ClosePartShort", when=TakePartialProfitShort, message="closepart tradeit={{trade_id}} part=0.5")