Pin Bar EA
Three ratios of the bar's own high-low range decide whether it qualifies, not fixed pip counts - a pin bar is a shape, and a shape scales with the instrument and the timeframe rather than a fixed distance. The body must be small (InpMaxBodyRatio), the signal-side tail must be long (InpMinTailRatio), and the opposite tail must also be small (InpMaxOppositeTailRatio). That last check is the detail a naive pin bar detector usually skips: without it, a bar with two long tails and a tiny body - a genuine indecision bar, not a one-sided rejection - would qualify by accident and be traded as if it meant something directional. The stop is placed just beyond the tail's own extreme, plus InpStopBufferPips: a pin bar whose rejection point trades through again has been proven wrong on its own terms, and the position exits there rather than at an arbitrary fixed distance. Take profit is expressed as a multiple of that risk distance via InpRewardToRiskRatio. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the stop distance, using tick value and tick size rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - Signals are evaluated once per closed bar, not on every tick, and only against the immediately preceding bar - there is no multi-bar pattern or trend filter. - One position at a time, tracked by InpMagicNumber. On a netting account that means one merged position per symbol; the magic filter is effectively all-or-nothing per symbol rather than per individual order. An opposite signal closes the current position before opening the new one; it will not manage or interfere with trades opened manually or by another EA (or, on MQL5 netting, another magic number). - If the tail-based stop would land inside the broker's minimum stop distance, that signal is skipped rather than sending an invalid order. - A pin bar is a shape, not a guarantee - the same shape appears in both genuine reversals and mid-trend pauses that continue straight through it. - Requires AutoTrading enabled and trading permitted at the terminal, account and expert level; if trading is disabled the EA logs it and skips the entry.
Expert advisor · MT5 · v1.0 · Free
About Pin Bar EA
Pin Bar EA is an expert advisor (trading robot) for MetaTrader 5. It can size trades from your balance and risk percent. It has 12 settings, such as Max body ratio, Min tail ratio and Max opposite tail ratio. MQL source code included.
Files in the download: PinBarEa.ex5, PinBarEa.mq5, PinBarEa.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Max body ratio | 0.30 | Body size as a fraction of the bar's range - must be at or below this |
| Min tail ratio | 0.60 | Signal-side tail as a fraction of the bar's range - must be at or above this |
| Max opposite tail ratio | 0.20 | Opposite-side tail as a fraction of the bar's range - must be at or below this |
| Stop buffer pips | 3.0 | Extra distance beyond the tail extreme added to the stop, in pips |
| Reward to risk ratio | 2.0 | Take profit as a multiple of the stop distance (0 = no take profit) |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260612 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Candlestick Patterns · Buy/Sell Arrows · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code