Loading…

Heikin Ashi Trend EA

MQL4 has no built-in Heikin Ashi indicator, and the formula is recursive - each bar's Heikin Ashi open depends on the previous bar's Heikin Ashi open and close - so it cannot be read from a single indicator call. This EA rebuilds the full Heikin Ashi sequence from raw OHLC over a configurable lookback window every closed bar, seeding the oldest bar in the window from its own raw open and close. Recomputing from scratch rather than caching a running value bar to bar means a terminal restart, a history gap, or a changed lookback input can never leave the sequence out of sync with what the indicator would actually show - the cost is a short loop once per bar, which is negligible. Entries require the textbook definition of a strong Heikin Ashi trend bar: a bullish candle with no lower shadow, or a bearish candle with no upper shadow. Exits are deliberately held to a lower bar - any plain colour flip, shadow or not, closes the position. Getting out early costs little, but a merely coloured candle without the clean shadow is not treated as strong enough evidence to commit new capital. Notes and limitations - Heikin Ashi candles are smoothed and lag raw price; the shadow-free entry filter reduces false starts further, which means this system enters later than a raw-price trend follower by design. - Signals are evaluated once per closed bar, not on every tick. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Requires AutoTrading enabled and IsTradeAllowed() true; if trading is disabled the EA logs it and skips the entry.

Expert advisor · MT4 · v1.0 · Free

About Heikin Ashi Trend EA

Heikin Ashi Trend EA is an expert advisor (trading robot) for MetaTrader 4. It can size trades from your balance and risk percent. It has 10 settings, such as Ha lookback, Stop loss pips and Take profit pips. MQL source code included.

Files in the download: HeikinAshiEa.ex4, HeikinAshiEa.mq4, HeikinAshiEa.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Ha lookback100Bars rebuilt each tick to seed the recursive HA formula
Stop loss pips50Stop loss distance, in pips
Take profit pips0Take profit distance, in pips (0 = none, exit only on colour flip)
Use risk sizingfalseSize by percent risk instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a fallback
Magic number20260705Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Heiken Ashi · Trend · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria