Lean Trade Panel
- Utilità
-
Jorge Eliecer Valencia Ferreira
🤖 Quantitative Developer & Algorithmic Trading Specialist | MQL5 & Python
Welcome to my official MQL5 profile. I am a Quantitative Developer and Algorithmic Trader focused on creating high-quality, institutionally robust Expert Advisors with strict risk management. - Versione: 1.0
- Attivazioni: 10
Lean Trade Panel is a manual trading panel for the chart. You choose how much to risk, set the stop loss, and press Buy or Sell. The panel works out the lot size from the real value per point of the symbol, sends the order with the stop loss and take profit attached on the server, and shows the lot, the money at risk and the R:R before you click.
It is for traders who enter by hand and for prop firm traders who need a daily loss cut-off, a spread filter and a cap on open positions. It has no entry logic and generates no signals. It never opens a trade on its own on a real or demo account. The one exception is the Strategy Tester demo described below.
Reviews of other trade panels often mention the same two problems: the panel is slow and heavy on the terminal, and the lot is wrong or stays at the minimum. This panel is built around those two points.
Light on the terminal
- OnTick only sets a flag. The work is done by a 500 ms timer.
- The panel updates only the texts that changed. If nothing changed, nothing is redrawn.
- Position management and the daily loss check run once per second.
- Buttons react at once when you click them.
Lot size
- Risk modes: % of equity, % of balance, fixed money amount, or fixed lot. You change the mode with a button on the panel and edit the value in the box next to it.
- The loss per lot is taken from the terminal's own profit calculation between entry and stop loss, so the lot follows the real value per point of the symbol (forex, metals, indices, crypto).
- The lot is rounded to the symbol's step, minimum and maximum, and kept inside the symbol's volume limit, counting pending orders.
- If the minimum lot would risk more than you asked for, the panel does not trade and tells you so, with both amounts. You can allow the minimum lot anyway with one input. It is off by default.
- A hard cap blocks any trade whose risk is above a % of equity (5 by default).
- The margin is checked against free margin before sending, and the stop distance is checked against the broker's stops level.
Stop loss and take profit
- Without lines: the stop is a number of points (300 by default) or an ATR multiple. The take profit is an R:R multiple of the stop (2.0 by default, 0 means no take profit).
- With lines: press Lines and three draggable lines appear: Entry, SL and TP. Each time you move one, the panel recalculates lot, risk in money, reward and R:R, and shows them in the panel and in labels next to the lines. The direction comes from the lines: a stop below Entry is a buy.
- With lines, if Entry is close to the price the order goes at market. If Entry is away from the price, the panel sends a pending order, limit or stop as needed.
- SL and TP are always sent with the order, never added later.
Position management
Buttons: Break-even, Partial, Close all, Close profit, Close loss, Delete pendings. The partial percentage is editable (50 by default). A filter button chooses what they act on: all positions of the chart symbol, only positions opened by the panel, or a given magic number.
Optional automatic management, all off by default: break-even at a chosen R multiple, partial close at a chosen R multiple, and a trailing stop by fixed points or by ATR. The trailing stop only moves the stop in your favor, with a minimum step. The panel never loosens a stop and does not send a modification when the stop is already at that value.
Prop firm protection
- Daily loss limit (3% by default): measured as equity against the balance at the start of the server day, so floating losses count. When it is reached, the panel closes the positions covered by the filter, deletes pending orders, and blocks panel orders until the next server day. Deposits and withdrawals during the day adjust the base.
- Maximum spread to enter, in points (off by default).
- Maximum open positions plus pending orders of the panel (5 by default).
- The day base, the lock and your panel settings are saved in terminal global variables, so a restart does not reset the day.
How to use it
- Attach it to a chart and allow algorithmic trading.
- Pick the risk mode and the value, then the stop (points or ATR) and the R:R. Or press Lines and drag Entry, SL and TP.
- Read the lot, risk and R:R shown on the panel and on the Buy and Sell buttons.
- Press Buy or Sell. Use the other buttons to manage the position. The panel can be minimized with the "_" button and dragged by selecting its title bar.
Optional: hotkeys B and S, and a confirmation window before each order (never shown in the tester).
Inputs
Risk per trade
- InpRiskMode (default % of equity): starting risk mode. Editable in the panel.
- InpRiskPct (default 1.0): risk as % of equity or balance.
- InpRiskMoney (default 10.0): risk in account currency, for the fixed money mode.
- InpFixedLot (default 0.01): lot for the fixed lot mode.
- InpMaxRiskPct (default 5.0): hard cap, blocks trades risking more than this % of equity. 0 = off.
- InpAllowMinLotOverRisk (default false): allow the minimum lot even if it risks more than requested.
Stop loss and take profit (when no lines)
- InpSlPoints (default 300): stop distance in points.
- InpTpRR (default 2.0): take profit as R:R multiple. 0 = no take profit.
- InpUseAtrSl (default false): use ATR for the stop distance.
- InpAtrPeriod (default 14) and InpAtrMult (default 1.5).
Orders
- InpMagic (default 26112901): magic number of panel orders.
- InpSlippage (default 30): maximum slippage in points.
- InpConfirm (default false): ask for confirmation before sending.
- InpHotkeys (default false): B = buy, S = sell.
- InpComment (default LeanTradePanel): order comment.
Position management
- InpFilter (default all positions of this symbol): what the buttons act on.
- InpFilterMagic (default 0): magic used by the magic filter.
- InpBeOffsetPts (default 10): break-even offset in points.
- InpPartialPct (default 50.0): partial close, % of volume.
Automatic management (all off by default)
- InpAutoBE (false) and InpAutoBE_R (1.0).
- InpAutoPartial (false) and InpAutoPartial_R (1.0).
- InpTrailMode (off): off, fixed points, or ATR multiple.
- InpTrailPts (300), InpTrailAtrMult (2.0), InpTrailStepPts (10).
Prop firm protection
- InpDailyLossPct (default 3.0): daily loss limit, % of day-start balance. 0 = off.
- InpMaxSpreadPts (default 0): maximum spread to enter, in points. 0 = no filter.
- InpMaxPositions (default 5): maximum open positions plus pending orders of the panel.
Panel
- InpPanelX (default 10), InpPanelY (default 20), InpFontSize (default 9), InpStartMin (default false).
Strategy Tester
- InpTesterDemo (default true): demo trades in the Strategy Tester only.
Checks before sending an order
The panel does not send the order, and writes the reason in the panel, when: the daily lock is on, algorithmic trading is not allowed, the symbol is closed to new trades or does not allow that direction, the market session is closed, the spread is above your maximum, the panel position limit is reached, the stop or take profit is too close to the price, the lot cannot be calculated, the risk is above the cap, there is not enough margin, or the account's pending order limit is reached. Each message is written once to the Experts log, with the prefix LTP, so it does not fill the log.
If the broker rejects the filling mode, the panel tries the other modes the symbol allows. Closes are retried on requote and price change.
Limitations
- The panel works on the symbol of the chart where it is attached. Its buttons and the daily lock close only the positions and pending orders of that symbol that the filter covers. For other symbols, attach another panel.
- The daily loss limit measures the whole account (equity against the day-start balance), but it closes only what the filter covers on the chart symbol.
- The daily reset happens at the start of the server day (00:00 server time). It is not an input. Check that this matches the rule of your broker or prop firm. The panel does not know the rules of any firm.
- The lock blocks the panel and closes what the filter covers. It cannot stop another EA or a manual order from being sent from outside the panel. It closes it after it exists.
- Closing is at market, so slippage applies. The final loss can be larger than the limit, especially with fast markets, gaps or wide spreads.
- It needs the terminal running and connected, with algorithmic trading enabled. If the terminal is off, it does nothing.
- If you attach it in the middle of the day, the day-start balance is rebuilt from the account history.
- Settings and the day state are saved per account. Panels on several charts of the same account share them.
- Changing the symbol or timeframe of the chart restarts the EA and turns the lines off.
- To move the panel, click its title bar once to select it, then drag. MT5 reports the move only when you release.
- It does not choose entries and does not tell you when to trade.
Strategy Tester demo
In the Strategy Tester, if InpTesterDemo is on, the panel opens a few trades by itself, only to show how it works, through the same code path as the Buy and Sell buttons (lot by risk, ATR stop, take profit on the server). It opens up to 3 trades per day, in time windows starting at 02:00, 08:00 and 14:00 server time, alternating buy and sell, with at most 2 open at the same time. On those trades it runs a partial close and break-even once the profit reaches 0.4 R, and it respects the daily loss limit. The panel is drawn in visual mode only and no state is saved between runs. This demo never runs outside the tester. On a real or demo account chart the panel opens nothing without your click.
Notes
- Works on any symbol and any timeframe the broker offers for trading.
- It is not a strategy and says nothing about future results.
Risk warning: trading leveraged products carries a high risk of loss. This panel sizes the lot from the risk you choose, but it does not guarantee that a loss will stay at that amount: slippage, gaps and rejected orders can make it larger. It is a trade management tool, not trading advice, and it does not generate signals.
