Trading robot · MT5

Ktai XAU DCA

by tiennguyen3000

This MetaTrader 5 Expert Advisor trades gold using an ATR-adaptive grid system combined with monthly price bands.

High risk

GitHub stars1
Forks0
Last update9 days ago25 Sep 2026
LicenceNone stated

Overview

Ktai XAU DCA segments account equity into a primary trading budget and a reserve fund, placing up to twelve levels of DCA orders. Grid spacing relies on ATR, while position sizing uses a quadratic progression budget mapped to broker margin requirements. The system exits positions collectively via a basket take profit, which can target either an ATR-based price distance or a percentage of trading capital. Risk management is handled through pre-trade margin checks, a maximum equity drawdown filter, and an optional basket stop loss.

Details

Author

tiennguyen3000 on GitHub

Type

Trading robot

Platform

MetaTrader 5 (MQL5)

Strategy

Grid, Mean reversion

Markets

Gold

Timeframes

M15-H1

Risk Profile

  • Opens a grid of orders: exposure builds up in a trend
  • Trades without a fixed stop loss

Input Parameters

Read from XAU_DCA_EA.mq5. Defaults are the author's; change them in the EA's Inputs tab.

NameTypeDefaultDescription
InpSymbolstringXAUUSDSymbol (Exness Standard: XAUUSDm)
CycleTFENUM_TIMEFRAMESPERIOD_H4Khung xac dinh chu ky
ATR_TFENUM_TIMEFRAMESPERIOD_H4Khung tinh ATR
ATR_Periodint14Chu ky ATR
DCA_Levelsint12So muc DCA
DCA_Capital_Percentdouble70.0% Equity cho DCA (production: <100)
Reserve_Percentdouble30.0% Equity du tru (production: >0)
ATR_Multiplierdouble0.75Buoc luoi = ATR x he so nay
Basket_TP_ATRdouble0.50TP ro = ATR x he so nay
Max_Equity_Drawdowndouble40.0% DD Equity toi da (dung DCA moi) - 40 de nuoi ro sau, chot lai theo thang
Min_Margin_Leveldouble300.0% Margin Level du kien toi thieu
MagicNumberulong26092601Magic number
Show all 40 inputs
NameTypeDefaultDescription
InpCycleModeENUM_CYCLE_MODECYCLE_MONTH_AUTONguon band: AUTO thang / MANUAL / CSV
InpMonthCountint1So thang DA DONG lay trung binh + bien do
InpBandWidthFracdouble0.50Be rong moi ben = frac x bien do thang TB
InpManualCenterdouble0.0MANUAL: gia trung binh thang (0 = tu suy)
InpManualLowdouble0.0MANUAL: Cycle Low
InpManualHighdouble0.0MANUAL: Cycle High
InpCycleCsvFilestringKTAI_XAU_DCA_cycles.csvCSV: month,anchor,low,high
InpAnchorModeENUM_ANCHOR_MODEANCHOR_BAND_CENTERNeo luoi: trung binh thang / gia / mep tren
InpInvalidateBelowLowbooltrueGia < Cycle Low -> cycle INVALID, dung DCA moi
InpRebuildOnBreakHighbooltrueGia pha Cycle High -> ghi nhan, tinh lai khi cho phep
InpUseClosedBarsOnlybooltrueChi dung nen DA DONG (khong look-ahead)
InpCooldownBarsint6So nen CycleTF cho (che do STRUCT_H4)
InpCooldownDaysint1So NGAY cho (che do band thang)
InpCycleLookbackint60(STRUCT_H4) so nen CycleTF lay High/Low
InpRenormalizeValidLevelsboolfalseChia lai quyen so chi tren cac muc hop le
InpSizingModeENUM_SIZING_MODESIZING_MARGINQuy ngan sach muc -> lot
InpExposureFractiondouble1.0He so dung ngan sach (mode EXPOSURE/RISK)
InpAllowBelowMinLotboolfalselot < min lot -> dung min lot (CHI de thu nghiem)
InpMaxPositionsint12So vi the BUY toi da cua EA
InpMaxFillsPerTickint1So muc DCA toi da khop trong 1 tick (chan dump khi gap)
InpUsePriceTPbooltrueTP theo gia: avgEntry + ATR x Basket_TP_ATR
InpMinTPDistancedouble0.0Khoang TP toi thieu (USD, 0 = khong ap)
InpMinTP_SpreadMultdouble3.0Hoac TP toi thieu = spread x he so nay
InpUseNetProfitTPbooltrueTP theo NET PROFIT (Profit+Swap+Commission)
Basket_TP_Percentdouble1.0% DCA capital lam muc tieu net profit
MaxMarginPercentdouble25.0Ky quy du kien toi da (% Equity)
MinFreeMarginPercentdouble30.0Free margin sau lenh toi thieu (% Equity)
InpBasketSL_Percentdouble0.0SL ro (% DCA capital, 0 = TAT)

How to Install It

  1. 1Download the sourceUse "Download source (.zip)" above, or clone tiennguyen3000/dca-cau-vang from GitHub, and unzip it.
  2. 2Open the data folderIn MetaTrader choose File, then Open Data Folder, and go to MQL5/Experts.
  3. 3Copy the filesCopy the .mq5 file into Experts, and any .mqh files into the Include folder the code expects.
  4. 4Compile in MetaEditorOpen the file in MetaEditor and press Compile. Fix any missing includes the compiler reports.
  5. 5Test before you tradeRun it in the Strategy Tester, then attach it to a demo chart and allow algorithmic trading.
Third-party code. ForexR did not write, test or endorse this EA, and the summary above was generated automatically from its README and code. ForexR lists only repositories with readable source code and never hosts files. Read the code, backtest it and use a demo account first; automated trading can lose money quickly.

Similar Expert Advisors

GridMaster Pro

by sajidmahamud835
128 stars

An automated MetaTrader 5 expert advisor that executes a bi-directional grid trading strategy. It uses the Average True Range (ATR) indicator to dynamically calculate grid spacing, allowing the system to adapt to current market volatility. The robot supports neutral, bullish, and bearish modes. It includes risk managem

MT5 Trading robot GridMean reversion High risk
Updated 6 months ago MIT GitHub repository of GridMaster Pro

RSI Martingale EA

by peefpee
10 stars

This Expert Advisor for MetaTrader 5 implements a martingale trading strategy triggered by the Relative Strength Index (RSI). It opens an initial position when RSI reaches overbought or oversold thresholds. If price continues to move against the initial trade, the EA layers additional orders at set point intervals, mul

MT5 Trading robot MartingaleMean reversionGrid High risk
8 stars

High Frequency Grid EA is an automated trading robot for MetaTrader 5 that implements a mean-reversion strategy through a grid of pending orders. It places buy and sell stop orders at calculated distances, using dynamic spread monitoring to ensure execution only during favorable conditions. The EA includes a trailing s

MT5 Trading robot GridMean reversionScalping High risk
7 stars

This MetaTrader 5 expert advisor executes a mean reversion strategy based on price deviation from a Simple Moving Average. It enters short positions when prices rise above the average and long positions when prices fall below. The algorithm utilizes an aggressive grid-based recovery system where both the entry distance

MT5 Trading robot Mean reversionMartingaleGrid High risk
4 stars

This high-frequency scalping robot for MetaTrader 5 is specifically designed for the gold market. It determines entry points using a combination of EMA trend filters, ADX trend strength, and dynamic RSI levels. To recover from losing positions, the EA utilizes an aggressive martingale grid system with a customizable lo

MT5 Trading robot ScalpingMartingaleGrid High risk
3 stars

This expert advisor facilitates arbitrage trading between futures and spot instruments, primarily targeting gold and stock indices. Available for MetaTrader 4 and 5, it monitors the price difference between two related symbols against a moving average to identify trade opportunities. The logic includes a noise-filterin

MT4MT5 Trading robot ArbitrageMean reversionGrid High risk
Updated 3 years ago None stated GitHub repository of Gold Futures Spot Arbitrage

More trading robots

Need a Broker for MT5?

Compare regulated brokers that support MetaTrader, with spreads, minimum deposits and leverage side by side.

Compare brokers