loader image

Brokey For Amibroker

Mastering Amibroker: Why Your Backtests Might Be Wrong (and How "Brokey" Fixes It)

If you are an AlgoTrader or a systematic trader using Amibroker, you know the golden rule: Your backtest is only as good as the data you feed it.

We have all been there. You run a backtest on a portfolio of stocks, and the equity curve looks like a straight line to the moon. You think you’ve found the "Holy Grail," only to realize later that the strategy is worthless.

Why? Because your data had holes in it.

Today, we are looking at a critical concept in the Amibroker community often referred to as "Brokey" (or the process of detecting broken/missing data keys). We will explore what it is, why it destroys trading strategies, and how to use Amibroker’s native tools to fix it.

Step 3: Modify Your Position Sizing

In your AFL code, add a Brokey risk filter: brokey for amibroker

// Before entering a trade
BrokeyRisk = ExRem(BrokeyRisk, False);
if( Buy AND NOT BrokeyRisk ) 
   // Only enter if stock isn't on the "about to die" watchlist
   SetPositionSize( 2, spsPercentOfEquity );

Additionally, use StaticVarGet to track an external “Brokey Score” for each ticker (based on debt-to-equity or price < $1 for 30 days).

Part 4: Step-by-Step – How to Set Up Brokey in AmiBroker

Let’s get technical. Assuming you have sourced a delisted stock master file (a CSV with Ticker, DelistDate, FinalPrice), here is how to integrate the Brokey system. Mastering Amibroker: Why Your Backtests Might Be Wrong

Practical Workflow: Using Brokey in Daily Trading

Let’s say you are trading E-mini S&P 500 futures.

  1. Identify the Overnight High/Low: Use Brokey’s Session Lines tool to plot the overnight high and low. These appear as colored horizontal lines with labels.
  2. Draw a Trendline: Click the Brokey trendline icon, click your first swing point, then the second. Brokey draws the line and shows the slope percentage.
  3. Apply Fibonacci: From the day’s low to the high, drag the Fib tool. Instantly see the 0.382, 0.5, and 0.618 retracement levels as price approaches them.
  4. Save Everything: Switch to a 5-minute chart, then back to a daily chart. Your lines are still there. This persistence alone saves hours of redrawing.

5.2 Merger and Reverse Merger Adjustments

Brokey handling of mergers is tricky. If Stock A merges into Stock B, your AmiBroker database might just delete Stock A. A proper Brokey approach: click your first swing point

Most traders ignore this. Brokey forces you to model it.