Babi Ngepet - MetaTrader 5 Expert | Martin EA Download - MT4/MT5 Resources


EA provides several external parameters that users can modify to control its behavior:
Set the EA's MagicNumber, margin mode and bias. It resets the Martingale state variables (s_currentLot, s_totalTradesInSeries, etc.) to their initial values, ready to start over.
A simple cleanup function that prints a message when the EA is stopped or deleted.
These functions check the current day and date based on user-defined inputs (AllowMonday to AllowFriday and ForbiddenDates) to determine whether the transaction is allowed.
This function handles opening a new market position (buy or sell).
It validates and normalizes lot sizes based on the broker's minimum, maximum, and step sizes.
It checks for sufficient available margin using CheckMargin().
It executes trades without fixed take profit or stop loss (tp_calculated is 0 ).
It updates the global Martingale state variables: s_currentLot, s_lastOpenPrice, s_seriesType and s_totalTradesInSeries.
Iterate through all currently open positions and close this EA (matching MagicNumber).
This function places a buy limit or sell limit order:
It verifies the lot size and checks whether there is enough margin.
It validates the entry price based on the broker's minimum distance (SYMBOL_TRADE_STOPS_LEVEL).
It calculates fixed take profit (tp) based on the take profit input.
It sends transaction requests. Notes: The UpdateHighLowAndOrders function call is used to place the initial buy limit and sell limit orders.
This is the initial entry mechanism when there are no vacancies:
It backtracks FindHighLowBackBars to find the high and low .
It calculates priceSellLimit (highest price + 1 tick) and price purchase limit (minimum low - 1 tick).
It checks whether the buy limit and sell limit orders for the EA's MagicNumber already exist.
It places an initial sell limit order just above the recent high and a buy limit order just below the recent low, using InitialLot for each order.
The core of EA execution logic:
Time check: prevent redundant calculations on the same quote.
Filter check: If trading is not allowed by date/date, all pending orders will be deleted.
Profit target check (series exit): if eaHasOpenPositions is true and totalFloatingProfit is ≥ SecureProfitMartingaleTarget, which calls CloseAllPositions() and resets all Martingale state variables to start a new series.
Initial order placement: If !eaHasOpenPositions AND trading is allowed, reset the Martingale state and check if a new bar is formed.
If a new bar is formed, it checks if barsCount is ≥ResetAfterBars . If so, it will delete the pending order and call UpdateHighLowAndOrders() to place a new initial order. If not, it just calls UpdateHighLowAndOrders().
Martingale step logic: If eaHasOpenPositions is true and s_totalTradesInSeries is $< MaxTradesInSeries`:
It checks if totalFloatingProfit is negative and the price has moved at least DistanceMartiningalePips relative to the last open trade.
If both conditions are met, it will calculate nextLot by multiplying s_currentLot by LotMultiplier.
It determines the orderToOpen direction (same direction as series or opposite, based on ReverseMartiningale).
It calls OpenTradeLogic() to open a new, multiplied position, continuing the Martingale series.
The “Babi Ngepet” EA implements the risky but potentially high-reward Martingale strategy combined with a breakout/range reversal initial entry:
Initial Inputs: The EA places an initial buy limit (below the recent low) and sell limit (above the recent high). This suggests that the original hypothesis was range behavior - buying when prices hit lows and selling when prices hit highs.
Trade Management: If one of the initial trades is triggered and the position experiences a total loss (negative floating profit), and the price continues to move a specified distance relative to the open position, the EA opens a new position with the same larger lot size (martingale) in the direction.
Exit strategy: The series of trades continues to increase in lot size until the total floating profit of all trades in the series reaches the SecureProfitMartiningaleTarget, at which point all positions are closed and the EA is reset to create a new series.
Warning: The Martingale strategy is known for high drawdowns and high risk of capital losses, since the lot size increases after every losing move.
Attachment download
📎 BabiNgepet_07.mq5 (49.42 KB)
Source: MQL5 #64444
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •