
何千ものPine Scriptのコードを見てみると,この”Master Trading Bot”には本当に2つのブラシがある.著者はDCAを新たな高度に演じています.無意識の定額投資ではなく,技術指標に基づいたスマートな加仓システムです.初期ポジションは5%で,DCAが増加するたびに2.5%,最大100%を超えません.この漸進的な資金管理は,従来の定額投資よりも科学的です.
鍵となるのはDCAのトリガー条件である:価格は平均コスト価格を下回り,2%+ステップ×4%の動的下落に達しなければならない.最初のDCAは2%を下回り,2番目のDCAは6%を下回り,3番目のDCAは10%を下回る必要がある.この設計は,小さな波動で頻繁にポジションを上げることを避け,真の回落でのみ上昇させる.
戦略は3/7/18周期EMAを使用してトレンドの枠組みを構築し,20周期ブリン帯の判断価格位置,52/200/3のMACDパラメータ設定偏向中長期の信号,14周期RSIは超買い超売り判断に使用されます.この組み合わせは,傾向,動量,波動性の3つの次元をカバーし,単一の指標戦略よりも信頼性が高くなります.
購入条件は厳格である: 急速EMA>遅いEMA+MACD金叉+価格がブルインの中間軌道上+RSI<65。これらの4つの条件が同時に満たされれば,偽信号のほとんどをフィルタリングする. 販売条件は同様に厳格である:最低2%の利潤 +トレンドの転換 +MACDデッドフォークが必要です。この"利潤をるため売る”の設計は,無意味なストップ損失を回避する。
コードで100%のストップ・ロスは誇張的に聞こえるが,注釈ははっきりと”価格が0まで下がらなければトリガーできない”と言っている.これは,実際には,伝統的なストップ・ロスを閉鎖し,技術指標と利益目標のみでリスクを管理する.
真のリスクコントロールは:2%の価格下落シグナル+動的DCA減值+強制的利益退出である.戦略は500サイクル間の最高価格を追跡し,現在の価格の高点から2%以上下落すれば,売り出しシグナルを誘発する.これは固定ストップよりも柔軟であり,異なる市場環境に対応できる.
毎回購入する金額=現在の利率×DCAパーセント÷現在の価格,この固定金額ではなく,利率の比率による設計は,戦略が口座の成長とともにポジションを拡大できるようにする.最初の5%のポジションは,1回のリスクを制御し,漸進的な加仓は,本当の機会の前に十分な火力を持っていることを保証する.
最も巧妙なのは”just_sold”状態管理: 売り切れしたばかりの商品は,強烈な看板の信号が出ない限り,すぐに再購入しない.これは,波動的な市場での頻繁な取引を避け,手数料コストと感情的な操作のリスクを低減する.
この戦略は,中長期の上昇傾向中の回転買いに最適で,熊市や長期横断期において一般的である.MACDの52/200のパラメータ設定は,短線取引には適さないより,より大きなレベルの傾向判断に適することを決定している.
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)