Your First Backtest
Turn an indicator into a strategy, simulate it over history, and read the report honestly.
A strategy is an indicator that can also place orders. Swap the indicator declaration for strategy and you gain a starting capital, a position sizing rule, and cost assumptions for commission and slippage. Those three parameters change results more than most people expect, so set them to something you could actually achieve before you look at the equity curve.
Entries and exits are declared, not imperative. strategy.entry registers an order with an id and a side; the when argument decides on which bars it is allowed to fire. strategy.exit attaches a stop, a target and an optional trail to that id, and the engine manages the bracket for you until one leg fills or the position is closed by something else.
Run the backtest from TypeScript when you want the raw numbers. The report contains stats, a trade list and the equity curve. Read maximum drawdown before net profit — a strategy that made 180 percent while spending four months down 60 percent is not one you would have held. Profit factor under about 1.2 and a sample of fewer than roughly a hundred trades both mean the result is mostly noise.
Change one thing at a time and re-run. Vary the lookback across a range and look for a plateau of similar results rather than a single peak; a lone spike is a curve fit and it will not survive contact with next month. Then re-run on a symbol and a period the strategy has never seen. If the shape of the equity curve is unrecognisable, you fit the noise.
Finally, keep the framing straight. A backtest tells you how a rule would have behaved under one specific fill model, on one data set, with no funding costs and no partial fills. Treat the number as a hypothesis about the rule, not a forecast of your account.