Skip to content
← All articles
Article

Multiple Technical Indicators Backtesting on Multiple Tickers using Python

Listen to the audio story

Testing one trading rule on hundreds of tickers · 2:21 · AI-written script, synthetic voices

Transcript

Ava: Here's a strange result. A trading rule turned a coin called OMGUSD into about a 200 percent gain, while simply holding it lost around 80 percent. How does a rule do that?

Andrew: By betting against the fall, I'd guess. Where does this come from?

Ava: From Antoine's BatchBacktesting engine, run at portfolio scale. Instead of testing one stock, he runs a rule across the whole S and P 500 and every crypto pair, and compares the results.

Andrew: Why bother with so many? One ticker is easier to read.

Ava: Because one ticker tells you whether the rule worked once. A big grid shows whether it works across sectors and eras, and where it falls apart. It's like testing a recipe in a hundred kitchens instead of one.

Andrew: What are the rules?

Ava: Two classics, built with backtesting dot py and pandas T A. The first is an EMA crossover: buy when the 20-period average crosses above the 80-period one, sell on the opposite cross, with a ten percent stop loss and a twenty-five percent take profit. The second is MACD: buy when the MACD line crosses above its signal line, sell on the reverse.

Andrew: And the machinery to run all of that?

Ava: Data adapters pull prices from Financial Modeling Prep and Binance. Strategy objects hold the parameters. A runner fans the work across a thread pool, twelve threads in his example, and writes CSV files and optional charts.

Andrew: What did the leaderboard look like?

Ava: For the EMA rule, the top five ranged from about 194 percent up to 294 percent, with BTCBUSD in first place at roughly 294. Next to each result, the charts show buy-and-hold for the same instrument, which is the comparison that makes the numbers meaningful.

Andrew: So the OMGUSD case is the interesting one.

Ava: Exactly. The rule made money by being short through a collapse, while Bitcoin and ALB rose under both approaches. That's what a wide run reveals: which gains come from the rule and which come from the period.

Andrew: And how do you compare the two strategies fairly?

Ava: Look at the median return across all tickers, not just the top five. That's a sturdier yardstick. The takeaway: a multi-ticker run is a great smoke test for a rule. The full write-up has both strategies' code and the leaderboards.

Multiple Technical Indicators Backtesting on Multiple Tickers using Python
Table of contents

Same BatchBacktesting[1] engine as the earlier indicator experiment, but emphasized at portfolio scale: many tickers, two strategies, equities plus crypto, aggregate winners and losers.

1. Why run many tickers at once

Single-ticker backtests flatter you. A grid run answers:

  • Does this rule only work on one heroic symbol?
  • Are disasters clustered in a sector or era?
  • Is crypto dominating the leaderboard because volatility is unbounded in the sim?

2. Architecture (same as BatchBacktesting)

LayerRole
Data adaptersFMP + Binance fetch
Strategy objectsEMA, MACD parameter sets
RunnerThread pool, CSV output, optional plots
output/Per-run artifacts — not committed to GitHub by default

Pre-calculated results are not in the upstream repo (too user-specific). You generate locally, then inspect output/charts/....

3. The two strategies

Both strategies use backtesting.py[2] with indicators from pandas_ta.

EMA crossover. Buy when the 20-period EMA crosses above the 80-period EMA, sell on the opposite cross. Each entry carries a 10 % stop loss and a 25 % take profit.

class EMA(Strategy):
    n1 = 20
    n2 = 80

    def init(self):
        close = self.data.Close
        self.ema20 = self.I(taPanda.ema, close.s, self.n1)
        self.ema80 = self.I(taPanda.ema, close.s, self.n2)

    def next(self):
        price = self.data.Close
        if crossover(self.ema20, self.ema80):
            self.position.close()
            self.buy(sl=0.90 * price, tp=1.25 * price)
        elif crossover(self.ema80, self.ema20):
            self.position.close()
            self.sell(sl=1.10 * price, tp=0.75 * price)

MACD crossover. The MACD line is the 12-period EMA minus the 26-period EMA; the signal line is a 9-period EMA of that difference. Buy when MACD crosses above its signal line, sell on the opposite cross. No stop loss or take profit here.

class MACD(Strategy):
    short_period = 12
    long_period = 26
    signal_period = 9

    def init(self):
        close = self.data.Close
        self.macd = self.I(taPanda.macd, close.s, self.short_period, self.long_period, self.signal_period)

    def next(self):
        macd_line = self.macd.macd
        signal_line = self.macd.signal
        if crossover(macd_line, signal_line):
            self.position.close()
            self.buy()
        elif crossover(signal_line, macd_line):
            self.position.close()
            self.sell()

4. Running at scale

tickers = get_SP500()
run_backtests(tickers, strategy=EMA, num_threads=12, generate_plots=True)
run_backtests(tickers, strategy=MACD, num_threads=12, generate_plots=True)

tickers = get_all_crypto()
run_backtests(tickers, strategy=EMA, num_threads=12, generate_plots=True)
run_backtests(tickers, strategy=MACD, num_threads=12, generate_plots=True)

Each call fans out over a thread pool. Tune num_threads to your machine and to the API rate limits of Financial Modeling Prep and Binance.

5. EMA leaderboard

Top five returns for the EMA strategy:

InstrumentReturn
BTCBUSD293.78 %
ALB205.97 %
OMGUSD199.62 %
BBWI196.82 %
GRMN193.47 %

Bottom five:

InstrumentReturn
BTTBUSD−99.93 %
UAL−82.63 %
NCLH−81.51 %
LNC−78.02 %
CHRW−76.38 %

Highest EMA returns next to buy-and-hold for the same instruments

The right-hand chart is the useful one. OMGUSD returned about 200 % with the EMA rule while buy-and-hold lost about 80 %, so the rule made money by being short through a collapse. BTCBUSD and ALB went up under both, which says more about the period than about the rule.

High returns often mix long bullish windows on volatile crypto pairs, lucky signals in sideways stocks, and parameters that happen to fit one period. Deep negatives flag illiquid symbols the simulation still trades, trend rules in collapsing sectors (airlines and cruise lines above), and broken or delisted pairs treated like normal tickers.

Before saying “MACD beats EMA”, compare the median return across all tickers, not only the top five.

6. Honest limitations

  • Not financial advice.
  • Fees, borrow, halts, and corporate actions are only as good as the data feed + library defaults.
  • Past batch output ≠ future edge.

7. Takeaway

Use multi-ticker backtests as smoke tests for rules — find where they break, not where to deploy capital.


Originally published on Medium[3]. Full code listings: BatchBacktesting[1].

References

  1. AlgoETS. (). BatchBacktesting. [Software repository] github.com.
  2. backtesting.py. (). [Web page] kernc.github.io.
  3. Medium. (). [Article] medium.com.

References use this article’s publication date.