Skip to content

Free MT5 Expert Advisor

Pin Bar Reversal EA

MT5 Expert Advisor that trades pin bars printing at a 20-bar swing high or low, with the stop beyond the wick and a reward:risk target.

Price actionv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Stop-loss on every trade
Strategy
Buys after a bullish pin bar that makes the lowest low of the last 20 bars and sells after a bearish pin bar that makes the highest high of the last 20 bars. The stop goes beyond the wick.
Risk model
1% of balance per trade (configurable), stop-loss beyond the pin-bar wick on every order, one position at a time

What it does

A pin bar has a long wick and a small body, showing that price pushed one way during the bar and was rejected. Pin Bar Reversal EA only trades pin bars that form at a swing extreme, where a rejection is more meaningful than in the middle of a range.

How it works

For the last closed bar, with range = high − low and body = |close − open|:

  • Bullish pin: lower wick (lower of open/close − low) is at least 60% of the range, the body is at most 33% of the range, and the bar's low is the lowest low of the last 20 bars.
  • Bearish pin: upper wick (high − higher of open/close) is at least 60% of the range, the body is at most 33%, and the bar's high is the highest high of the last 20 bars.
  • Size filter: the bar's range must be at least 0.8 × ATR(14).
  • Entry: at market on the open of the next bar.
  • Stop-loss: low − 0.1 × ATR for buys, high + 0.1 × ATR for sells. Trades whose stop would exceed 3 × ATR are skipped.
  • Take-profit: 2 × the stop distance.

The candlestick patterns lesson covers pin bars and related shapes, and support and resistance explains why location matters.

How to use it

Higher timeframes give more reliable pin bars, because more trading activity stands behind each wick. H4 and D1 are a good starting point. Lowering the wick ratio to 0.5 increases trade count at the cost of weaker patterns. Some traders also restrict trading to their main session through the trading-hours inputs.

Settings

InputDefaultWhat it changes
Swing lookback20Location requirement
Min wick ratio0.60Strictness of the rejection
Max body ratio0.33Strictness of the small body
Min range (x ATR)0.8Ignores small bars
Stop buffer (x ATR)0.1Room beyond the wick
Max stop (x ATR)3.0Skips very wide setups
Reward:risk target2.0Take-profit, 0 disables it
Risk per trade / Fixed lots1.0% / 0Position sizing
Max spread / Trading hours30 / 7–20Filters
Break-even / Trailingon / offStop management

Limitations

A pin bar at a 20-bar extreme is still only one bar of evidence, and strong trends often print pin bars that fail. Long wicks mean wide stops and smaller position sizes. Pattern definitions differ between traders, so the EA may skip bars you would call pin bars, or take some you would not.

Before you run it live

Test it in the Strategy Tester on several symbols and timeframes and review the trades visually to check the pattern matches your idea of a pin bar. Then run it on a demo account with a small risk per trade. Past behavior does not guarantee future results.

Key inputs

Key inputs of Pin Bar Reversal EA
InputDefaultDescription
Pin bar must make the lowest low / highest high of N bars20Swing lookback that defines the location.
Rejection wick as a share of the bar range0.60Minimum length of the long wick.
Maximum body as a share of the bar range0.33Keeps the body small.
Minimum pin-bar range (x ATR)0.8Ignores small, insignificant bars.
Stop buffer beyond the wick (x ATR)0.1Room added beyond the wick.
Take-profit as a multiple of the stop (0 = none)2.0Reward-to-risk target.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors