STOCH 거래 전략에 기반한 자동 거래


생성 날짜: 2023-09-28 11:38:44 마지막으로 수정됨: 2023-09-28 11:38:44
복사: 0 클릭수: 702
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

이 전략은 STOCH 지표에 기반한 간단한 자동 거래 시스템을 설계했다. 이 전략은 외환, 주식 지수, 상품 등의 시장에 적합하며, 주식 및 암호화폐 시장으로 확장할 수 있다.

전략 개요

이 전략은 STOCH 지표를 사용하여 과매매 상태를 식별하고, PIVOT 점과 결합하여 손실 위치를 설정하여 트렌드 추적을 구현합니다. STOCH 지표가 과매매를 표시하면 더 많은 코카이드를 수행합니다.

전략 원칙

이 전략은 STOCH 지표의 빠른 라인 %K와 느린 라인 %D를 사용하여 금포가 더 많이 하고 사다리가 더 텅 비도록 한다. 구체적인 논리는,%K 라인이 아래에서 위로 %D 라인을 돌파할 때, 더 많은 작업을 수행한다. %K 라인이 위에서 아래로 %D 라인을 돌파할 때, 공백 작업을 수행한다. 이렇게 오버 바이 오버 셀 상태를 포착한다.

위험을 제어하기 위해, 장仓做多损失点은 당일 최저 PIVOT 포인트 근처에,空仓做空损失点은 당일 최고 PIVOT 포인트 근처에 설치하여 위험을 효과적으로 잠금할 수 있다.

부분적으로 정지 논리는, 포지션을 개시한 후 특정 수익 수준에서 50%의 포지션을 닫는 것이다. 이렇게 하면 자금 사용 효율을 최적화할 수 있다.

종합적으로, 이 전략은 전체적으로 Capture가 과매매 상태의 정확한 시점; Control의 위험 관리 측면; Optimize의 자금 사용 효율성. 캡처, 컨트롤 및 Optimize의 유기적 결합이라고 할 수 있습니다.

전략적 이점

  • STOCH 지표를 사용하면 과매매 현상을 효과적으로 포착할 수 있으며, PIVOT 포인트와 함께 위험을 제어할 수 있어 거래 위험을 완전히 통제할 수 있다.

  • 부분 정지 메커니즘은 자금 사용 효율을 최적화한다. 부분 평점 방식을 채택하여 부분 수익을 보장하면서도 후속 운영 수익을 유지할 수 있다.

  • 전략의 매개 변수는 사용자 정의 가능하며, 거래자는 시장과 위험 선호에 따라 매개 변수를 조정하여 전략을 유연하게 사용할 수 있습니다.

  • 전략 논리는 매우 간단하고 명확하며, 이해하기 쉽고, 다양한 거래자가 사용할 수 있습니다. 코드는 직관적으로 읽기 쉽고, 수정을 쉽게합니다.

전략적 위험

  • 트렌드 추적 전략으로 쓰이는 이 트렌드 트래킹 전략은 변동적인 상황에 갇혀서 수익을 창출할 수 없습니다.

  • STOCH 지표는 잘못된 신호를 생성하여 불필요한 거래 행동을 유발할 수 있다. 불필요한 거래를 피하기 위해 신호를 적절히 필터링한다.

  • 정지점은 당일 축점에 가깝고, 돌파구 평정 후에 너무 가까이 올 수 있으므로, 정지 거리를 적절히 늘려야 한다.

  • 일부 전략 파라미터들, 예를 들어 기간 길이는 다른 시장에 따라 조정해야 하며, 그렇지 않으면 전략의 성과에 영향을 줄 수 있다.

  • 리베이트는 단지 역사적인 데이터에 기초하여 미래의 성과를 보장할 수 없습니다. 실전에서는 통제할 수 없는 요소에 의해 더 많은 영향을 받을 수 있습니다.

  • 자동 거래 시스템은 서버의 안정성을 보장하고, 연결 문제로 인해 정상 거래가 되지 않도록 한다.

전략 최적화 방향

  • 트렌드 필터를 도입하여 트렌드가 불분명할 때 맹목적인 거래를 방지할 수 있다. 예를 들어 MA 지표가 트렌드 방향을 판단하는 것을 포함한다.

  • 거래량 모니터링에 추가할 수 있습니다. 방전량, 공수 방전량 등과 같이, 필터링 가짜 돌파구. 을 피한다.

  • 다양한 품종, 주기에 따라 매개 변수를 조정할 수 있으며, 전략의 성능을 최적화할 수 있다. 예를 들어 STOCH의 매개 변수를 조정한다.

  • 머신러닝 알고리즘을 추가하고, 빅데이터 트레이닝 모델을 활용하여 자동으로 최적화된 파라미터를 고려할 수 있다.

  • 리스크 컨트롤을 도입하여 큰 손실이 발생하는 단위를 방지하기 위해 적당 손실 비율을 설정할 수 있습니다.

  • 더 많은 조건이 추가되어 진입 시기를 필터링하고 전략 승률을 높일 수 있습니다. 주식 기본 모형의 도입과 같은 것들.

요약하다

이 전략은 전체적으로 단순하고 직관적인 트렌드 추적 방법을 사용하여 STOCH 지표로 과매매 상태를 식별하고 PIVOT 중지 손실을 추가하여 위험을 제어하며, 투자 효율성을 최적화하기 위해 부분적인 차단을 도입합니다. 캡처, 제어 및 최적화 세 차원에서 설계되어 전체적인 자동 거래 시스템을 형성합니다. 이 전략의 논리는 이해하기 쉽고, 파라미터는 사용자 정의 할 수 있으며, 다른 거래자를 위해 사용할 수 있습니다.

전략 소스 코드
/*backtest
start: 2022-09-21 00:00:00
end: 2023-09-27 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="TradingView Alerts to MT4 MT5 - Forex, indices, commodities, stocks, crypto", commission_type=strategy.commission.cash_per_contract, commission_value=0.00003, overlay=false, default_qty_value=20000, initial_capital=1000)
//
// This script was created for educational purposes only.
// It is showing how to use Alerts-Straight-From-Strategies and
// dynamic variables in TradingView alerts.
// And how to auto-execute them in Forex, indices, commodities markets
// 
// (This method will also work with stocks and crypto - anything your 
// broker is offering via their MT4/MT5 platform).
 
TakeProfitLevel=input(400)
TakePartialProfitLevel=input(150)

// **** Entries logic **** {
periodK = input(13, 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 and year>2009
GoShort=crossunder(k,d) and k>20 and year>2009

AlertTest=open>close or open<close or open==close
// } 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

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)

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 TakePartialProfitLong
    alertsyntax_closepartlong='closepart tradeid=' + tostring(trade_id) + ' part=0.5'
    alert(message=alertsyntax_closepartlong, freq=alert.freq_once_per_bar_close)
if TakePartialProfitShort
    alertsyntax_closepartshort='closepart tradeid=' + tostring(trade_id) + ' part=0.5'
    alert(message=alertsyntax_closepartshort, freq=alert.freq_once_per_bar_close)