Loading…

Setup Scoring Framework

Most discretionary-turned-mechanical scoring systems assign factor weights once, by feel, and never revisit them - "trend alignment worth 3 points, volatility worth 2, session worth 1" typed in once and left alone regardless of whether trend alignment ever actually predicted anything on this instrument. CSetupScorer instead lets a strategy register named factors, score candidate setups as a weighted average, and separately record what actually happened to past setups so the weights can be recalibrated against real evidence. Calibration is a plain per-factor Pearson correlation between that factor's recorded value across history and the recorded outcome (any signed number the caller defines consistently, such as a normalised R-multiple or a +1/-1 win/loss code). A factor that tracked winning setups converges toward a weight near +1; a factor that was pure noise converges toward 0; the library never lets a negatively-correlated factor's weight go negative, because a factor a trader added expecting it to help should never silently start SUBTRACTING from the score without an explicit, separate decision to invert its sign. Factor definitions and the recorded outcome history both use fixed-size arrays (10 factors, 300 records) rather than dynamic ones, both for the struct-copy safety this catalogue standardises on and because an unbounded outcome history would eventually calibrate weights against ancient, no-longer-relevant market conditions - a ring buffer over the most recent MAX_SCORE_RECORDS setups keeps calibration responsive to recent regime, and a caller wanting a longer memory raises the constant and recompiles, a deliberate choice rather than an accidental limit. Notes and limitations - ScoreSetup() expects every factor value already normalised to roughly 0..1 by the caller - the framework has no way to know each factor's natural range (an ADX reading and a spread-in-points live on completely different scales), so normalising is deliberately left as the caller's responsibility rather than guessed at internally. - PearsonCorrelation() returns 0.0 (neutral) rather than attempting a division by zero whenever fewer than 3 records exist or either the factor's values or the outcomes never varied across the recorded history - a flat series has no meaningful correlation to compute. - Correlation measures a LINEAR relationship only. A factor with a genuine but non-linear relationship to outcome (e.g. only predictive in its extreme deciles) can calibrate to a lower weight than its real value, because Pearson correlation does not detect that shape. - CalibrateWeights() recomputes every factor's weight from scratch each call using the full recorded history - it does not smooth or blend with the previous weight, so weights can move by a meaningful amount between consecutive calibrations if recent data materially disagrees with older data.

Script · MT4 · v1.0 · Free

About Setup Scoring Framework

Setup Scoring Framework is a script for MetaTrader 4. It has 2 settings, such as Synthetic records and Random seed. MQL source code included.

Files in the download: SetupScoringFramework.mqh, SetupScoringFramework.txt, SetupScoringFrameworkDemo.mq4.

Settings

SettingDefaultWhat it does
Synthetic records60Fabricated historical setups to feed the calibrator
Random seed7Seed for the synthetic noise factor

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

MQL4 & MQL5 scripts · PolyMaria