Discussing the article: "How to Build a 29-Pair Portfolio with an L1 Filter and VaR-based Allocation of Lots"
I’ve had a look at the maths – some interesting ideas. A good and interesting article.
However, the system could cause problems when the trend reverses.
This wasn’t mentioned in the article.
But what if the exchange rate has changed?
The L1 filter draws perfectly straight lines on an established trend, ignoring noise. But the causal version (which does not look into the future) has an inevitable cost for smoothing: inertia.
The current live cycle operates on a timer — it recalculates signals once an hour or checks conditions every 10–60 seconds. On volatile instruments such as XAUUSD or GBPJPY, the most dramatic reversals occur within an hour. If the price reverses sharply, forming a strong pattern, waiting for the H1 bar to close or for the one-minute timer to trigger will result in a massive drawdown on the open position.
Good morning. When I launch the programme, I get the error “❌ EURUSD: unable to retrieve a tick”. This error occurs with all symbols. Are there any solutions? In backtesting mode using historical data, everything works perfectly, and the charts are generated successfully. However, in ‘Infinite real-time cycle’ mode, I get the error mentioned above.
<moderator’s note: machine translation into Russian>
1 – change the total lot from a static value of 6 to the output of a function that calculates it based on a multiplier of the free margin(e.g. 0.2)... then the maximum per symbol would be a multiple of totLots (e.g. 0.1)
2- In many cases, after the code has been retrained, it loses contact with MT5; you might benefit from adding this to the `send_market_order` function:
mt5, terminal = mt5_connect_expected()
<moderator’s note: machine translation into Russian>
for j in range( prev_i + 1, i): w = ( j - prev_i) / ( i - prev_i) out[ j] = (1 - w) * prev_val + w * float( seg_l1[-1]) # ← seg_l1[-1] is the value at point i (FUTURE!)
The algorithm looks ahead by a stride of 1 bar when interpolating , which makes it unsuitable for live trading.
Check out the new article: How to Build a 29-Pair Portfolio with an L1 Filter and VaR-based Allocation of Lots.
Sooner or later, every trading system developer faces the same disappointment: a model that performed brilliantly on historical data begins to generate false signals as soon as the market shifts into a different market regime. There's almost always just one reason — noise. High-frequency price fluctuations, which provide no predictive information about the direction of the trend, end up in the training sample alongside meaningful signals and clutter the model with patterns that will never recur.
But there is a second problem that is less often discussed: trading a single currency pair makes the system dependent on that specific instrument. EURUSD may generate no profit for months in a sideways market, while GBPJPY shows directional movement. Traders come to this article with two pain points: features built directly from raw prices feed too much noise into the model, and reliance on a single currency pair makes returns unstable.
The solution is based on three ideas. Individually, they are useful; together, they take quality to a whole new level. The first is the L1 Trend Filter, a mathematically rigorous nonlinear smoothing method based on convex optimization that extracts a clean piecewise-linear trend from a price time series without lag. The second is diversification across 29 instruments: 28 major and cross currency pairs, plus gold (XAUUSD). The third is parametric VaR-based allocation of lots, in which each instrument receives a share of the total budget inversely proportional to its volatility, automatically reducing the weight of high-risk instruments and increasing that of stable ones.
Author: Yevgeniy Koshtenko