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

저자:차오장, 날짜: 2023-09-28 11:38:44
태그:

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

전략 개요

이 전략은 STOCH 지표와 PIVOT 지점과 결합하여 과도한 구매 및 과잉 판매 상태를 식별하여 트렌드를 따라 스톱 손실 포지션을 설정합니다. STOCH 지표가 과잉 구매 또는 과잉 판매 신호를 표시 할 때 길거나 짧습니다. 중단 손실 포인트는 위험을 효과적으로 제어하기 위해 하루의 PIVOT 지점 근처에 설정됩니다. 부분 수익 포인트는 특정 수익 수준 후에 부분 포지션을 종료하도록 설정됩니다.

전략 논리

이 전략은 STOCH 지표의 %K 및 %D 라인의 교차를 사용하여 긴 및 짧은 신호를 생성합니다. 구체적으로, %K 라인이 %D 라인의 위를 넘을 때, 그것은 길게 갈 것입니다. %K 라인이 %D 라인의 아래를 넘을 때, 그것은 짧게 갈 것입니다. 이것은 과잉 구매 및 과잉 판매 상태를 캡처합니다.

위험을 통제하기 위해, 긴 스톱 로스 포인트는 매일 가장 낮은 PIVOT 포인트 근처에 설정되고 짧은 스톱 로스 포인트는 매일 가장 높은 PIVOT 포인트 근처에 설정됩니다. 이것은 효과적으로 위험을 잠그고 있습니다.

부분적 취득을 위해, 포지션 개척 후 특정 수익 수준 후에 포지션의 50%를 닫습니다. 이것은 자본 활용 효율을 최적화합니다.

요약하자면, 이 전략은 과잉 구매 및 과잉 판매 포인트를 적절히 캡처하고, 스톱 로스를 사용하여 위험을 제어하고, 자본 사용 효율을 최적화합니다. 그것은 캡처, 컨트롤 및 최적화를 유기적으로 결합합니다.

전략 강점

  • STOCH 지표를 사용하면 과잉 구매 및 과잉 판매 상태를 효과적으로 파악 할 수 있습니다. PIVOT 포인트로 위험을 포괄적으로 제어합니다.

  • 부분 수익 메커니즘은 자본 사용 효율을 최적화합니다. 부분 폐쇄는 추가 이익에 대한 공간을 유지하면서 약간의 이익을 보장합니다.

  • 사용자 정의 가능한 매개 변수는 시장 조건과 위험 선호도에 따라 유연성을 허용합니다.

  • 단순하고 명확한 논리, 모든 거래자가 쉽게 이해하고 마스터 할 수 있습니다. 깨끗한 코드는 수정 및 유지보수를 촉진합니다.

전략 위험

  • 트렌드를 따라가는 전략으로서, 범위에 묶인 시장에 갇혀서 수익을 얻지 못할 수도 있습니다.

  • STOCH는 잘못된 신호를 생성하여 불필요한 거래를 일으킬 수 있습니다. 원치 않는 거래를 피하기 위해 적절한 신호 필터링이 필요합니다.

  • 피보트 포인트 근처의 스톱 손실은 브레이크 이후 너무 가깝게 될 수 있습니다.

  • 기간과 같은 일부 매개 변수들은 다른 시장에 대한 조정이 필요할 수 있습니다. 그렇지 않으면 전략 성과에 영향을 미칩니다.

  • 백테스트는 역사적인 데이터에만 의존합니다. 미래 성과를 보장할 수 없습니다. 실시간 거래에서 통제할 수 없는 요소가 더 많습니다.

  • 자동 거래 시스템은 거래 실행 문제를 피하기 위해 안정적인 연결이 필요합니다.

전략 최적화

  • 트렌드 필터를 추가하여 명확한 트렌드가 없는 거래를 피합니다. 예를 들어 트렌드 방향을 결정하기 위해 MA를 사용하는 것과 같습니다.

  • 부진을 감지하고 함정을 피하기 위해 볼륨 분석을 추가하십시오. 예를 들어 상승/하락 볼륨.

  • 성능을 최적화하기 위해 다른 제품과 시간 프레임에 따라 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)


더 많은