Crypto Trading Simplified with the Lorentzian Classification Indicator

Lorentzian Classification Indicator - CryptoChris World

Overview

A Lorentzian Distance Classifier (LDC) is a machine learning classification algorithm that can categorize historical data based on multiple features. This classifier can also predict the direction of future price movements when used as the distance metric to implement an Approximate Nearest Neighbors (ANN) algorithm.

In physics, Lorentzian space is perhaps best known for its role in describing the curvature of space-time in Einstein’s theory of General Relativity (2). Interestingly, however, this abstract concept from theoretical physics also has tangible real-world applications in trading.

Background

Recently, it was hypothesized that Lorentzian space was also well-suited for analyzing time-series data (4), (5). This hypothesis has been supported by several empirical studies that demonstrate that Lorentzian distance is more robust to outliers and noise than the more commonly used Euclidean distance (1), (3), (6). Furthermore, Lorentzian distance was also shown to outperform dozens of other highly regarded distance metrics, including Manhattan distance, Bhattacharyya similarity, and Cosine similarity (1), (3). Outside of Dynamic Time Warping based approaches, which are unfortunately too computationally intensive for PineScript at this time, the Lorentzian Distance metric consistently scores the highest mean accuracy over a wide variety of time series data sets (1).

Euclidean distance is commonly used as the default distance metric for NN-based search algorithms, but it may not always be the best choice when dealing with financial market data. This is because financial market data can be significantly impacted by proximity to major world events such as FOMC Meetings and Black Swan events. This event-based distortion of market data can be framed as similar to the gravitational warping caused by a massive object on the space-time continuum. For financial markets, the analogous continuum that experiences warping can be referred to as “price-time”.

Below is a side-by-side comparison of how neighborhoods of similar historical points appear in three-dimensional Euclidean Space and Lorentzian Space:

This figure demonstrates how Lorentzian space can better accommodate the warping of price-time since the Lorentzian distance function compresses the Euclidean neighborhood in such a way that the new neighborhood distribution in Lorentzian space tends to cluster around each of the major feature axes in addition to the origin itself. This means that, even though some nearest neighbors will be the same regardless of the distance metric used, Lorentzian space will also allow for the consideration of historical points that would otherwise never be considered with a Euclidean distance metric.

Intuitively, the advantage inherent in the Lorentzian distance metric makes sense. For example, it is logical that the price action that occurs in the hours after Chairman Powell finishes delivering a speech would resemble at least some of the previous times when he finished delivering a speech. This may be true regardless of other factors, such as whether or not the market was overbought or oversold at the time or if the macro conditions were more bullish or bearish overall.

These historical reference points are extremely valuable for predictive models, yet the Euclidean distance metric would miss these neighbors entirely, often in favor of irrelevant data points from the day before the event. By using Lorentzian distance as a metric, the ML model is instead able to consider the warping of price-time caused by the event and, ultimately, transcend the temporal bias imposed on it by the time series.

Trading Killzones - CryptoChris World

How to use

Below is an explanatory breakdown of the different parts of this indicator as it appears in the interface:

Below is an explanation of the different settings for this indicator:

General Settings


Source – This has a default value of “hlc3” and is used to control the input data source.
Neighbors Count – This has a default value of 8, a minimum value of 1, a maximum value of 100, and a step of 1. It is used to control the number of neighbors to consider.
Max Bars Back – This has a default value of 2000.
Feature Count – This has a default value of 5, a minimum value of 2, and a maximum value of 5. It controls the number of features to use for ML predictions.
Color Compression – This has a default value of 1, a minimum value of 1, and a maximum value of 10. It is used to control the compression factor for adjusting the intensity of the color scale.
Show Exits – This has a default value of false. It controls whether to show the exit threshold on the chart.
Use Dynamic Exits – This has a default value of false. It is used to control whether to attempt to let profits ride by dynamically adjusting the exit threshold based on kernel regression.

Feature Engineering Settings:

The Feature Engineering section is for fine-tuning the features used for ML predictions. The default values are optimized for the 4H to 12H timeframes for most charts, but they should also work reasonably well for other timeframes. By default, the model can support features that accept two parameters (Parameter A and Parameter B, respectively). Even though there are only 4 features provided by default, the same feature with different settings counts as two separate features. If the feature only accepts one parameter, then the second parameter will default to EMA-based smoothing with a default value of 1. These features represent the most effective combination I have encountered in my testing, but additional features may be added as additional options in the future.


Feature 1 – This has a default value of “RSI” and options are: “RSI”, “WT”, “CCI”, “ADX”.
Feature 2 – This has a default value of “WT” and options are: “RSI”, “WT”, “CCI”, “ADX”.
Feature 3 – This has a default value of “CCI” and options are: “RSI”, “WT”, “CCI”, “ADX”.
Feature 4 – This has a default value of “ADX” and options are: “RSI”, “WT”, “CCI”, “ADX”.
Feature 5 – This has a default value of “RSI” and options are: “RSI”, “WT”, “CCI”, “ADX”.

Lorentzian Filters Settings:

Use Volatility Filter – This has a default value of true. It is used to control whether to use the volatility filter.
Use Regime Filter – This has a default value of true. It is used to control whether to use the trend detection filter.
Use ADX Filter – This has a default value of false. It is used to control whether to use the ADX filter.
Regime Threshold – This has a default value of -0.1, a minimum value of -10, a maximum value of 10, and a step of 0.1. It is used to control the Regime Detection filter for detecting Trending/Ranging markets.
ADX Threshold – This has a default value of 20, a minimum value of 0, a maximum value of 100, and a step of 1. It is used to control the threshold for detecting Trending/Ranging markets.

Kernel Regression Settings

Trade with Kernel – This has a default value of true. It is used to control whether to trade with the kernel.
Show Kernel Estimate – This has a default value of true. It is used to control whether to show the kernel estimate.
Lookback Window – This has a default value of 8 and a minimum value of 3. It is used to control the number of bars used for the estimation. Recommended range: 3-50
Relative Weighting – This has a default value of 8 and a step size of 0.25. It is used to control the relative weighting of time frames. Recommended range: 0.25-25
Start Regression at Bar – This has a default value of 25. It is used to control the bar index on which to start regression. Recommended range: 0-25

Display Settings

Show Bar Colors – This has a default value of true. It is used to control whether to show the bar colors.
Show Bar Prediction Values – This has a default value of true. It controls whether to show the ML model’s evaluation of each bar as an integer.
Use ATR Offset – This has a default value of false. It controls whether to use the ATR offset instead of the bar prediction offset.
Bar Prediction Offset – This has a default value of 0 and a minimum value of 0. It is used to control the offset of the bar predictions as a percentage from the bar high or close.

Backtesting Settings

Show Backtest Results – This has a default value of true. It is used to control whether to display the win rate of the given configuration.

Links

Read here about the EMA , RSI and the MACD indicators

Post Sources

TradingView.com

Leave a Reply

Your email address will not be published. Required fields are marked *