Loading…

Pin Bar Context Dependency Study

A pin bar is usually taught as a standalone signal, but most traders who actually use them insist context matters - the same shape at a random midpoint of a range is treated very differently from one that forms at a swing level in the direction of the trend. This script checks that claim directly instead of leaving it as chart-reading folklore. Every bar in the loaded history is tested against an explicit shape filter: a long wick on one side (at least InpNoseRatio of the bar's range), a short wick on the other (at most InpOppWickRatio), and a small body (at most InpBodyRatio). Bars satisfying both directions at once are skipped as ambiguous rather than guessed at. Each qualifying pin bar is then scored on two independent conditions - trend alignment (an SMA slope check) and proximity to a prior swing extreme - and sorted into one of four buckets. Trend and level are kept separate rather than folded into a single confluence flag, because a pin bar with only one of the two present is a genuinely different setup from one with both, or neither; collapsing that distinction would hide exactly the comparison this study exists to make. Outcome for each bucket is a simple target-versus-stop race over a fixed lookahead, with stop checked before target when both could have been touched within the same bar, since intrabar order is not recoverable from OHLC data alone. Notes and limitations - This is a descriptive study, not a trading signal. A win rate difference between buckets on a small sample is not proof of an edge; check the reach (sample count) column before drawing conclusions. - The level check compares the pin's own high or low against the single most extreme prior swing point in the lookback window, not every minor swing in between - a market with several nearby levels only registers the outermost one. - Stop is checked before target within the same bar when both could plausibly have been hit, which understates win rate slightly rather than overstates it - the conservative direction for a study meant to be trusted. - Outcomes that hit neither target nor stop within InpLookaheadBars are reported separately as "no hit" and excluded from the win-rate percentage, which is computed only over decided outcomes. - Says nothing about spread or slippage cost - purely a study of where price went relative to the signal bar's close.

Script · MT4 · v1.0 · Free

About Pin Bar Context Dependency Study

Pin Bar Context Dependency Study is a script for MetaTrader 4 based on Moving Average. It can alert you with a pop-up, sound, email or push message and marks candlestick patterns. It has 17 settings, such as Symbol, Timeframe and Max bars. MQL source code included.

Files in the download: PinBarContextStudy.mq4, PinBarContextStudy.txt.

Settings

SettingDefaultWhat it does
SymbolSymbol to study, blank = this chart's symbol
TimeframePERIOD_H1Timeframe to study
Max bars3000Most recent bars to include
Nose ratio0.66Long wick must be at least this fraction of the bar range
Opp wick ratio0.25Opposite wick at most this fraction of the bar range
Body ratio0.35Body at most this fraction of the bar range
Min range pips5.0Ignore bars with a range smaller than this, in pips
Trend ma period50SMA period used to judge the prevailing trend
Trend slope bars10Bars back the SMA slope is measured over
Trend min slope pips2.0Minimum SMA move over that span to call a trend, in pips
Level lookback bars100Bars searched for a prior swing high/low
Level tolerance pips8.0Pin extreme within this many pips of that swing counts as "near a level"
Lookahead bars10Bars forward checked for target/stop
Target pips20.0Favourable move counted as a win
Stop pips10.0Adverse move counted as a loss
Save csvtrueWrite the bucket table to a CSV file
DelimiterDelimiterCommaCSV column separator

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Candlestick Patterns · Buy/Sell Arrows · Trend · Alerts · Moving Average · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria