신경과 전문의 트레이딩 로봇

EMA BB MACD RSI DCA
생성 날짜: 2025-10-20 15:48:05 마지막으로 수정됨: 2025-10-20 15:48:05
복사: 0 클릭수: 216
avatar of ianzeng123 ianzeng123
2
집중하다
329
수행원

신경과 전문의 트레이딩 로봇 신경과 전문의 트레이딩 로봇

이것은 일반적인 DCA 전략이 아니라, 생각을 하는 거래 로봇입니다.

수천 개의 파인 스크립트 코드를 살펴보면, 이 “마스터 트레이딩 봇”은 두 가지 브러쉬가 있습니다. 저자는 DCA를 새로운 수준으로 끌어 올렸습니다. 무심한 투자가 아니라 기술 지표에 기반한 지능형 증액 시스템입니다. 초기 포지션은 5%이며, DCA가 증가할 때마다 2.5%, 최대 100%를 넘지 않습니다.

핵심은 DCA의 촉발 조건에 있습니다: 가격은 평균 비용 가격보다 떨어져야하며, 하락은 2% + 단계 × 4%의 동적 하락에 도달해야합니다. 첫 번째 DCA는 2% 떨어져야하고, 두 번째는 6% 떨어져야하며, 세 번째는 10% 떨어져야합니다. 이러한 디자인은 작은 변동에서 자주 가중되는 것을 피하고, 진정한 회귀에서만 증가합니다.

다중 기술 지표의 조합, 하지만 논리적으로 명확하고 불필요하지 않습니다.

이 전략은 3/7/18 주기 EMA를 사용하여 트렌드 프레임워크를 구축하고, 20 주기 브린 밴드를 사용하여 가격 위치를 판단하고, 52/200/3의 MACD 파라미터를 설정하여 중기 중기 신호를 편향하고, 14 주기 RSI는 과매매 과매매 판단을 위해 사용됩니다. 이 조합은 트렌드, 운동, 변동성의 세 가지 차원을 포괄하며, 단일 지표 전략보다 더 신뢰할 수 있습니다.

구매 조건은 엄격하다: 빠른 EMA> 느린 EMA+MACD 금포+가격은 브린 중도 궤도 상위 + RSI <65 ᄂ. 이 네 가지 조건이 동시에 충족되면 입장을 열 수 있으며, 대부분의 가짜 신호를 필터링 할 수 있다. 판매 조건은 마찬가지로 엄격하다: 최소 2%의 수익 + 추세가 약화 + MACD 사각지대가 있어야 한다. 이러한 “이익을 얻기 위해 판매”의 설계는 무의미한 손실을 피한다.

100% 상쇄가 과격한 것처럼 보이지만, 합리적입니다.

코드에서 100%의 스톱로스는 과장된 것처럼 보이지만, 코멘트는 명확하게 “가격이 0으로 떨어져야 촉발된다”라고 말한다. 이것은 사실상 전통적인 스톱로스를 닫고, 기술 지표와 수익 목표에 전적으로 의존하여 위험을 관리한다. DCA 전략에 있어서는 이 디자인은 합리적입니다.

진정한 위험 통제는: 2% 가격 하락 신호 + 동적 DCA 하락 + 강제 이익 철수. 전략은 500주기 동안의 최고 가격을 추적하고, 현재 가격의 최고점에서 2% 이상 떨어지면 판매 신호를 유발합니다. 이것은 고정된 스톱 손실보다 더 유연하며, 다른 시장 환경에 적응할 수 있습니다.

이 전략의 핵심은 자금 관리입니다.

매번 매입되는 금액 = 현재 이자 × DCA 비율 ÷ 현재 가격, 이 이자 비율이 아닌 고정 금액으로 설계된 이 전략은 계정 성장에 따라 포지션을 확장할 수 있게 해준다. 초기 5%의 포지션은 일회성 위험을 통제하고, 점진적 인 포지션은 실제 기회에 충분한 화력이 있음을 보장한다.

가장 정교한 것은 “just_sold” 상태 관리입니다: 팔린 후에 다시 구매하지 않습니다. 강한 호기심의 신호가 나타나지 않는 한 말이죠. 이것은 불안한 시장에서 자주 거래되는 것을 피하고, 수수료 비용과 감정적 인 조작의 위험을 줄입니다.

“사실, 모든 것이 다룰 수 있는 전략이 아닙니다.

이 전략은 중장기 상승 추세에서 회귀 구매를 위해 가장 적합하며, 곰 시장이나 장기 수평에서 매우 일반적으로 나타납니다. MACD의 52200 파라미터 설정은 더 큰 수준의 추세 판단에 적합하며, 단선 거래에는 적합하지 않습니다.

RSI 오버소드 문은 30이 아닌 25으로 설정되어, 전략적 편향이 더 깊은 회귀에서 구매하는 것을 나타냅니다. 이 디자인은 황소 시장에서 더 나은 구매 지점을 얻을 수 있지만, 곰 시장에서 “사격 칼”이 될 수 있습니다. 명확한 상승 추세에서 사용하는 것이 권장되며, 시장의 상위 또는 하향 추세에서 시작하는 것을 피하십시오.

최대 회수 및 연쇄 손실에 주의를 기울여야 합니다.

전략의 이론적 논리는 완벽하지만 실제 성과는 구체적인 재검토 데이터에 달려있다. 주요 관심사는 최대 회수 범위가 허용 가능한 범위, 연속 손실이 너무 많거나, 다른 시장 환경에서의 성능 차이가 있는지 여부이다.

DCA 전략의 자연스러운 특징은 하락 과정에서 계속 가중되는 것으로, 이는 계정의 순가치가 먼저 하락하고 나서 상승한다는 것을 의미한다. 투자자는 충분한 심리적 견딜 수 있는 능력과 자금 저축을 갖춰야 한다. 먼저 작은 자금으로 테스트하고 전략 특성을 확인한 후 점차적으로 투자 규모를 늘리는 것이 좋습니다.

위험 팁: 모든 양적 전략에는 손실의 위험이 있습니다. 역사적인 회전은 미래의 수익을 나타내지 않으며, 엄격한 위험 관리와 적절한 재원 배분이 필요합니다.

전략 소스 코드
/*backtest
start: 2024-10-20 00:00:00
end: 2025-10-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":500000}]
*/

// This Pine Script™ code is subject to the terms of the MPL 2.0 at https://mozilla.org/MPL/2.0/
// © MTB by Neurodoc
// By Nicolás Astorga

//@version=5
strategy("Master Trading Bot by Neurodoc", 
         shorttitle="MTB Adaptation", 
         overlay=true, 
         initial_capital=10000, 
         pyramiding=100,
         commission_value=0.1, 
         commission_type=strategy.commission.percent,
         default_qty_type = strategy.cash)

// —————— CONFIGURATION (Based on ve.env) ——————
// Purchase and DCA Percentages
var GRP_DCA = "DCA Configuration"
start_percentage = input.float(5.0, "Initial Buy Percentage (%)", group=GRP_DCA)
increment_percentage = input.float(2.5, "Increment per DCA Buy (%)", group=GRP_DCA)
max_percentage = input.float(100.0, "Maximum Buy Percentage (%)", group=GRP_DCA)
min_profit_percent = input.float(2.0, "Minimum Profit for Sell (%)", group=GRP_DCA)

// Stop Loss and Drop Signal
var GRP_RISK = "Risk Management"
stop_loss_percent = input.float(100.0, "Stop Loss (%)", group=GRP_RISK, tooltip="A value of 100 means there’s no real stop loss, as price would have to go to 0.")
drop_percent_signal = input.float(2.0, "Price Drop for Sell Signal (%)", group=GRP_RISK)

// Indicator Parameters
var GRP_INDICATORS = "Indicator Parameters"
ema_fast_period = input.int(3, "Fast EMA", group=GRP_INDICATORS)
ema_mid_period = input.int(7, "Medium EMA", group=GRP_INDICATORS)
ema_slow_period = input.int(18, "Slow EMA", group=GRP_INDICATORS)
bb_length = input.int(20, "Bollinger Bands Length", group=GRP_INDICATORS)
bb_stddev = input.float(2.0, "BB Standard Deviation", group=GRP_INDICATORS)
macd_fast = input.int(52, "MACD Fast", group=GRP_INDICATORS)
macd_slow = input.int(200, "MACD Slow", group=GRP_INDICATORS)
macd_signal = input.int(3, "MACD Signal", group=GRP_INDICATORS)
rsi_length = input.int(14, "RSI Length", group=GRP_INDICATORS)
rsi_oversold_threshold = input.int(25, "RSI Oversold (for divergence)", group=GRP_INDICATORS)

// —————— INDICATOR CALCULATIONS ——————
// EMAs
ema_fast = ta.ema(open, ema_fast_period)
ema_mid = ta.ema(open, ema_mid_period)
ema_slow = ta.ema(open, ema_slow_period)

// Bollinger Bands
[bb_middle, bb_upper, bb_lower] = ta.bb(close, bb_length, bb_stddev)
bb_width = (bb_upper - bb_lower) / bb_middle * 100
is_bb_expanding = bb_width > bb_width[1]

// MACD
[macd_line, signal_line, _] = ta.macd(close, macd_fast, macd_slow, macd_signal)

// RSI
rsi = ta.rsi(close, rsi_length)

// Price drop signal from highest price (similar to `cummax` in Python)
highest_price = ta.highest(high, 500) // Using 500-bar lookback to approximate the high
price_drop_percent = ((highest_price - close) / highest_price) * 100
is_price_drop_signal = price_drop_percent >= drop_percent_signal

// —————— TRADING LOGIC ——————
// Trend Conditions
is_bullish = ema_fast > ema_slow and macd_line > signal_line and close > bb_middle
is_bearish = ema_fast < ema_slow and macd_line < signal_line and close < bb_middle
is_weakening = rsi < rsi[1]

// Variables to manage strategy state
var bool just_sold = false
var int dca_step = 0

// Determine next buy percentage of capital
dca_buy_percentage = start_percentage + (dca_step * increment_percentage)
if dca_buy_percentage > max_percentage
    dca_buy_percentage := max_percentage

avg_buy_price = strategy.position_avg_price

// Initial Long Condition
long_signal_initial = strategy.position_size == 0 and is_bullish and macd_line > signal_line and rsi < 65

// DCA Condition
price_drop_from_avg = ((avg_buy_price - close) / avg_buy_price) * 100
dca_required_drop = 2.0 + (dca_step * 4.0) // DCA price drop start and increment logic
long_signal_dca = strategy.position_size > 0 and is_bearish and close < avg_buy_price and price_drop_from_avg >= dca_required_drop

// Manage `just_sold` state
if strategy.position_size > 0
    just_sold := false
if strategy.position_size == 0 and strategy.position_size[1] > 0
    just_sold := true

// Avoid immediate repurchase after sell unless bullish condition is strong
long_signal = (just_sold and is_bullish) ? long_signal_initial : (not just_sold ? (long_signal_initial or long_signal_dca) : false)

// Sell (Close) Condition
current_profit_percent = ((close - avg_buy_price) / avg_buy_price) * 100
has_min_profit = current_profit_percent >= min_profit_percent
stop_loss_price = avg_buy_price * (1 - stop_loss_percent / 100)
is_stoploss_triggered = close <= stop_loss_price

short_signal = strategy.position_size > 0 and has_min_profit and ((is_bearish and is_weakening) or is_price_drop_signal or is_stoploss_triggered or (macd_line < signal_line))

// —————— ORDER EXECUTION ——————
if (long_signal)
    // Calculate how much MONEY (USDT) to invest in this trade
    cash_to_invest = (strategy.equity * dca_buy_percentage / 100) / close
    strategy.entry("Buy", strategy.long, qty=cash_to_invest)
    dca_step := dca_step + 1
        
if (short_signal)
    strategy.close_all(comment="Sell")
    dca_step := 0 // Reset DCA counter after selling

// —————— VISUALIZATION ——————
// Background color by trend
bgcolor(is_bullish ? color.new(color.green, 90) : is_bearish ? color.new(color.red, 90) : na)

// Plot EMAs and Bollinger Bands
plot(ema_fast, "Fast EMA", color.blue)
plot(ema_slow, "Slow EMA", color.orange)
p1 = plot(bb_upper, "Upper BB", color=color.gray)
p2 = plot(bb_lower, "Lower BB", color=color.gray)
fill(p1, p2, color=color.new(color.gray, 90))

// Plot average buy price when in position
plot(strategy.position_size > 0 ? avg_buy_price : na, "Average Buy Price", color.yellow, style=plot.style_linebr, linewidth=2)

// Plot Take Profit target
plot(strategy.position_size > 0 ? avg_buy_price * (1 + min_profit_percent / 100) : na, "Sell Price (TP)", color.aqua, style=plot.style_linebr, linewidth=2)

// Plot Stop Loss level
plot(strategy.position_size > 0 ? stop_loss_price : na, "Stop Loss", color.fuchsia, style=plot.style_linebr, linewidth=2)