Ichimoku A45Case study · Transtorm

Client case · automating a stock-market strategy

Automating a Trading Strategy: A 20-Year Backtest and Production Case Study

“My method works when I follow it. The problem is me. I want the decision to come out of a program, not out of my mood that evening.”

A strategy is only worth something if it is followed to the letter, and that is where a human stumbles. A trader handed us the way he chooses stocks, enters and exits. We turned it into rules, we simulated it over twenty years, then we automated it. Every evening he now gets an email telling him to buy, to sell, or to do nothing.

By Mamisoa Andriantafika, founder of Transtorm, workflow automation and software engineering

Talk about your projectRead the case study

Why automate

In the markets, the hard part is rarely finding a good method. It is applying it without fail, every day, including the days when the market makes you want to do something else. Automation solves exactly that problem: the program executes the strategy to the letter, without hesitation.

Our client has a method. He knows it well and is convinced it works when he follows it. What remains is the down evening when he cuts too soon and the up evening when he holds too long; added up, those gaps end up costing more than the return of the method itself.

So he asked us to automate the application of his method. We deliver an email every evening, after New York closes. It carries one verdict and nothing else — buy, sell or do nothing — and the orders to schedule before the next day's open.

The work unfolded in three stages.

Scoping: the method put in writing

We first translated the method into rules a program applies without interpretation. “I buy when the stock is well oriented” cannot be coded: you have to say on which price, at what point in the session, and what happens when two conditions contradict each other.

Three questions structured the interview. What drives the choice of stocks? On what signal do you enter and exit? What share of the capital does each position receive? The two sections that follow give the result of that scoping, as the client validated it. The exact thresholds belong to the client and are not published here.

The stock selection

Twice a year, in May and in November, a scan reviews a full month of quotes. The universe combines the hundred Nasdaq-100 stocks and the energy-sector stocks of the S&P 500, about 120 candidates. The retained basket enters the portfolio on the first trading day of the following month.

Each candidate passes four filters, in this order:

  1. Liquidity. The price is above 1 USD and the stock trades a significant volume every day. We have to be able to enter and exit without moving the market.
  2. Underlying trend. The stock is in what Stan Weinstein calls stage 2, the established uptrend that follows accumulation. We don't buy a dip, we buy a trend already in place.
  3. Relative strength. The stock does better than the U.S. market, and not merely better than zero: a 5% rise is worth nothing if the index made 8%.
  4. Relative volume. Trading intensifies compared with its usual regime, which shows that capital is moving into the stock.

The scan then ranks the stocks that pass all four filters by the average of their relative-strength rank and their volume rank; the top five form the basket. At the next scan, those still holding their trend keep their open position and only the others are replaced. Renewing the whole basket every time would cost fees and would deprive positions of the time they need to work.

The buying and selling rules

Each stock in the basket receives one-fifth of the capital. Only two indicators drive entries and exits: the stock's RSI, which measures the vigour of its recent move, and the state of the U.S. market, given by the position of the Nasdaq index relative to its long moving average.

The RSI acts as a guardrail at both ends. We don't buy a stock whose move is already stretched, and we sell when it clearly overheats beyond that level. This double limit avoids entering a rally that is ending and staying in place when it turns.

RuleBuySellWhat it brings
A16Nasdaq above its long moving average and RSI not too hightwo closes of the Nasdaq below its long moving average, or RSI overheatingthe base rule: invested when the market rises, in cash when it breaks
A24as A16; in a bearish market, a buy becomes possible again if the Nasdaq holds three closes above its 26-day Kijunas A16; in a bearish market, one close of the Nasdaq below the Kijunit catches rebounds without waiting for the return above the average, and it gives the best result of the three over twenty years
A25RSI not too high, on the whole sleeve in a supportive market and on half otherwiseRSI overheatingit always stays partly invested, so a break costs only half the position

The execution convention is the same in the study and in the live tracking. The program reads the rule on the closing price and places the order at the next session's open, never at the price that produced the signal: this is what separates an honest simulation from a flattering one. Each execution costs 10 basis points, half in commission, half in price slippage.

Backtest and optimization: twenty years of simulations

We then simulated the method from December 2005 to November 2025, varying three things: the selection, the rules and the leverage. Each variant starts from 100,000 USD, goes through forty windows of six months and pays its fees at every execution.

We don't judge on a single figure. A curve that finishes higher but goes through an 80% drawdown doesn't hold: nobody follows it to the end, and that is exactly the problem we were trying to solve. So we read four indicators together: final capital, worst drawdown, Sharpe ratio and the number of windows won.

One major precaution is to reconstruct the investment universe as it existed at each point in time: the universe of each scan is the index's composition on that date, not today's. Without it, we would only be testing winners already known in advance.

Twenty years on shares, 2005-2025

The demonstration chains 40 six-month windows, from December 2005 to November 2025, with the basket dated to each scan and 100,000 USD at the start. For each scan in the study, the Nasdaq-100 universe is the index composition on that date, not today's. A stock that has since left the index remains a candidate for the periods when it belonged to it. This precaution reduces survivorship bias, which consists of testing only today's winners. The energy list, meanwhile, is the 2022 one throughout the period: it was not reconstructed. The vertical scale is logarithmic: the same slope corresponds to the same growth rate, in 2006 as in 2024.

Twenty years on shares, 2005-2025Logarithmic vertical scale: the same slope means the same growth rate, in 2006 as in 2024. The dashed line is the starting capital, 100,000 USD.
50 k100 k200 k500 k1 M2005200820102012201420162018202020222024
Buy & HoldA16A24A25
✕ Close
StrategyFinal capital (USD)Annualised returnWorst drawdownSharpeSortinoWindows won
Buy & Hold1,037,514+12.4%−72%0.55
A161,144,738+13.0%−38%0.6517 / 40
A241,312,607+13.7%−40%0.6718 / 40
A251,163,442+13.1%−57%0.6313 / 40

Buy & Hold serves as the reference: the same five stocks, bought on entering the basket and held with no rule. The three rules finish above it, with a smaller maximum drawdown (−38 to −57% against −72% for Buy & Hold in 2008). A24 is chosen as the engine for the live tracking. It gives the best final capital and the best Sharpe ratio, and its bearish regime opens entries the other two do not.

Leverage through turbo calls

A turbo call is a certificate issued by a bank. It replicates a stock with leverage: with leverage 3, a 1% rise in the stock earns the certificate about 3%, and a 1% fall costs it about 3%. The certificate's price corresponds, roughly, to the gap between the stock's price and a level called the barrier, set here about one-third below the entry price. If the stock touches the barrier, the certificate is knocked out and the stake is lost. The barrier rises every day, by about 8.6% a year on U.S. stocks. That is the carry cost charged by the issuer. Added to it is the gap between the buy price and the sell price.

The three rules were rerun with the whole sleeve placed in a 3× turbo call on each buy signal, knocked out on the session low, and bought back five sessions later if the signal is still a buy. These variants are named A42, A45 and A46.

Twenty years with turbo call leverage, 2005-2025Logarithmic vertical scale: the same slope means the same growth rate, in 2006 as in 2024. The dashed line is the starting capital, 100,000 USD.
50 k100 k200 k500 k1 M2 M5 M2005200820102012201420162018202020222024
Buy & HoldA42A45A46
✕ Close
StrategyFinal capital (USD)Annualised returnWorst drawdownSharpeSortinoWindows won
Buy & Hold1,038,865+12.4%−72%0.550.78
A423,883,594+20.1%−76%0.610.8924 / 40
A455,668,540+22.4%−79%0.640.9324 / 40
A463,848,078+20.0%−87%0.610.8720 / 40

Leverage multiplies the annualised return by 1.5 to 1.7 and doubles the worst drawdown. A45 finishes far ahead, but it lost 79% of its value between November 2022 and October 2023, when the failed rebounds of a bearish market were paid for three times over. The Sharpe ratio does not improve: leverage does not improve the quality of the signals, it amplifies their results. For this reason, the live tracking is a full-size simulation, not a real account.

The discarded variants

We compared before choosing. Over the same twenty years, we measured several a priori reasonable variants, then we discarded them. The table gives A24's final capital in each case.

VariantA24 final capital (USD)GapWhy
Partial semiannual rotation, positions carried (kept)1,312,607+0.0%the reference: stocks still above their long moving average are kept from one window to the next
Quarterly rotation1,043,974−20.5%rescanning every three months replaces stocks that have not had time to work
Retention requiring two closes above the average1,123,862−14.4%since the decision is made only twice a year, the tolerance filters no noise and delays genuine exits by a full window
Market filter by each stock's GICS sector ETF865,458−34.1%the selected stocks track the Nasdaq far more than their sector, and the sector ETFs fall below their long moving average more often
Single market filter by the SPY834,972−36.4%the S&P 500 breaks its long moving average more often than the Nasdaq and rebounds later
Calmed market filter (hysteresis band, weekly close, slow re-entry)see labelthe three variants cost 12 to 38% of the final capital: a false QQQ signal costs little, a delayed exit costs a great deal

These trials all lead to the same conclusion. On volatile stocks, anything that delays an exit costs more than the false signals avoided, and anything that shortens the holding period deprives positions of the time they need to progress.

Data and method: survivorship bias, look-ahead bias and trading costs

The figures on this page rest on the following choices.

  • Price source. Daily prices provided by Yahoo Finance.
  • Nasdaq-100 composition. Rebuilt at each scan date from the 211 dated changes published on the Wikipedia page “Historical components of the Nasdaq-100”, worked back to 2005.
  • Energy universe. The 2022 list of the S&P 500 energy sector, fixed for the whole period.
  • Delisted securities. 57 of the 123 stocks of November 2005 are no longer available from the provider and are missing from the simulation.
  • Period and capital. December 2005 to November 2025, with 100,000 USD at the start.
  • Execution. The signal is read on the closing price and the order is executed at the next day's open.
  • Costs. 0.1% per execution, half commission and half price slippage.
  • Look-ahead bias. An automated test multiplies every price after a cut-off date by factors of 10 to 50 and requires the decisions before that date to remain identical. It is one of the automated tests run again on every change to the program.

Production: one email every evening

A validated strategy is only worth something if it is applied every evening, without exception. Production does not take the decision away from the client: the rule remains his and he can change it whenever he wants. What automation adds is reliable application every evening, continuous monitoring and a trace of every verdict.

The setup rests on a server, a scheduled task and a program. After New York closes, the program downloads the day's prices, reruns the simulation from day one, runs a series of checks, then sends an email carrying one of three verdicts: BUY, SELL or NOTHING TO DO. The client schedules the orders the next morning, before the open.

Nothing is entered by hand, nothing is arbitrated by hand. At identical prices, the program produces the same order, whether the week was good or bad.

Placing the orders stays in the client's hands here: that is his choice, he wants to keep that last gesture. It can be automated in turn, with the orders going straight to the broker, as soon as the broker exposes an interface to receive them.

Each evening's run

The setup rests on a server, a scheduled task and a program that follows an algorithm. No data is entered by hand.

  1. 10:00 p.m., ParisNew York closes.
  2. 11:15 p.m.The scheduled task runs the program, Monday to Friday.
  3. PricesThe program downloads today's closes for the five stocks, the QQQ, the SPY and the EUR/USD, then caches them.
  4. EngineThe program reruns the simulation from 1 Dec 2025 with the real products: A24 signals, buys and sells at the next open, valuation at the bid, knock-outs. The references (Buy & Hold, A24 on shares, synthetic-turbo engine) are recomputed on the same prices.
  5. ChecksThe program checks that today's data is present, that the bars are aligned, that the execution dates match the engine's, and that the ISINs are valid. It also reads each product's page at its issuer: quote active, real bid and ask, barrier matching.
  6. Email and pageThe email goes out with today's orders at the top. This page is regenerated at the same time. A failed check never blocks the send: it appears in the email with the instruction to follow.
  7. The morningThe orders are read in the email and scheduled with the broker before the New York open at 3:30 p.m.

The products currently tracked, one per stock, were chosen for a barrier near two-thirds of the entry price and an issue date earlier than the start:

StockIssuerProductCodeISINIssued onBarrier (USD)
IDXXSociété GénéraleBEST Turbo Call open end IDEXX LaboratoriesSX3S88DE000SX3S88324 Apr 2025462.62
BIIBUniCreditHVB Turbo Bull open end BiogenUG5EG8DE000UG5EG8622 Apr 2025124.85
AMGNHSBCTurbo Call open end AmgenTT1RUTDE000TT1RUT531 Mar 2020237.02
MARSociété GénéraleBEST Turbo Call open end Marriott InternationalSX7Q8XDE000SX7Q8X811 Apr 2025230.77
GOOGLSociété GénéraleBEST Turbo Call open end Alphabet AFC0P2PDE000FC0P2P612 Sep 2025226.75

If a product is knocked out, the sleeve waits five sessions then buys back the next product on record for the stock. If there is none, the email flags “choose product”.

Limitations

  • The figures on this page come from twenty years of simulations, not from a record of orders actually placed.
  • A signal is executed with a one-day lag, at the next open. An unfavourable opening gap feeds through to the result.
  • With leverage 3, a drawdown close to −80% has already occurred and can happen again. A knock-out wipes out the entire sleeve concerned.
  • Past results, even after correcting for survivorship bias as far as the available historical data allows, guarantee nothing about future results.
  • The price provider no longer distributes the history of delisted companies: 57 of the 123 stocks of the November 2005 universe cannot be found. The bankruptcies and buyouts among them are therefore missing from the simulation, and their net effect on the result is unknown.
  • The S&P 500 energy list is the 2022 composition, used for the whole period: this is a second, smaller, retrospective selection bias.
  • Transtorm does not design or recommend investment strategies: we formalise, test and automate the rules supplied by the client.

The approach beyond this project

What automation brings here holds well beyond this strategy: the program applies the rule exactly as it was written, every day, without wondering whether the moment feels right. The three stages apply whenever a decision comes back regularly and rests on rules that are known but not always followed. Scoping turns the method into executable rules, optimization shows which ones hold up over the long run, production applies it every evening, monitors it and keeps a trace of it, without taking the rule out of the client's hands.

The code, the data and the results remain the client's property. That is why the exact selection and RSI thresholds do not appear on this page.

Do you have a method to automate?

Transtorm scopes the method, measures it and takes it to production. From the first interview to the first automatic email, this project took three stages; yours will probably take about as many.

We publish this case study with the client's agreement. Selection and RSI thresholds are not disclosed; the figures shown are those of the simulations.

Talk about your projectRead the behind-the-scenes article