Robot pelaburan tetap pintar

EMA MACD RSI BB
Tarikh penciptaan: 2025-10-23 16:23:41 Akhirnya diubah suai: 2025-10-23 16:23:41
Salin: 0 Bilangan klik: 198
2
fokus pada
329
Pengikut

Robot pelaburan tetap pintar Robot pelaburan tetap pintar

Ini bukan perancangan biasa, ini adalah perancangan robot yang boleh berfikir!

Anda tahu? Kebanyakan orang melakukan pelaburan tetap adalah “beli-beli tanpa otak”, tetapi strategi ini seperti memberi anda pembantu pelaburan yang sangat bijak! Ia akan menyesuaikan jumlah setiap pembelian mengikut keadaan pasaran, dari 5% awal secara beransur-ansur hingga 100% maksimum. Seperti anda pergi ke pasar sayur-sayuran, membeli lebih banyak apabila ia murah, membeli sedikit apabila ia mahal, mudah kasar tetapi sangat berkesan!

Empat Indeks Teknologi Berpadu, Trend Pasaran Terlihat

Strategi ini menggunakan gabungan empat penunjuk teknikal:

  • EMA berkuranganSeperti carta jantung pasaran, menunjukkan arah trend
  • MACD“Meter hujan” untuk menentukan masa untuk membeli dan menjual
  • RSI“Termometer” yang terlalu banyak dibeli untuk mengelakkan kenaikan harga
  • Talian Brin‘Zona selamat’ untuk turun naik harga, menilai sokongan terhadap rintangan

“Ketika empat indikator ini digabungkan, ia seolah-olah membentuk sebuah ‘Aliansi Avengers’, masing-masing mempunyai tugas yang berbeza tetapi bekerja secara diam-diam!

Logik Pengecutan Intelektif Yang Berjaya

Ini adalah strategi yang lebih bijak, kerana masalah terbesar dalam pelaburan biasa adalah tidak dapat mengawal kedudukan:

  • Pertama kali membeli dengan 5% untuk menguji air
  • Masing-masing kenaikan 2.5%
  • Lebih banyak harga jatuh, lebih banyak jarak antara kenaikan harga (dua peratus, enam peratus, 10 peratus…)
  • Maksimum 100 peratus daripada jumlah dana yang disumbangkan dalam satu masa

Seperti menaik taraf permainan, semakin banyak yang anda masukkan ke dalam permainan, semakin besar pula kosnya, tetapi risiko yang anda ambil adalah sangat besar!

Stop loss yang bijak, profit yang cepat, dan stop loss yang bijak

Ini adalah strategi untuk menjual logik supermanusia:

  • Minimum 2% keuntungan untuk mempertimbangkan penjualan“Saya tidak tahu apa-apa, saya tidak tahu apa-apa, saya tidak tahu apa-apa, saya tidak tahu apa-apa, saya tidak tahu apa-apa”, kata beliau.
  • Permulaan trend lemah dan berakhir tepat pada masanya“Saya tidak tahu apa-apa, tetapi saya tahu bahawa saya tidak boleh berputus asa.
  • Harga jatuh 2% dan menyebabkan jualanPerlindungan daripada keuntungan:
  • Garis Hentikan Kerosakan yang boleh ditetapkanWalaupun 100% secara lalai, anda boleh mengubahnya mengikut tahap toleransi risiko.

Secara ringkasnya, strategi ini adalah “tidak pernah lemah ketika mendapat wang, tidak pernah bergaduh ketika berlari”!

||

🤖 This Isn’t Ordinary DCA - It’s a Thinking DCA Robot!

You know what? Most people do dollar-cost averaging like mindless “buy-buy-buy” machines, but this strategy is like having a super-smart investment assistant! It adjusts the purchase amount based on market conditions, starting from 5% and gradually increasing up to 100%. It’s like shopping at a farmers market - buy more when it’s cheap, buy less when it’s expensive. Simple, brutal, but incredibly effective!

📊 Four Technical Indicators Working as a Team

Key point! This strategy uses a combination of four technical indicators:

  • Fast/Slow EMA: Like the market’s “heartbeat monitor,” showing trend direction
  • MACD: The market momentum “barometer” for timing entries and exits
  • RSI: The overbought/oversold “thermometer” to avoid chasing highs and selling lows
  • Bollinger Bands: Price volatility “safety zones” for support and resistance

These four indicators work together like assembling the “Avengers” - each has their role but they coordinate perfectly!

💡 Smart Pyramiding Logic: Buy More as It Drops

Pitfall alert! The biggest problem with regular DCA is poor position sizing control. This strategy is much smarter:

  • Initial purchase uses 5% of capital to test the waters
  • Each additional purchase increases by 2.5%
  • The more price drops, the larger the spacing between purchases (2%, 6%, 10%…)
  • Maximum single investment never exceeds 100% of total capital

It’s like leveling up in a video game - the investment gets bigger as you progress, but risk is tightly controlled!

🎯 Smart Take-Profit and Stop-Loss: Let Profits Run, Cut Losses Short

This strategy’s exit logic is super user-friendly:

  • Minimum 2% profit before considering sale: No more “working hard for nothing”
  • Exit when trend weakens: Take profits while you can, secure the gains
  • 2% price drop triggers sell signal: Protect profits from giving back
  • Configurable stop-loss: Though default is 100% (basically never triggered), you can adjust based on risk tolerance

Simply put, this strategy is “ruthless when making money, decisive when it’s time to run”!

[/trans]

Kod sumber strategi
// 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, "DCA Increment per 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 Percentage 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 is effectively no stop loss, as the price would have to go to zero.")
drop_percent_signal = input.float(2.0, "Price Drop 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, "Bollinger Bands Std Dev", 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 recent highest price (equivalent to `cummax` in Python)
highest_price = ta.highest(high, 500) // 500-bar lookback as an approximation of all-time 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]

// Strategy state variables
var bool just_sold = false
var int dca_step = 0

// Determine the capital percentage for the next buy
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

// Long Entry Condition
// Initial Buy (no open position)
long_signal_initial = strategy.position_size == 0 and is_bullish and macd_line > signal_line and rsi < 65

// DCA (if already in position)
price_drop_from_avg = ((avg_buy_price - close) / avg_buy_price) * 100
dca_required_drop = 2.0 + (dca_step * 4.0) // Logic equivalent to DCA_PRICE_DROP_START and INCREMENT
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 rebuying after selling unless strong bullish condition
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 (e.g., 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) // "qty" represents a cash-based position
    dca_step := dca_step + 1
        
if (short_signal)
    strategy.close_all(comment="Sell")
    dca_step := 0 // Reset DCA counter upon selling

// —————— CHART 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 if position is open
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 Target (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)