Loading…

Target Feasibility Solver

Picking a "2R" target or the next round number is popular because it is easy to compute, not because it is likely to be reached. This header does not replace that choice with a prediction - it reports the empirical fraction of historical forward windows whose maximum favourable excursion reached at least the candidate's distance, so a trader can see a 2R target was only reached 18% of the time on this instrument's recent history before committing to it, rather than finding out afterwards. RMultipleTargetPrice projects a fixed multiple of the entry-to-stop distance, the most common method. StructureTargetPrice searches a lookback window for the nearest swing high (buy) or swing low (sell) strictly beyond entry, returning false rather than guessing when no such level exists. RangeQuantileTargetPrice takes a quantile of recent per-bar ranges and scales it by a caller-chosen bar count, representing "typical movement over that many bars" rather than one single bar's range, which is usually far too small to be a useful target distance on its own. BuildForwardMfeSamples turns an OHLC history into a set of forward N-bar maximum-favourable-excursion distances - how far price actually moved in the trade's favour within that horizon, at every historical window start. EstimateReachProbability then reports what fraction of those historical windows reached at least a given distance, and ScoreTargetAgainstHistory attaches that figure to any of the three candidate types uniformly, so all three can be compared on the same footing. Reach probability is a plain historical frequency over whatever sample the caller supplies. It says nothing about the future and is only as representative as the sample - a caller comparing methods should build the MFE sample from the same instrument and a reasonably long, representative window, and re-run periodically as the reference sample updates. Self-contained: no order, position or account calls. Every function operates on plain OHLC arrays the caller supplies. Notes and limitations - BuildForwardMfeSamples and the other array-based functions assume the caller's arrays are in a consistent oldest-to-newest or newest-to-oldest order throughout one call; mixing orders between arguments in the same call will silently misalign the calculation. - reachProbability of -1.0 means "not scored" (no MFE sample supplied), not "zero percent" - check for the negative value explicitly. - StructureTargetPrice returns false when no qualifying swing exists within the lookback window; it never falls back to an arbitrary distance. - Reach probability is descriptive of past behaviour only. It is not a forecast and should be re-derived from a fresh, representative sample rather than reused indefinitely. - No thread or state concerns: every function is pure and operates only on the arrays passed in.

Script · MT4 · v1.0 · Free

About Target Feasibility Solver

Target Feasibility Solver is a script for MetaTrader 4. MQL source code included.

Files in the download: TargetFeasibilitySolver.mqh, TargetFeasibilitySolver.txt, TargetFeasibilitySolverDemo.mq4.

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: MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria