Loading…

Flexible Distribution Fit Panel

A plain mean/standard-deviation summary of returns assumes the distribution is symmetric. Real return distributions usually are not - they skew, and a normal-distribution summary throws that information away. This panel instead fits Azzalini's skew-normal family, which adds a third parameter (shape/skew) on top of location and scale, to the trailing window of returns. The fit method is named explicitly because it is a deliberate simplification: the textbook way to fit a skew-normal is maximum likelihood, which needs iterative numerical optimisation - MQL4 has no general-purpose solver for that. The method-of-moments estimator used here is closed-form instead: it matches the sample's mean, variance and skewness exactly to the three skew-normal parameters (xi, omega, alpha) via Azzalini's published algebraic relations, no iteration required. This is a standard, documented alternative to MLE for this family, not an ad-hoc shortcut - it is exact for the three moments it targets, though not identical to a full MLE fit on any other measure. Sample skewness has a hard mathematical ceiling for what any skew-normal distribution can represent (|skewness| < ~0.9953, regardless of alpha); when a window's own skewness exceeds that, the panel clamps to the boundary and says so plainly rather than producing an undefined or nonsensical fit. Notes and limitations - The fit is method-of-moments, not maximum likelihood - it matches mean/variance/skewness exactly but is not guaranteed to be the single "best" fit by every other criterion (e.g. it does not directly target kurtosis or tail probability at all). - Skew-normal itself has a hard skewness ceiling (~0.9953 in magnitude); a window whose sample skewness exceeds that gets clamped to the boundary, and the panel flags this explicitly rather than hiding it. - The panel updates once per completed bar, not intrabar, so the displayed fit describes the settled distribution of completed bars only. - This describes the shape of RETURNS over the lookback window, not a forecast - it says what the recent distribution has looked like, not what tomorrow's return will be.

Indicator · MT4 · v1.0 · Free

About Flexible Distribution Fit Panel

Flexible Distribution Fit Panel is an indicator for MetaTrader 4. It has 4 settings, such as Lookback bars, Corner and Font size. MQL source code included.

Files in the download: FlexibleDistributionFit.ex4, FlexibleDistributionFit.mq4, FlexibleDistributionFit.txt.

Settings

SettingDefaultWhat it does
Lookback bars300Trailing bars whose returns are fitted
Corner0Panel corner: 0=LeftUpper 1=RightUpper 2=LeftLower 3=RightLower
Font size9Panel font size
Text colorclrWhitePanel text colour

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 → Indicators.
  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 indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Trailing Stop & Break-even · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria