How to Build Trading Strategies for Stocks

A stock trading strategy needs more than a list of indicators. Define which stocks you will consider, what triggers an entry, how you will exit, how much exposure you will take, and how you will judge the results. Then test those rules using information that would have been available at the time.
In LuxAlgo charts, you can inspect price and volume, add indicators, and use Quant, our coding agent, to turn a precise idea into a strategy you can review and backtest. The goal is a reproducible decision process. A profitable historical result is evidence to investigate, not a promise of future returns.
1. Define the stock strategy before choosing indicators
Start with the market and the practical constraints. A daily strategy holding through earnings has different risks from an intraday strategy that exits before the closing session. Technical analysis can help define price-based rules, while company announcements and fundamentals can still affect the stocks you trade.
- Universe: one specified stock, a fixed list, or a selection rule applied using historical information.
- Direction and holding period: long-only or both directions; intraday, several days, or longer.
- Data: exact symbol, source, interval, session, and history available.
- Exposure limits: maximum position allocation, total invested capital, and concentration in related stocks.
- Event policy: whether to hold through earnings or other scheduled announcements, using dates known at the time.
- Review criteria: acceptable losses, costs, operational demands, and what evidence would make you reject the idea.
Do not choose a monthly return target and keep changing settings until the backtest reaches it. Decide what question the strategy will answer. For example: does a defined trend-following rule improve the return-and-drawdown tradeoff relative to holding the same stock over the same period?
2. Give each indicator a specific job
Indicators transform price or volume data; combining more of them does not automatically create independent confirmation. Begin with a simple baseline and test whether each additional filter improves results after costs and outside the development sample.
| Tool | Possible role | Limitation to test |
|---|---|---|
| SMA or EMA | Define a trend or crossover rule. An SMA weights observations equally; an EMA emphasizes recent observations. | Both lag price and can produce repeated losing signals in a range. |
| RSI | Measure recent gains relative to losses on a 0–100 scale. | Readings above 70 or below 30 do not require an immediate reversal. |
| MACD | Compare fast and slow exponential averages and a signal average. | “Momentum confirmation” needs an exact condition; it is not a complete entry rule. |
| OBV | Accumulate volume positively or negatively according to close-to-close direction. | It does not identify institutions or count new money entering a stock. |
| ATR | Scale a proposed stop distance or compare recent price ranges. | Past range size does not cap a future gap or loss. |
The Fidelity technical indicator guide is a useful reference for calculations and interpretation. For example, OBV adds volume when the close rises and subtracts it when the close falls. It can diverge from price, so “OBV always rises in an uptrend” is not an adequate rule.
Add the tools to your LuxAlgo chart
Open the intended stock and interval, add the indicators you need, and record their inputs. Check that the chart uses the session and data you intend to test before interpreting any signal.
3. Write rules that can be tested
Replace phrases such as “buy when momentum is strong” or “sell when MACD weakens” with observable conditions and order timing. The following is an illustrative single-stock research baseline, not a recommendation or a strategy with demonstrated performance:
- Chart: regular-session daily candles for one specified stock, with enough earlier bars to initialize the calculations. No trades before the chosen test start date.
- Calculations: a 50-period EMA of closing prices; MACD calculated as the 12-period EMA minus the 26-period EMA, with a 9-period EMA signal line.
- Entry signal: while flat, the completed close crosses above its 50-period EMA: the previous close was at or below its previous EMA, and the current close is above its current EMA. MACD must also be above its signal line.
- Entry order: simulate a buy at the next available session’s open, including the chosen slippage model. Allocate 10% of account equity, subject to available cash and the selected whole-share or fractional-share policy. Do not add to an open position.
- Exit signal: if a completed close is below the 50-period EMA, exit at the next available session’s open.
- Protective stop: use a stop-market order 5% below the actual entry fill, active after entry. Verify that the simulation makes it active when intended, including on the entry bar. A gap through it fills according to the execution model, not automatically at the stop price.
- End-of-test policy: stop admitting new signals at the chosen cutoff, report any open position separately at the final available close, and do not quietly count an unfilled pending order as a completed trade.
The percentages and lengths above are example settings. The allocation is not the amount at risk. This baseline has no profit target and allows overnight holding, including earnings dates. If you add an earnings exclusion, trailing stop, maximum holding period, or portfolio ranking rule, document it as a new version and test it separately.
4. Separate allocation from planned risk
Suppose a hypothetical $50,000 account allocates 10% to a stock bought at $100. That is a $5,000 position, or 50 shares before fees. A 5% stop is $95, so planned price risk is 50 × $5 = $250, or 0.5% of the account. It is not 10% account risk.
If you instead start with a $200 risk budget and the same $5 stop distance, the risk-based size is 40 shares, before allowing for costs and exposure limits:
Shares = planned cash risk ÷ (entry price − stop price)
For whole shares, round down. Then check available cash, maximum allocation, and total exposure across other positions. Several stocks in the same sector can lose together; separate per-trade budgets do not establish a portfolio loss ceiling.
If the first example gaps down and the stop executes at $90, the 50 shares lose $500 before fees. The SEC’s stop-order bulletin explains that the stop price is not a guaranteed execution price. A stop-limit order controls the permitted price but can remain unfilled.
A 2R target with a 1R loss would break even at a one-third win rate before costs if every outcome matched those amounts. Costs, gaps, and partial exits change that calculation. A favorable target-to-stop ratio alone does not ensure profitability.
5. Build and review the strategy with Quant
Use the Quant strategy workflow to describe the rules, sizing, and timing. Ask it to expose inputs for the settings you intend to compare. Open Code, review the implementation, and click Run. Use the settings gear for Inputs and simulation Properties, including capital, order size, commissions, slippage, and pyramiding.
Review a few trades manually before judging the aggregate result. Did the entry occur after the signal became available? Did the stop use the actual fill? Was its order active on the entry bar? Did a session gap receive a realistic execution? Fixing a syntax error does not answer these trading-logic questions.
The backtest viewer provides summary metrics and more detailed performance and trade analysis. Review net profit, trade count, win rate, drawdown, and profit factor together. Save useful runs with their symbol, timeframe, inputs, and properties so comparisons remain reproducible. A run on one chart does not establish the behavior of a multi-stock portfolio sharing the same capital.
6. Check stock data and backtest biases
- Data coverage: LuxAlgo’s data documentation identifies Cboe EDGX as its US-equity source and distinguishes regular from extended sessions. Do not assume a venue-specific volume series represents all US trading volume.
- Corporate actions: document split and dividend treatment. Confirm that signals, fills, and the comparison benchmark use a coherent convention. Avoid counting dividends twice.
- Stock selection: a test using only today’s successful stocks can omit companies that failed, delisted, or left an index. A single chosen stock is a case study, not proof that a selection strategy works across the market.
- Execution: include costs and test worse slippage. Historical candles alone may not resolve the precise sequence of prices inside a bar. For short strategies, add borrow availability and costs rather than assuming every stock can always be shorted.
- Comparison: compare the same dates and capital convention with a relevant baseline. Report time invested and idle cash alongside returns; lower exposure can explain lower drawdown.
For example, TradingView’s dividend-adjustment documentation explains how its adjusted chart reflects dividends. That is a platform-specific data choice; verify the corresponding convention in any other environment rather than assuming charts are interchangeable.
7. Validate before expanding the strategy
Develop the idea on an earlier period, freeze its rules, and evaluate a later period you did not use to tune it. Compare neighboring parameter values and different market conditions. Do not keep retuning on that later period while continuing to call it an untouched test.
Keep a record of every variant, including rejected ones. A filter that produces a better headline result from only a handful of trades may have reduced the evidence rather than improved the strategy. More tests also create more opportunities to find a lucky historical fit.
Forward observation or paper trading can help check signal timing and operational details, although simulated fills still differ from live trading. Record discrepancies and review them before changing the rules. Build confidence in the process through reproducible evidence, with position size and risk limits set separately from the appeal of a backtest.
Read next