Logistic Regression Classifier
Logistic regression is one linear combination of features passed through a sigmoid, trained directly against 0/1 labels via log-loss. That makes its output a genuine probability, not an unbounded score that merely resembles one - which is precisely why it is the right first model to try before a multi-layer network, on nearly any small tabular feature set an indicator or EA can build. It cannot overfit as wildly as a network with hidden layers, it trains in milliseconds, and its weights are directly inspectable. L2 (ridge) regularisation is applied to every weight except the bias, which is the standard and deliberate choice: shrinking the bias toward zero would bias every prediction toward 0.5 regardless of what the features actually say, which is not what regularisation is supposed to do. Neither MQL4 nor MQL5 supports a genuinely dynamic double[][] matrix, so the library sidesteps this entirely by taking the feature matrix as one flat 1D array in row-major order (row*columnCount + column) alongside explicit row and column counts, rather than fighting either language's array rules or hardcoding a fixed feature count. TrainBatch shuffles row order every epoch with Fisher-Yates so weight updates are not driven by whatever order the caller happened to build the matrix in. LogLoss reports the actual objective being minimised; BrierScore reports mean squared probability error, which penalises overconfidence separately from plain accuracy - a model can classify every row correctly and still have a poor Brier score if its probabilities are not honest about their own uncertainty. The header is self-contained. No dependencies, no DLLs. Notes and limitations - This is plain batch/stochastic gradient descent, not a second-order solver like Newton-Raphson or L-BFGS - it needs more epochs to converge than a production statistics package would, in exchange for a tiny, dependency- free implementation. - Features are not standardised internally. Feed features on comparable scales (or standardise them yourself first) - gradient descent converges much faster and more predictably when no one feature dominates the others purely by having a larger raw magnitude. - Binary classification only. A multi-class problem needs one-vs-rest: train one CLogisticRegression per class and compare the probabilities. - No money is at risk in the demo. It trains and predicts on synthetic data only, and never sends an order on either platform. - Like any model trained on a rolling window of market features, whatever edge it finds can decay when the regime that produced the training data changes - retrain periodically rather than trusting one fixed fit forever.
Script · MT4 · v1.0 · Free
About Logistic Regression Classifier
Logistic Regression Classifier is a script for MetaTrader 4. It has 3 settings, such as Epochs, Learning rate and L2 lambda. MQL source code included.
Files in the download: LogisticRegression.mqh, LogisticRegression.txt, LogisticRegressionDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Epochs | 300 | Training epochs (full passes over the dataset) |
| Learning rate | 0.30 | Gradient descent step size |
| L2 lambda | 0.01 | L2 regularisation strength |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: AI & Neural Network · MT4 Script · MQL4 Source Code