← Back to Insights

The Anti-Fragile Farm: Building a Decorrelated Bot Portfolio

2025-12-19

If you have 5 bots running, and they all make money on the same day, you have a problem. It means they are Correlated.

If they all win together, they will all lose together. When the market regime shifts (e.g., from Bull to Crab), your entire farm will collapse simultaneously. This is the definition of a "Fragile" system.

To build an Anti-Fragile system—one that thrives in chaos—you need Decorrelation.

You need a portfolio where Bot A loves what Bot B hates.

  • Bot A (Trend): Loves volatility. Hates sideways chop.
  • Bot B (Grid): Hates volatility. Loves sideways chop.

When you combine these two, you smooth out the equity curve. You stop caring about "Market Direction" and start caring about "Market Mechanics."

The Yin and Yang of Algorithms

We structure our 3Commas portfolio into two distinct buckets:

1. The Hunters (Long Volatility)

  • Logic: SuperTrend, Breakout, Moving Average Cross.
  • Role: Catch the big pumps and dumps.
  • Weakness: They bleed money in boring markets (Whipsaws).

2. The Farmers (Short Volatility)

  • Logic: Grid Bots, RSI Mean Reversion.
  • Role: Harvest the noise in boring markets.
  • Weakness: They get crushed by strong trends (Impermanent Loss).

A balanced portfolio is 50% Hunters, 50% Farmers. When the Hunters are bleeding, the Farmers are feeding. And vice versa.

The Code: Visualizing the Regime

To execute this, you need to know which Regime you are in. This Pine Script doesn't generate buy signals; it generates Allocation Signals. It tells you which bucket should receive more capital right now.

//@version=6
indicator("Codon: Market Regime Classifier", overlay=false)

// --- Settings ---
int atrLen = input.int(14, "ATR Length")
int maLen = input.int(100, "Baseline MA")

// --- Logic ---
// 1. Volatility Filter (ATR normalized by Price)
float atr = ta.atr(atrLen)
float normalizedATR = (atr / close) * 100
float volThreshold = ta.sma(normalizedATR, 100) // Dynamic threshold

// 2. Trend Filter (ADX)
[diplus, diminus, adx] = ta.dmi(14, 14)

// --- Regime Definition ---
// High Vol + High ADX = TREND REGIME (Hunters Active)
bool isTrendRegime = (normalizedATR > volThreshold) and (adx > 25)

// Low Vol + Low ADX = CHOP REGIME (Farmers Active)
bool isChopRegime = (normalizedATR < volThreshold) and (adx < 20)

// --- Visualization ---
// Plot ADX
plot(adx, color=color.white, title="Trend Strength (ADX)")
hline(25, color=color.gray, linestyle=hline.style_dotted)

// Background Color to indicate active strategy
bgcolor(isTrendRegime ? color.new(color.green, 80) : na, title="Trend Zone")
bgcolor(isChopRegime ? color.new(color.red, 80) : na, title="Grid Zone")

// Labels
if barstate.islast
    string status = isTrendRegime ? "🔥 DEPLOY HUNTERS (Trend)" : (isChopRegime ? "🌾 DEPLOY FARMERS (Grid)" : "⚠️ TRANSITION ZONE")
    color col = isTrendRegime ? color.green : (isChopRegime ? color.red : color.orange)
    label.new(bar_index, adx, status, color=col, textcolor=color.white)

The Automation Layer

You do not need to manually turn bots on and off. You can automate the "Capital Rotation" using 3Commas Presets.

  1. Tag Your Bots: In 3Commas, tag your Trend bots as "Hunter" and your Grid bots as "Farmer."
  2. Risk Allocation:
    • If the Regime Script shows Green (Trend), you can manually (or via advanced webhook scripts) increase the "Max Active Deals" for your Hunter bots.
    • If the Regime Script shows Red (Chop), you allocate more margin to your Grids.

The Result: Psychological Stability

The biggest benefit of this architecture is not just financial; it is psychological.

There is never a "Bad Market."

  • Market crashes? "Great, my Trend bots are shorting."
  • Market does nothing? "Great, my Grid bots are printing."

You stop fearing specific outcomes because you have an agent assigned to every possibility. You are no longer a gambler praying for a specific number. You are the Casino Owner, profiting regardless of where the ball lands.

(Check the footer for our full portfolio allocation template)