Linear SVM Classification of Bar Direction Using Open and Close Prices
Summary
This example applies a linear support vector machine to classify each new bar’s next close-to-close movement as upward, downward, or relatively flat. It builds training examples from historical bar open and close prices, labels each example according to whether the following close changes by more than a fixed spread threshold, then fits a classifier and predicts a class for the current bar. The script waits for new records and tracks whether past predictions match the subsequent movement category.
The document includes a partially commented variant with logging and account-position scaffolding, but does not provide complete trading rules or results. Its input features are raw prices, so the model may be sensitive to price scale and market regime. The sample also gives no validation procedure, holdout data, transaction costs, or evidence that its reported prediction count measures trading profitability. Its threshold and implementation details require careful checking before practical use.
Key ideas
- The classifier predicts upward, downward, or flat movement based on a threshold applied to the next close-to-close change.
- Historical open and close prices are used as the model’s two input features.
- A linear support vector classifier is refitted on available historical records before each prediction.
- The script checks predictions against the following bar movement and logs a success count.
- The example provides no out-of-sample evaluation, cost model, or evidence of profitable trades.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.