You want to train a model to predict good trades.
So what do you do? You create a label like:
“If price goes up after 10 bars → label = 1, else 0.”
It sounds logical — but in reality, it’s flawed.
This kind of label ignores two fundamental things every real trade faces:
Risk (what if the price drops before going up?)
Timing (what if it goes up… but only after weeks?)
That’s why serious quants don’t use simple returns as labels.
They use something far more robust: the Triple Barrier Method.
In this newsletter, you’ll learn how it works, why it’s better, and how to implement it in Python using the quantreo library, so your backtests stop lying and your models start learning.
1. What Is the Triple Barrier Method?
The Triple Barrier Method, introduced by Marcos López de Prado, is a powerful way to label trading data.
Instead of checking whether the price goes up or down after n candles, it simulates realistic trade conditions using three key barriers:
🟢 1. Upper Barrier → Take Profit
Set at a fixed percentage or return above the entry price.
If the price hits this level first, the trade is labeled as +1 (profit).
🔴 2. Lower Barrier → Stop Loss
Placed below the entry price.
If this level is reached first, the label is -1 (loss).
⏱ 3. Vertical Barrier → Max Holding Time
If neither TP nor SL is hit within a certain number of periods, the trade expires, and the label is 0 (neutral).
📌 What makes it powerful?
It doesn’t just care about how much the price moved —
It asks how the trade played out under realistic conditions:
Did it reach the profit fast enough?
Was it stopped out?
Did it just move sideways?
The result is a label that reflects both the direction, the risk, and the timing of each opportunity.
And that makes it ideal for machine learning, especially in noisy markets.
2. How to Use the Triple Barrier Method in Practice
Now that you understand the concept, let’s make it concrete.
You don’t need to reinvent the wheel, the method is already implemented in the quantreo library.
Let’s go through a simple example to label your data.
🧪 Step 1: Load a Sample Dataset
from quantreo.datasets import load_generated_ohlcv_with_time
df = load_generated_ohlcv_with_time()
df = df.loc["2016"]
To use the Triple Barrier Method, you must have low_time
and high_time
columns, they tell when the price reached its lowest and highest points during the holding period.
If you’re working with resampled data (like 1H or 4H candles), just extract 1-minute data first, then resample it; this way, you can easily track when the high or low occurred. If you use alternative bars, just use the ticks.
🧱 Step 2: Apply the Triple Barrier Labeling
df["label"] = te.directional.triple_barrier_labeling(df, 500, open_col="open", high_col="high", low_col="low", high_time_col="high_time", low_time_col="low_time", tp=0.015, sl=-0.015, buy=True)
This function scans each row in the dataset, applies the three barriers (TP, SL, time), and creates a new column label
with values:
1
→ trade hit the take-profit-1
→ trade hit the stop-loss0
→ trade expired with neither hit
✅ That’s it.
Now your ML models won’t just learn from oversimplified returns.
They’ll learn from real-world trade outcomes, shaped by profit, loss, and time.
The Triple Barrier Method gives your model a much stronger foundation to distinguish between valid trades and noisy signals.
3. Why It’s a Perfect Fit for Meta-Labelling
The Triple Barrier Method is a natural foundation for building meta-labels.
In meta-labelling, your goal isn’t to predict the market directly — it's to decide whether to act on a primary signal (long/short). But to do that, your model needs feedback on how those signals typically end.
That’s exactly what the triple barrier provides.
It gives each entry signal a structured label:
+1
if the trade would have reached take-profit,-1
if it would have hit the stop-loss,0
if it expired before reaching either.
This clear outcome gives your meta-model a concrete objective: learn to filter out bad signals, and only act on those with a higher chance of success.
In short, the Triple Barrier Method transforms raw directional signals into a reliable training set for smarter decision-making.
Most traders label their data in a simplistic way, and wonder why their models don’t work.
The Triple Barrier Method changes the game.
It adds realism to your backtests by mimicking what would actually happen in a trade:
Take-profit, stop-loss, or timeout.
And if you’re building advanced workflows like meta-labelling, it’s not optional —
it’s the backbone that allows your meta-model to learn from real trade outcomes, not noisy price shifts.
👉 Start using it today with just a few lines of code in the quantreo library.
Your model, and your future self, will thank you.