JKEFAdvancedModel
- Experts
-
Shi Yuan Wang
Sviluppo indicatori personalizzati, Expert Advisor (EA), script e strumenti di trading per MetaTrader 4 e MetaTrader 5, nonché indicatori per TradingView (Pine Script).
Cosa posso fare per te: - Versione: 1.5
- Attivazioni: 5
JKEFAdvancedModel — Volatility-Adaptive Trend Breakout Trading System
Overview
JKEFAdvancedModel is a fully automated Expert Advisor for MetaTrader 5. On the selected timeframe it adapts to market volatility to follow the trend and trade breakouts.
The system evaluates the state of closed bars only, so signals are not revised by an unfinished bar. Once a direction is confirmed, the robot can enter with a market order or place a stop order at a defined distance from the current price and wait for breakout confirmation, trailing that pending order while it remains unfilled. Only one position is held per cycle. There is no position adding, no averaging down, and no grid or martingale logic.
Trading Logic
State detection. Price volatility is measured first: the stronger the volatility, the faster the moving average tracks price; the calmer the market, the smoother the average. The average then receives a momentum-weighted smoothing step to produce a trend baseline. A recent deviation percentile is calculated above and below the baseline. A close above the upper deviation percentile sets the long state, and a close below the lower deviation percentile sets the short state. States are updated on completed bars only. The signal timeframe is defined by InpTF and may differ from the chart timeframe.
First entry. After loading or after pressing Start, if the current symbol has no position and no pending order from this system, the robot reads the current signal direction. When a direction is defined and permitted, it opens a market position immediately with the initial stop loss attached. When the direction is neutral, it keeps waiting until a defined direction appears.
After a position is closed. When a position ends — by stop loss, by trailing stop, or manually — the robot records the close time, waits for the configured number of seconds, and then places a stop order in the direction of the current signal: a buy stop for long and a sell stop for short, at the configured distance from the current market price.
Pending order management. While a stop order is waiting, the robot keeps comparing it with the current signal:
- if the signal direction flips, the pending order is deleted and a new one is placed in the opposite direction;
- if the direction is excluded by the trade direction filter, the pending order is deleted and the wait timer restarts;
- if price moves in the favorable direction, the pending price follows it — a buy stop moves down and a sell stop moves up — so the order trails the market instead of staying fixed.
A filled pending order becomes an open position.
Position management. While a position is open, all unfilled pending orders are removed and the stop loss is maintained according to the trailing stop parameters: the trailing stop activates once profit reaches the trigger distance, keeps the configured distance from the current price, and moves only in the favorable direction.
Exit. No fixed take profit is used. Exits are produced by the initial stop loss, by the trailing stop, or by the Close All button on the panel.
Risk Management
- Fixed lot size with one position per cycle. No adding, no averaging, no hedging-style recovery.
- Every entry carries an initial stop loss at the configured distance in points; a value of zero means no stop loss is attached.
- Optional trailing stop with separate trigger and distance parameters; setting either to zero disables the feature.
- Free margin is calculated before each order request. If free margin is insufficient, no order is sent, an entry is written to the log, and a cooldown period starts to avoid repeated failed requests.
- The filling mode supported by the symbol is detected automatically, with fallback retries when needed. Market orders and pending orders are handled separately.
- Trading sessions and symbol trade modes are checked, so no requests are sent while the market is closed and a cooldown is applied to reduce unnecessary error messages.
- Lot size is normalized to the symbol minimum, maximum, and step to avoid server rejections caused by precision.
On-Chart Panel
The chart shows three buttons — Start, Stop, and Close All — plus a status line.
- Start enables automated trading. If there is no position, the first entry is attempted according to the current signal. Market-closed and insufficient-funds cooldowns are cleared.
- Stop stops new entries. Open positions are not affected and the trailing stop keeps running.
- Close All closes positions opened by this system on the current symbol, deletes pending orders, and stops automated trading.
The status line shows running or stopped state, signal timeframe, permitted direction, lot size, confirmation mode, initial stop loss, trailing trigger and distance, pending distance, wait time, and the current phase: market closed, insufficient funds, waiting for first entry, in position, pending order, waiting for pending order, or flat.
Button group placement (one of four chart corners), horizontal and vertical offset, button width and height, and font size are all configurable.
Recommended Operating Conditions
- Symbol: instruments with good liquidity and stable spreads, such as major currency pairs, liquid crosses, precious metals, and major index CFDs. Verify on a demo account first.
- Timeframe: the robot can be attached to any chart; the signal timeframe is set by InpTF, M5 by default.
- Account type: both netting and hedging accounts are supported.
- Account size: lot size and stop loss are user-defined, so derive the lot size from the maximum loss you are willing to take per trade. With the default 0.01 lot and a 500-point initial stop loss, an account balance of at least 500 USD or the equivalent is generally suggested; with low leverage or instruments with a large point value, use a larger balance or a smaller lot size. This is a capital-tolerance suggestion only and is not a performance expectation.
- Environment: use an account with stable execution and low latency, and keep the terminal online on a VPS.
Input Parameters
Trade Parameters
Parameter | Default | Description |
|---|---|---|
InpTF | PERIOD_M5 | Timeframe used for signal calculation; may differ from the chart timeframe |
InpTradeDirection | TRADE_DIR_BOTH | Permitted direction: both, long only, or short only |
InpLots | 0.01 | Fixed lot size, normalized to symbol rules |
InpStopLoss | 500 | Initial stop loss distance in points; 0 means no stop loss |
InpTrailTrigger | 200 | Profit required to activate the trailing stop, in points |
InpTrailDistance | 100 | Distance kept between the trailing stop and current price, in points |
InpWaitSeconds | 10 | Seconds to wait after a position is closed before the next pending order |
InpPendingDistance | 500 | Distance of the stop order from the current market price, in points |
InpMagic | 20267777 | Order identifier used to separate this system from other programs |
InpSlippage | 30 | Maximum accepted deviation for order sending, in points |
Filling Mode Settings
Parameter | Default | Description |
|---|---|---|
InpAutoDetectFilling | true | Detect the filling modes supported by the symbol automatically |
InpManualFilling | ORDER_FILLING_FOK | Filling mode used when automatic detection is disabled |
InpFillRetryMax | 4 | Maximum number of filling mode retries |
Startup Option
Parameter | Default | Description |
|---|---|---|
InpAutoStart | true | Start trading immediately after loading; shared with the panel Start button |
Interface
Parameter | Default | Description |
|---|---|---|
InpBtnCorner | BTN_CORNER_RL | Chart corner for the button group |
InpBtnX | 10 | Horizontal offset from the selected corner, in pixels |
InpBtnY | 10 | Vertical offset from the selected corner, in pixels |
InpBtnW | 70 | Button width in pixels |
InpBtnH | 25 | Button height in pixels |
InpText | 9 | Button font size |
Installation and Quick Start
- Install the product from the Market or the Navigator; it appears in the Experts\Market folder.
- Open a chart of the target symbol and attach the robot.
- Set lot size, initial stop loss, trailing stop, pending distance, and signal timeframe in the Inputs tab.
- Make sure AutoTrading is enabled in the terminal and that the robot name with a smiley icon appears in the top-right corner of the chart.
- Keep InpAutoStart set to true for an immediate start, or press Start on the panel.
- Press Stop to halt new entries, or Close All to close positions and delete pending orders.
Testing Recommendations
- Download complete history for the symbol and test with real or custom spreads in the Strategy Tester.
- Run the robot on a demo account first to confirm pending order behavior, trailing stop behavior, and log output.
- When running on several symbols in one account, use a separate chart per symbol and consider separate order identifiers to keep records clear.
- Before changing the lot size, estimate the maximum loss per trade as initial stop loss in points multiplied by point value multiplied by lot size.
Limitations and Notes
- The robot manages only positions and pending orders on the current chart symbol that carry its own order identifier. Manual positions and orders from other programs are not affected.
- No take profit target is used; how much profit is given back depends on the trailing stop parameters.
- There is no built-in news filter, session filter, spread filter, maximum holding time, or daily loss limit.
- The lot size is fixed; there is no automatic risk-percent sizing, so adjust it manually when the account size changes.
- The terminal must stay online. No requests are sent during disconnection, and the state after reconnection depends on the positions and orders that exist at that moment.
- Pending orders and stop loss modifications are involved, so actual fill prices depend on spread, slippage, and liquidity.
Risk Notice
Automated trading does not remove market risk. Results obtained on historical data do not represent future results, and demo account results may differ from live account results. This product does not guarantee any profit and is not investment advice. Set lot size and stop loss according to your own risk tolerance and test thoroughly before using a live account. Trading results obtained with this product remain the responsibility of the user.
Frequently Asked Questions
The robot did not open a trade right after starting. Is that expected?
Yes. If the signal direction is neutral at startup, the robot waits until a defined long or short state appears.
What happens to open positions after pressing Stop?
Stop only halts new entries. Open positions remain and the trailing stop continues to run.
Can it be used on several symbols at once?
Yes. Attach it to one chart per symbol. Separate order identifiers are recommended to keep records clearly separated.
A pending order has been waiting for a long time. What should I do?
The pending price follows the market when price moves in the favorable direction. If the signal direction flips or the direction is filtered out, the order is deleted and rescheduled according to the current rules.
Why does the log show an insufficient funds message?
Free margin is checked before each request. When it is insufficient, no order is sent, the event is logged, and a cooldown begins. Reduce the lot size or add funds.
