OBV와 MA 교차 신호를 기반으로 한 추세 추종 전략

OBV MA SMA
생성 날짜: 2024-04-29 13:48:58 마지막으로 수정됨: 2024-04-29 13:48:58
복사: 0 클릭수: 802
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

OBV와 MA 교차 신호를 기반으로 한 추세 추종 전략

개요

이 전략은 “OBV와 MA의 교차 신호에 기반한 OBVious MA 전략”이라고 불리며, 핵심은 OBV (On Balance Volume) 지표와 이동 평균의 교차를 사용하여 거래 신호를 생성하는 것입니다. OBV는 선도적인 트렌드 신호를 제공 할 수 있으며, 이 전략은 OBV를 이동 평균을 뚫고 진입 및 출퇴근 조건으로 사용하여 트렌드를 포착합니다. 독립적인 진입 MA와 출퇴근 MA를 동시에 사용하여 포지션 시간을 더 유연하게 제어 할 수 있습니다.

전략 원칙

  1. OBV 지표값을 계산한다: 만약 현재 종결가치가 앞의 K선보다 높다면, OBV는 현재 거래량을 더하고, 그렇지 않으면 거래량을 다.
  2. OBV의 네 가지 이동 평균을 계산한다: 장기 많은 출전 MA, 장기 많은 출전 MA, 단기 빈 출전 MA 및 단기 빈 출전 MA.
  3. 트레이딩 신호를 생성합니다.
    • OBV에서 장기 사이클을 착용하고 MA를 추가하고 방향 필터가 공백을 만들지 않을 때 더 많은 포지션을 열기
    • OBV 아래의 긴 사이클에서 더 많은 출전 MA를 할 때, 평상시 더 많은 포지션
    • OBV 아래에서 짧은 주기 공백 입구 MA를 통과하고 방향 필터가 더 이상 작동하지 않을 때, 공백 창고
    • OBV 상에서 짧은 주기적으로 공백 출장 MA를 할 때, 공백 포지션
  4. 거래 관리: 역전 신호가 발생하면, 기존의 포지션을 제거하고 새로운 포지션을 개설한다.

전략적 이점

  1. 오비 (OBV) 의 선도적인 트렌드 신호를 최대한 활용하여 트렌드 초기에 적시에 매장할 수 있다.
  2. 출장과 출장 마를 분리하여 출장 시기를 독립적으로 최적화 할 수 있습니다.
  3. 코드의 논리는 간단하고 명확하며, 이해하기 쉽고 개선하기 쉽습니다.
  4. 방향 필터를 도입하여 빈번한 거래를 방지하고 비용을 절감할 수 있습니다.

전략적 위험

  1. 다른 확인 지표가 없으면 잘못된 신호가 발생할 수 있습니다. 다른 지표와 함께 사용하는 것이 좋습니다.
  2. 단편적 손실을 증가시킬 위험이 있는 스톱로스 및 포지션 관리의 부족. 합리적인 스톱로스 및 재원 관리 조치에 추가 될 수 있다.
  3. 매개 변수 선택이 적절하지 않으면 전략 성능에 영향을 줄 수 있다. 다른 시장 특성과 주기에 따라 매개 변수 최적화가 필요하다.

전략 최적화 방향

  1. 트렌드 필터, MA 방향, ATR 등을 도입하여 신호 품질을 향상시킬 수 있습니다.
  2. OBV에 EMA, WMA 등과 같은 다른 유형의 MA를 사용하여 다른 속도의 추세를 잡을 수 있습니다.
  3. 포지션 관리를 최적화 할 수 있습니다. 예를 들어, 트렌드 강도가 상승 할 때 포지션을 올리고, 감소 할 때 포지션을 줄이는 전략이 적용됩니다.
  4. MVA, PVT 등과 같은 다른 수량 지표와 결합하여 합동 신호를 구성하여 승률을 높일 수 있다.

요약하다

이 전략은 OBV와 MA의 교차를 기반으로 한 간단한 트렌드 추적 방법을 보여줍니다. 장점은 논리적으로 명확하고, 트렌드를 적시에 포착 할 수 있으며, 출구 MA를 분리하여 포지션을 유연하게 제어 할 수 있습니다. 단점은 위험 제어 조치와 신호 확인 수단이 부족하다는 것입니다. 추세 필터링, 매개 변수 최적화, 포지션 관리, 결합 신호 등의 측면에서 후속적으로 개선 할 수 있습니다. 더 안정적인 전략 성능을 얻기 위해 이 전략은 가이드 신호로 협력하여 다른 전략과 함께 사용할 수 있습니다.

전략 소스 코드
/*backtest
start: 2023-04-23 00:00:00
end: 2024-04-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ThousandX_Trader

//@version=5
strategy(title="OBVious MA Strategy [1000X]", overlay=false, 
         initial_capital=10000, margin_long=0.1, margin_short=0.1,
         default_qty_type=strategy.percent_of_equity, default_qty_value=100,
         slippage=1, commission_type=strategy.commission.percent, commission_value=0.1)

// Direction Input ///
tradeDirection = input.string("long", title="Direction", options=["long", "short"], group = "Direction Filter")

    ///////////////////////////////////////
   //  1000X OBV MA INDICATOR           //
  ///////////////////////////////////////

// OBV Trend Length Inputs //
long_entry_length = input(190, title="Long Entry MA Length", group = "Moving Average Settings")
long_exit_length = input(202, title="Long Exit MA Length", group = "Moving Average Settings")
short_entry_length = input(395, title="Short MA Entry Length", group = "Moving Average Settings")
short_exit_length = input(300, title="Short Exit MA Length", group = "Moving Average Settings")

// OBV Calculation
obv = ta.cum(ta.change(close) >= 0 ? volume : -volume)

// Calculate OBV Moving Averages
obv_ma_long_entry = ta.sma(obv, long_entry_length)
obv_ma_long_exit = ta.sma(obv, long_exit_length)
obv_ma_short_entry = ta.sma(obv, short_entry_length)
obv_ma_short_exit = ta.sma(obv, short_exit_length)

   ///////////////////////////////////////
  //         STRATEGY RULES            //
 ///////////////////////////////////////

longCondition = ta.crossover(obv, obv_ma_long_entry) and tradeDirection != "short" and strategy.position_size <= 0
longExitCondition = ta.crossunder(obv, obv_ma_long_exit)
shortCondition = ta.crossunder(obv, obv_ma_short_entry) and tradeDirection != "long" and strategy.position_size >= 0
shortExitCondition = ta.crossover(obv, obv_ma_short_exit)

  ///////////////////////////////////////
 //         ORDER EXECUTION           //
///////////////////////////////////////

// Close opposite trades before entering new ones
if (longCondition and strategy.position_size < 0)
    strategy.close("Short Entry")

if (shortCondition and strategy.position_size > 0)
    strategy.close("Long Entry")

// Enter new trades
if (longCondition)
    strategy.entry("Long Entry", strategy.long)

if (shortCondition)
    strategy.entry("Short Entry", strategy.short)

// Exit conditions
if (longExitCondition)
    strategy.close("Long Entry")

if (shortExitCondition)
    strategy.close("Short Entry")

  ///////////////////////////////////////
 //            PLOTTING               //
///////////////////////////////////////

// Plot OBV line with specified color
plot(obv, title="OBV", color=color.new(#2962FF, 0), linewidth=1)

// Conditionally plot Long MAs with specified colors based on Direction Filter
plot(tradeDirection == "long" ? obv_ma_long_entry : na, title="Long Entry MA", color=color.new(color.rgb(2, 130, 228), 0), linewidth=1)
plot(tradeDirection == "long" ? obv_ma_long_exit : na, title="Long Exit MA", color=color.new(color.rgb(106, 168, 209), 0), linewidth=1)

// Conditionally plot Short MAs with specified colors based on Direction Filter
plot(tradeDirection == "short" ? obv_ma_short_entry : na, title="Short Entry MA", color=color.new(color.rgb(163, 2, 227), 0), linewidth=1)
plot(tradeDirection == "short" ? obv_ma_short_exit : na, title="Short Exit MA", color=color.new(color.rgb(192, 119, 205), 0), linewidth=1)