동적 스톱 로스 경고 거래 보기 전략

저자:차오장, 날짜: 2023-09-18 17:20:06
태그:

전반적인 설명

이 전략은 TradingConnector를 사용하여 MT4/5 플랫폼에서 실행을 위해 TradingView 알림을 통해 동적 스톱 로스 가격을 전달하는 것을 보여줍니다. 엔트리는 최근 피보트에 설정된 동적 스톱으로 스토카스틱 지표를 사용하여 결정됩니다. 부분 수익도 가능합니다.

전략 논리

스토카스틱 K 및 D 라인 크로스 상의 긴 및 짧은 엔트리. 최근 피보트 최고/하위는 동적 스톱 로스 가격으로 계산됩니다. 이들은 엔트리에 대한 알림을 통해 브로커에게 실시간으로 전달됩니다. 부분 이익은 정지 손실 거리의 특정 비율로 취합니다. 이익 가격은 또한 동적으로 알릴 수 있습니다.

장점

  • 동적 중지 수술적 중지 손실 배치를 허용
  • 부분적 이익 취득은 자본 효율을 향상시킵니다.
  • 스톱 로스 가격을 브로커 계정으로 실시간으로 전달
  • 백테스트 된 스톱 로스 모방 라이브, 현실적인 시뮬레이션

위험성

  • 스토카스틱 지표에 지연이 있습니다.
  • 빈번한 부분 이익 취득이 지분을 방해합니다
  • 동적 변수는 시간 프레임에 따라 다르게 행동합니다.
  • 부분 이익 비율 최적화 필요

리스크는 스토카스틱 매개 변수를 조정하고 부분 이익 비율을 조정하여 관리 할 수 있습니다.

개선

  • 다른 스토카스틱 매개 변수 조합을 테스트합니다.
  • 부분 수익률을 최적화
  • 트레일링 스톱과 같은 다른 스톱 손실 접근 방식을 탐구하십시오.
  • 시장과 제품 간의 견고성 테스트

결론

이 전략은 새로운 기능을 사용하여 트레이딩뷰에서 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")


더 많은