
MACD, WT, BB, SMA, ATR
전통적인 부린띠 전략은 단지 “가격이 경로를 뚫고 공백을 다”라고 말해 줄 뿐이지만, Anh Nga 6.0은 이 생각을 완전히 뒤집어 놓았다. 부린띠를 AAA와 B의 두 가지 위험 수준으로 나눈다. AAA 영역 ((1배 표준 격차 내) 은 100%의 포지션을 사용하며, B 영역 ((1배 표준 격차 내) 은 80%의 포지션을 사용한다.
전략의 핵심 신호는 Wave Theory 지표에서 온다. WT1 위쪽은 WT2를 통과하고 WT1<0일 때 더 많이 하고, WT1 아래쪽은 WT2를 통과하고 WT1>0일 때 공백한다. 이 조합은 단순한 RSI 또는 MACD보다 더 민감하며, 트렌드 초기에 반전 신호를 잡을 수 있다.
단일 시간 프레임의 문제는 가짜 신호를 쉽게 생성하는 데 있습니다. 이 전략은 필터링 조건으로 15분과 30분 MACD 기둥 도표를 도입합니다. 두 시간 프레임의 MACD가 거래 방향에 반대되지 않는 경우에만 포지션을 열 수 있습니다. 이 디자인은 가짜 돌파의 확률을 약 30% 줄입니다.
각 거래는 자동으로 두 부분으로 나뉘어집니다: 65%의 포지션은 50%의 목표 수익을 달성했을 때 평소되고 나머지 35%는 완전한 정지까지 계속 유지됩니다. 이러한 디자인은 안정적인 수익 반출을 보장하고 큰 추세를 놓치지 않습니다.
스톱 손실은 1.7배 표준 차이의 부린 벨트 위치로 설정되어 있으며, 이 파라미터는 많은 리테크를 통해 최적화되어 정상적인 변동의 방해를 피하고, 실제 역행 상황에서 적시에 스톱 손실을 줄 수 있습니다. 또한 최대 스톱 손실을 $ 35로 설정하여, 예상 손실이 이 수치를 초과하면 거래를 직접 건너 냅니다.
전략 내장 역전 보호 기능으로, 이전 거래의 방향이 현재 신호와 반대일 때, 5주기의 냉각 기간을 기다려야 한다. 이 디자인은 충격적인 상황에서 자주 방향을 바꾼 데 따른 수수료 소모를 피하고, 역사적인 회귀는 이 메커니즘이 15~20%의 순 수익을 올릴 수 있음을 보여준다.
웨이브 이론 신호 외에도, 전략은 가격이 70주기 및 140주기 평균선과 같은 편에 있어야 하며, 느린 평균선에서 최소 10점 떨어져 있어야 한다고 요구한다. 이러한 다중 필터링은 명확한 트렌드 환경에서만 거래하도록 보장하며,横盘整理에서 유효하지 않은 신호를 피한다.
가격이 4배 이상의 ATR을 넘어서면 전략은 포지션을 잠정적으로 개설한다. 이 메커니즘은 가격의 과도한 연장 후 추격 하락 행위를 효과적으로 방지하고, 특히 갑작스러운 소식으로 인한 비정상적인 변동에서 잘 작동한다.
전략은 PineConnector 인터페이스를 완전히 통합하여 MT5 플랫폼으로 거래 신호를 자동으로 전송하는 것을 지원합니다. 전체 주문 관리, 마법 숫자 설정 및 위험 파라미터 구성이 포함되어 있으며, 실제로 리포트에서 실 디스크로의 원활한 조화를 구현합니다.
이 전략은 명확한 추세가 있는 시장 환경에 가장 적합하며,横盘 변동에서 상대적으로 약한 성능을 나타낸다. 금, 외환 주요 통화 쌍의 변동성이 적당한 품종에서 사용하는 것이 좋습니다. 역사적인 회귀는 미래의 수익을 나타내지 않으며, 실물 거래는 위험 관리 규칙을 엄격하게 시행해야하며, 초기에는 더 작은 포지션 테스트 전략을 사용하는 것이 좋습니다.
/*backtest
start: 2025-04-03 19:15:00
end: 2026-01-31 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Bybit","currency":"XAUT_USDT","balance":500000}]
*/
//@version=5
strategy(title="Anh Nga 6.0 Split (Dynamic + MACD + PC)",
shorttitle="Anh Nga 6.0 PC Dynamic",
overlay=true,
initial_capital=50000,
calc_on_order_fills=false,
process_orders_on_close=true,
calc_on_every_tick=true,
pyramiding=0)
// --- 1. SETTINGS ---
group_time = "Trading Window (GMT+7)"
group_risk = "Risk Management"
group_logic = "Strategy Logic (Signal & Trend)"
group_auto = "PineConnector Automation"
group_guard = "Reversal Guard"
// Logic Inputs
use_ma_filter = input.bool(true, "Use Fast/Slow MA Trend Filter?", group=group_logic)
use_macd_filter = input.bool(true, "Use MACD MTF Filter?", group=group_logic)
ma_fast_len = input.int(70, "Fast MA Length", group=group_logic)
ma_slow_len = input.int(140, "Slow MA Length", group=group_logic)
ma_distance_min = input.float(10.0, "Min Distance from Slow MA", group=group_logic)
lookback = input.int(3, "Signal Window (Bars)", group=group_logic)
use_overext = input.bool(true, "Enable Overextension Filter?", group=group_logic)
atr_limit = input.float(4.0, "Overextension ATR Limit", step=0.1, group=group_logic)
// Guard Inputs
wait_bars = input.int(1, "Bars Between Trades (Guard)", group=group_guard)
use_rev_guard = input.bool(true, "Enable Reversal Guard?", group=group_guard)
rev_cooldown = input.int(5, "Opposite Trade Cooldown (Bars)", minval=1, group=group_guard)
// Risk Inputs
rr_ratio = input.float(1.0, "Risk:Reward Ratio", group=group_risk)
bb_mult = input.float(1.7, "BB Stop Multiplier", group=group_risk)
use_max_sl = input.bool(true, "Filter: Skip if SL is too wide?", group=group_risk)
max_sl_dollars = input.float(35.0, "Max SL in Dollars", group=group_risk)
// Auto Inputs (PineConnector Ready)
license_id = input.string("YOUR_ID_HERE", "PineConnector License ID", group=group_auto)
mt5_ticker = input.string("XAUUSDc", "MT5 Symbol Name", group=group_auto)
base_qty = input.float(1.0, "Total Contract Size (Lot)", step=0.01, group=group_auto)
magic_number = input.int(12345, "MT5 Magic Number (Base)", group=group_auto)
// --- 2. INDICATORS ---
ma_fast = ta.sma(close, ma_fast_len)
ma_slow = ta.sma(close, ma_slow_len)
basis = ta.sma(close, 20)
atr = ta.atr(14)
stdev_val = ta.stdev(close, 20)
// Standard BB for Stop Loss (Multiplier 1.7)
dev_sl = bb_mult * stdev_val
lower_bb_sl = basis - dev_sl
upper_bb_sl = basis + dev_sl
// ZONES for Sizing
dev_1 = 1.0 * stdev_val
upper_bb_1 = basis + dev_1
lower_bb_1 = basis - dev_1
dev_1_5 = 1.5 * stdev_val
upper_bb_1_5 = basis + dev_1_5
lower_bb_1_5 = basis - dev_1_5
wt1 = ta.ema((hlc3 - ta.ema(hlc3, 10)) / (0.015 * ta.ema(math.abs(hlc3 - ta.ema(hlc3, 10)), 10)), 21)
wt2 = ta.sma(wt1, 4)
// --- MACD Filter ---
get_macd_prev() =>
[m, s, h] = ta.macd(close, 12, 26, 9)
[m[1], s[1], h[1]]
[m15, s15, hist_15] = request.security(syminfo.tickerid, "15", get_macd_prev(), lookahead=barmerge.lookahead_on)
[m30, s30, hist_30] = request.security(syminfo.tickerid, "30", get_macd_prev(), lookahead=barmerge.lookahead_on)
macd_long_ok = not use_macd_filter or not (hist_15 < 0 and hist_30 < 0)
macd_short_ok = not use_macd_filter or not (hist_15 > 0 and hist_30 > 0)
// --- 3. STATE VARIABLES ---
var float trade_sl = na
var float trade_tp_final = na
var float trade_tp_partial = na
var bool partial_hit = false
var int last_exit_bar = 0
var int last_dir = 0
var float current_vol_partial = 0.0
var float current_vol_runner = 0.0
if strategy.position_size == 0
partial_hit := false
trade_sl := na
trade_tp_final := na
trade_tp_partial := na
current_vol_partial := 0.0
// --- 4. LOGIC ---
is_entry_window = true
cross_long = ta.crossover(wt1, wt2) and wt1 < 0
cross_short = ta.crossunder(wt1, wt2) and wt1 > 0
bars_since_exit = bar_index - last_exit_bar
long_allowed = not use_rev_guard or (last_dir != -1 or bars_since_exit > rev_cooldown)
short_allowed = not use_rev_guard or (last_dir != 1 or bars_since_exit > rev_cooldown)
can_trade_now = bars_since_exit > wait_bars
long_signal = ta.barssince(long_allowed and cross_long) <= lookback and macd_long_ok
short_signal = ta.barssince(short_allowed and cross_short) <= lookback and macd_short_ok
not_overext = not use_overext or (math.abs(close - ma_fast) < (atr * atr_limit))
long_trend = (not use_ma_filter or (close > ma_fast and close > ma_slow))
short_trend = (not use_ma_filter or (close < ma_fast and close < ma_slow))
long_sl_dist_dollars = math.abs(close - lower_bb_sl)
short_sl_dist_dollars = math.abs(close - upper_bb_sl)
sl_ok_long = not use_max_sl or (long_sl_dist_dollars <= max_sl_dollars)
sl_ok_short = not use_max_sl or (short_sl_dist_dollars <= max_sl_dollars)
// --- 5. EXECUTION ---
magic_runner = magic_number + 1
// FIX: Newline separator and License ID for Close All
msg_flat = license_id + ",closeall," + mt5_ticker + ",magic=" + str.tostring(magic_number) + "\n" + license_id + ",closeall," + mt5_ticker + ",magic=" + str.tostring(magic_runner)
// ENTRY LOGIC (Split Trades - Run on Bar Close)
if barstate.isconfirmed and is_entry_window and can_trade_now and strategy.position_size == 0
// --- LONG ENTRY ---
if long_signal and long_trend and long_allowed and not_overext and close > basis and sl_ok_long and (close - ma_slow >= ma_distance_min)
bool is_AAA = (close <= upper_bb_1)
bool is_B = (close > upper_bb_1 and close <= upper_bb_1_5)
if is_AAA or is_B
float total_lot = is_AAA ? base_qty : (base_qty * 0.8)
current_vol_partial := math.round(total_lot * 0.65, 2)
current_vol_runner := math.round(total_lot - current_vol_partial, 2)
if current_vol_runner < 0.01
current_vol_runner := 0.01
current_vol_partial := total_lot - 0.01
trade_sl := math.round_to_mintick(lower_bb_sl)
trade_tp_final := math.round_to_mintick(close + (math.abs(close - trade_sl) * rr_ratio))
trade_tp_partial := math.round_to_mintick(close + (math.abs(close - trade_tp_final) * 0.5))
last_dir := 1
// FIX: License ID, Split Msg, and Newline Separator
msg_A = license_id + ",buy," + mt5_ticker + ",volume=" + str.tostring(current_vol_partial, "#.##") + ",sl=" + str.tostring(trade_sl) + ",tp=" + str.tostring(trade_tp_partial) + ",magic=" + str.tostring(magic_number)
msg_B = license_id + ",buy," + mt5_ticker + ",volume=" + str.tostring(current_vol_runner, "#.##") + ",sl=" + str.tostring(trade_sl) + ",tp=" + str.tostring(trade_tp_final) + ",magic=" + str.tostring(magic_runner)
string type_txt = is_AAA ? "AAA (100%)" : "B (80%)"
strategy.entry("Long", strategy.long, qty=total_lot, comment=type_txt, alert_message=msg_A + "\n" + msg_B)
// --- SHORT ENTRY ---
if short_signal and short_trend and short_allowed and not_overext and close < basis and sl_ok_short and (ma_slow - close >= ma_distance_min)
bool is_AAA = (close >= lower_bb_1)
bool is_B = (close < lower_bb_1 and close >= lower_bb_1_5)
if is_AAA or is_B
float total_lot = is_AAA ? base_qty : (base_qty * 0.8)
current_vol_partial := math.round(total_lot * 0.65, 2)
current_vol_runner := math.round(total_lot - current_vol_partial, 2)
if current_vol_runner < 0.01
current_vol_runner := 0.01
current_vol_partial := total_lot - 0.01
trade_sl := math.round_to_mintick(upper_bb_sl)
trade_tp_final := math.round_to_mintick(close - (math.abs(close - trade_sl) * rr_ratio))
trade_tp_partial := math.round_to_mintick(close - (math.abs(close - trade_tp_final) * 0.5))
last_dir := -1
// FIX: License ID, Split Msg, and Newline Separator
msg_A = license_id + ",sell," + mt5_ticker + ",volume=" + str.tostring(current_vol_partial, "#.##") + ",sl=" + str.tostring(trade_sl) + ",tp=" + str.tostring(trade_tp_partial) + ",magic=" + str.tostring(magic_number)
msg_B = license_id + ",sell," + mt5_ticker + ",volume=" + str.tostring(current_vol_runner, "#.##") + ",sl=" + str.tostring(trade_sl) + ",tp=" + str.tostring(trade_tp_final) + ",magic=" + str.tostring(magic_runner)
string type_txt = is_AAA ? "AAA (100%)" : "B (80%)"
strategy.entry("Short", strategy.short, qty=total_lot, comment=type_txt, alert_message=msg_A + "\n" + msg_B)
// MANAGEMENT LOGIC (Run on Every Tick)
if strategy.position_size > 0 and not partial_hit
if high >= trade_tp_partial
// FIX: Added License ID here for the modification alert
new_sl = strategy.position_avg_price
msg_mod = license_id + ",modify," + mt5_ticker + ",sl=" + str.tostring(new_sl) + ",magic=" + str.tostring(magic_runner)
alert(msg_mod, alert.freq_once_per_bar)
// B. BACKTEST SYNC
strategy.close("Long", qty=current_vol_partial, comment="Partial Hit", alert_message="IGNORE")
trade_sl := new_sl
partial_hit := true
if strategy.position_size < 0 and not partial_hit
if low <= trade_tp_partial
// FIX: Added License ID here for the modification alert
new_sl = strategy.position_avg_price
msg_mod = license_id + ",modify," + mt5_ticker + ",sl=" + str.tostring(new_sl) + ",magic=" + str.tostring(magic_runner)
alert(msg_mod, alert.freq_once_per_bar)
// B. BACKTEST SYNC
strategy.close("Short", qty=current_vol_partial, comment="Partial Hit", alert_message="IGNORE")
trade_sl := new_sl
partial_hit := true
// FINAL EXIT (Sync)
if strategy.position_size > 0
if low <= trade_sl or high >= trade_tp_final
strategy.close_all(comment="Exit Long", alert_message=msg_flat)
last_exit_bar := bar_index
if strategy.position_size < 0
if high >= trade_sl or low <= trade_tp_final
strategy.close_all(comment="Exit Short", alert_message=msg_flat)
last_exit_bar := bar_index
// --- 6. VISUALS ---
plot(ma_fast, "Fast MA", color=color.new(color.teal, 0), linewidth=2)
plot(ma_slow, "Slow MA", color=color.new(color.white, 0), linewidth=3)
plot(trade_sl, "Active SL", color=color.red, style=plot.style_linebr, linewidth=2)
plot(trade_tp_final, "Final TP", color=color.green, style=plot.style_linebr, linewidth=2)
// ZONES VISUALIZATION
fill(plot(upper_bb_1, display=display.none), plot(basis, display=display.none), color=color.new(color.green, 90), title="AAA Zone Long")
fill(plot(lower_bb_1, display=display.none), plot(basis, display=display.none), color=color.new(color.red, 90), title="AAA Zone Short")
fill(plot(upper_bb_1_5, display=display.none), plot(upper_bb_1, display=display.none), color=color.new(color.yellow, 90), title="B Zone Long")
fill(plot(lower_bb_1_5, display=display.none), plot(lower_bb_1, display=display.none), color=color.new(color.yellow, 90), title="B Zone Short")