Tick KK Park
- Experts
- 버전: 2.10
- 활성화: 5
NakedK_Trend EA 完整说明(中英双语) 1. 策略概述 / Strategy Overview 中文:
NakedK_Trend.mq5 是一个基于 裸K形态突破 的全自动交易机器人(Expert Advisor),运行于 MetaTrader 5 平台。其核心思想是:通过监测价格的连续波动方向(连续上涨或下跌次数达到阈值),识别可能的突破信号,并以前一根K线的高低点为参考放置突破挂单(Buy Stop / Sell Stop)。同时集成了 倍投(马丁格尔)恢复机制、尾随止盈、固定止损止盈、日盈亏限制、交易时段控制、日尾盘全平 等风控模块。挂单默认在 10秒后未成交自动取消,避免挂单堆积。该策略属于中高频趋势突破类,适合波动性较高的品种和周期。 English:
NakedK_Trend.mq5 is a fully automated trading robot (Expert Advisor) based on naked K-bar breakout patterns, running on the MetaTrader 5 platform. Its core idea: monitor the consecutive directional moves of price (consecutive up/down counts reaching a threshold), identify potential breakout signals, and place pending orders (Buy Stop / Sell Stop) using the previous bar's high/low as reference. It also integrates martingale recovery (doubling after loss), trailing stop profit, fixed stop loss / take profit, daily profit/loss limits, trading session control, end-of-day forced close, and other risk management modules. Pending orders are automatically cancelled after 10 seconds if not filled, preventing order pile-up. This strategy is a medium-to-high frequency trend breakout type, suitable for volatile instruments and timeframes. 2. 核心策略逻辑 / Core Strategy Logic 2.1 信号生成 / Signal Generation • 中文:
实时监控当前价格的连续上涨或下跌次数。当连续上涨次数 ≥ ConsecutiveThreshold(默认 3),并且当前卖价(Bid)高于前一根K线的最高价(prevHigh)时,产生买入突破信号,放置 Buy Stop 挂单;当连续下跌次数 ≥ ConsecutiveThreshold,并且当前卖价低于前一根K线的最低价(prevLow)时,产生卖出突破信号,放置 Sell Stop 挂单。 • English:
Real-time monitoring of consecutive price moves. When consecutive up moves ≥ ConsecutiveThreshold (default 3) and current Bid > previous bar's High (prevHigh), a buy breakout signal is generated, placing a Buy Stop order. When consecutive down moves ≥ ConsecutiveThreshold and current Bid < previous bar's Low (prevLow), a sell breakout signal is generated, placing a Sell Stop order. 2.2 挂单管理 / Pending Order Management • 中文:
挂单放置前会检查以下条件:当前K线是否已交易过(MaxTradesPerBar,默认每K线最多1次)、持仓数量是否已达上限(MaxPositions,默认1)、K线波动范围是否达到最小要求(MinBarPoints,默认30点)。挂单带有止损和止盈(固定点数),并在放置后开始计时(PendingCancelSec,默认10秒),超时则自动删除。 • English:
Before placing a pending order, the EA checks: whether this bar already has a trade (MaxTradesPerBar, default 1 per bar), whether the number of positions reached MaxPositions (default 1), and whether the bar range meets the minimum (MinBarPoints, default 30 points). Orders are placed with fixed stop loss and take profit, then a countdown starts (PendingCancelSec, default 10 seconds). If not filled within the timeout, the order is auto‑cancelled. 2.3 倍投(马丁格尔)恢复 / Martingale Recovery • 中文:
当一笔交易亏损平仓后,该方向的倍投层级(buyMartingaleLevel 或 sellMartingaleLevel)增加1(上限 MaxMartingaleLevel,默认10)。随后,同一个方向的下一次交易将以更大手数开仓(市价单,非挂单),手数 = FixedLot × (MartingaleMultiplier ^ level)。盈利平仓后重置层级为0。 • English:
When a trade closes with a loss, the martingale level for that direction (buyMartingaleLevel / sellMartingaleLevel) increments by 1 (capped at MaxMartingaleLevel, default 10). The next trade in the same direction opens with a larger lot size using a market order (not pending), calculated as FixedLot × (MartingaleMultiplier ^ level). The level resets to 0 after a profitable close. 2.4 时间控制 / Time Control • 中文:
可设定每日允许交易的时间段(StartTime~EndTime,默认 02:30~23:30)。非交易时段只管理现有持仓,不产生新信号。还可设定日尾盘全平时间(EndOfDayCloseTime,默认 23:50),到达该时间后自动平掉所有持仓并删除挂单。 • English:
Users can define a daily trading session (StartTime ~ EndTime, default 02:30 ~ 23:30). Outside the session, only existing positions are managed; no new signals are generated. There is also an end‑of‑day forced close time (EndOfDayCloseTime, default 23:50). When reached, all positions are closed and pending orders deleted. 2.5 日盈亏限制 / Daily Profit/Loss Limits • 中文:
每日初始余额记录在 dailyStartBalance 中。当日盈利百分比 ≥ DailyProfitLimit(默认300%)时,全平并停止当日交易。注意该参数实际为百分比值,300%意味着盈利300%才会触发,实际使用中需调整。亏损限制未单独实现,但可以通过净值变化间接控制(实际上代码仅实现了获利限制,亏损限制未主动检查,但建议用户自行调整)。 • English:
The EA records the initial daily balance. When the daily profit percentage ≥ DailyProfitLimit (default 300%), all positions are closed and trading stops for the day. (Note: this parameter is a percentage; 300% means a 300% profit before triggering. Loss limit is not explicitly coded.) 2.6 尾随止盈 / Trailing Stop Profit • 中文:
当持仓的浮动盈利 ≥ TrailingActivate(默认300点)时,启动尾随:将止损移动到当前价格减去(多头)或加上(空头)TrailingStep(默认100点)的位置,且只在移动方向有利时执行。 • English:
When floating profit ≥ TrailingActivate (default 300 points), trailing starts: stop loss is moved to current price minus (for long) or plus (for short) TrailingStep (default 100 points), and only when the move improves the stop level. 3. 参数说明 / Parameter Description 参数名称 默认值 说明(中文) Description (English) MagicNumber 12345 EA魔术码,用于识别订单 EA magic number to identify orders LotMode 0 手数模式:0=固定手数,1=余额比例 Lot mode: 0=fixed, 1=balance ratio FixedLot 0.01 固定手数(LotMode=0时有效) Fixed lot size (when LotMode=0) BaseBalancePerLot 1000.0 每1000资金交易0.01手(LotMode=1时) Trade 0.01 lot per 1000 balance UseMartingale true 启用倍投 Enable martingale MartingaleMultiplier 1.5 倍投乘数 Martingale multiplier MaxMartingaleLevel 10 最大倍投层级 Maximum martingale level ConsecutiveThreshold 3 连续波动次数达到此值触发信号 Fluctuation count to trigger signal MaxTradesPerBar 1 每K线最大交易次数 Maximum trades per bar MinBarPoints 30 最小K线范围(点),小于此值不开仓 Minimum bar range (points) SlippagePoints 30 允许滑点(点) Allowed slippage TrailingActivate 300 尾随激活所需盈利点数 Profit points to activate trailing TrailingStep 100 尾随步长(点) Trailing step (points) StopLossPoints 1000 固定止损点数 Fixed stop loss points UseFixedTP true 使用固定止盈 Use fixed take profit FixedTakeProfitPoints 1200 固定止盈点数 Fixed take profit points MaxPositions 1 最大同时持仓数 Maximum simultaneous positions StartTime "02:30" 交易开始时间 Trading start time EndTime "23:30" 交易结束时间 Trading end time EnableTimeControl true 启用时间段控制 Enable time control EndOfDayCloseTime "23:50" 日尾盘全平时间 End-of-day close time EnableEndOfDayClose true 启用日尾盘全平 Enable end-of-day close DailyProfitLimit 300.0 日获利限制(百分比) Daily profit limit (%) PendingCancelSec 10 挂单超时秒数 Pending order timeout (seconds) 4. 代码结构 / Code Structure 中文:
EA 由以下主要函数组成: • OnInit() – 初始化变量、指标、打印信息。 • OnTick() – 主循环,按顺序执行:超时检查 → 新日重置 → 日盈亏检查 → 尾盘全平 → 时间段检查 → 新K线处理 → 管理持仓 → 倍投恢复 → 信号生成 → 日盈亏再次检查。 • CheckPendingOrdersTimeout() – 遍历挂单队列,删除超时或已失效的挂单。 • ManageExistingPositions() – 对每个持仓执行尾随止盈并检查是否需要设置初始止损。 • ApplyTrailingStop() – 尾随逻辑。 • CheckMartingaleRecovery() – 当倍投恢复标志为真时,立即用市价单开仓(不经过挂单流程)。 • GenerateSignals() – 更新价格波动历史,检查连续波动次数和价格突破条件,调用 ExecuteOrder。 • ExecuteOrder(orderType, useMarket) – 统一执行函数:若 useMarket=true 则开市价单,否则开挂单。为修复 Invalid stops 错误,采用了两步法:先开单/挂单时不设止损止盈,开单成功后再用 PositionModify 或 OrderModify 设置止损止盈。 • UpdatePriceHistory() / CountConsecutiveDirections() – 维护20个周期的价格和方向历史。 • CloseAllPositions() / DeleteAllPendingOrders() – 全平全删。 • OnTradeTransaction() – 监听成交事件,更新倍投层级。 • 其他辅助函数如 NormalizeVolume, IsNewDay, ResetDailyBalance, CheckDailyProfit, IsInTimeRange, IsTimeEqualOrAfter 等。 English:
The EA consists of the following main functions: • OnInit() – Initialization. • OnTick() – Main loop performing checks in sequence: pending order timeout → new day reset → daily P/L check → end-of-day close → time session → new bar → manage positions → martingale recovery → signal generation → daily P/L recheck. • CheckPendingOrdersTimeout() – Iterates pending order queue, removes expired or invalid orders. • ManageExistingPositions() – Applies trailing stop and sets initial SL if missing. • ApplyTrailingStop() – Trailing logic. • CheckMartingaleRecovery() – Opens a market order immediately when recovery flag is set. • GenerateSignals() – Updates price history, checks consecutive moves and price versus previous bar extremes, then calls ExecuteOrder. • ExecuteOrder(orderType, useMarket) – Unified execution. Uses a two-step approach (open first without SL/TP, then modify) to avoid Invalid stops errors. • UpdatePriceHistory() / CountConsecutiveDirections() – Maintains 20‑period price and direction history. • CloseAllPositions() / DeleteAllPendingOrders() – Close all positions and delete all pending orders. • OnTradeTransaction() – Listens to completed deals to update martingale levels. • Helper functions: NormalizeVolume, IsNewDay, ResetDailyBalance, CheckDailyProfit, IsInTimeRange, IsTimeEqualOrAfter, etc. 5. 风险与注意事项 / Risk & Considerations 中文: • 倍投风险:马丁格尔策略在连续亏损时手数会呈指数增长(1.5^层级),可能导致巨大亏损。虽然 MaxMartingaleLevel 默认为10,但实际建议设置在3~5层以内,且初始手数要足够小。 • 挂单超时:10秒自动删除挂单可以防止堆积,但也可能导致信号被快速跳过(滑点或流动性不足时)。可适当增大 PendingCancelSec。 • 最小K线范围:MinBarPoints=30 会在盘整期间过滤掉大部分信号,避免反复虚假突破。 • 日获利限制:默认300%极高,实际可能永远达不到。建议根据自己的风控需求调整为2%~5%或使用账户货币金额限制(但代码未实现)。 • 经纪商限制:不同经纪商对止损止盈的最小距离有不同要求(SYMBOL_TRADE_STOPS_LEVEL)。代码已自动适配,但若仍出现 Invalid stops,需检查日志中的 StopsLevel 值并手动调整 minStopDist 计算。 • 不建议用于实盘:未经充分回测和优化的策略不建议直接用于真实账户。马丁格尔策略风险极高,尤其在小账户中可能快速爆仓。 English: • Martingale Risk: The lot size grows exponentially (1.5^level) after consecutive losses, which can lead to huge drawdown. Although MaxMartingaleLevel defaults to 10, it's strongly recommended to keep it within 3–5 levels and use a very small starting lot. • Pending Order Timeout: The 10‑second timeout prevents order piling but may cause missed signals during fast markets. Increase PendingCancelSec if needed. • Minimum Bar Range: MinBarPoints=30 filters out many signals in quiet markets, avoiding false breakouts. Adjust according to instrument volatility. • Daily Profit Limit: The default 300% is extremely high and may never be hit. For proper risk management, set a realistic percentage (e.g., 2%–5%) or modify code to use absolute currency values. • Broker Restrictions: Different brokers enforce different minimum SL/TP distances (SYMBOL_TRADE_STOPS_LEVEL). The EA automatically adapts; if Invalid stops still occurs, check the log output for StopsLevel and adjust the minStopDist calculation. • Not for Live Trading Without Testing: The strategy has not been fully optimized. Martingale strategies carry high risk and can quickly blow up a small account. Always backtest and forward test on a demo account first. 6. 总结 / Summary 中文:
NakedK_Trend.mq5 是一款功能较为全面的裸K突破EA,融合了挂单交易、倍投恢复、尾随止盈、时间控制、日盈亏限制和自动超时删除等特性。代码结构清晰,参数灵活。但马丁格尔的本质决定了其高风险特性,使用者必须深刻理解并做好风控。建议先在策略测试器中详细回测,并针对不同品种优化参数。 English:
NakedK_Trend.mq5 is a comprehensive naked‑K breakout EA combining pending orders, martingale recovery, trailing stops, time control, daily limits, and automatic order cancellation. The code is well‑structured with flexible parameters. However, the martingale nature implies high risk; users must fully understand and implement proper risk management. Thorough backtesting and parameter optimization for different instruments are strongly advised before any live deployment.
