Turn Your Stock-Picking Logic into Buy Rules: Moving Averages, ADX, Breakouts

Turning stock-picking logic into buy rules means translating instincts like "enter once it holds the average" or "buy the breakout on volume" into conditions a machine can check: an indicator, a comparison operator, and a threshold, combined with AND / OR. Only a rule written that clearly can be backtested, scanned daily, and trusted when your judgment is at its worst. This guide gives you a translation table and one example you can check with a calculator.

Key takeaways

  • An executable rule has exactly three parts: indicator, operator, threshold. If you cannot name all three, the logic is still a feeling, not a rule.
  • Moving averages judge direction, ADX judges trend strength, breakouts judge whether momentum has started. They answer different questions and are usually combined.
  • AND makes a rule stricter and produces fewer signals; OR makes it looser and produces more. Build the skeleton with AND, add OR sparingly.
  • Every buy rule needs a paired exit rule. Without one, a backtest cannot be computed and a live trade has no way out.
  • Write the rule, backtest it, then put it in the daily scan. Never go straight to real money.

Why intuition cannot be used as-is

"It looks ready to move" or "this one has stabilised" are often right in the moment, but they have two fatal flaws. They cannot be verified: you cannot go back 300 trading days and ask, day by day, "did it look ready then?" And they cannot be reproduced: your standard for "stabilised" today is probably not last month's, nor the one you will use right after a loss.

Writing rules freezes the standard. Only then can you answer three questions: has this logic worked historically, how often does it fire, and where do I get out afterwards?

The three most-used technical conditions

Moving averages: direction. Price above the 20-day average says the short term is bullish; MA20 above MA50 says the medium-term trend is up. Averages are simple and visual, but they lag, confirming a move only after it is under way.

ADX: trend strength. ADX ignores direction and measures only how strong a trend is. Above 25 usually means a trend worth following; below 20 is mostly chop, where breakouts tend to fail. ADX works best as a filter, not as a buy reason on its own. See using ADX to filter false breakouts.

Breakouts: momentum onset. A close at a new 20-day high often marks money starting to move in. A breakout alone is noisy, so it is usually paired with volume (volume versus the 20-day average) and ADX. If you do not want to chase, use distance from the 20-day high to confine entries to a narrow band near the high.

Remember it this way: averages say which side to stand on, ADX says whether standing there is worth it, breakouts say whether now is the time to move.

Translation table: what you say → indicator and threshold

This table maps common spoken logic to Stock Compass indicator ids and thresholds. The thresholds are starting points, not answers; adjust them after backtesting on your own market and watchlist.

What you sayAs a conditionMeaning
"Holding above the 20-day line"price_vs_ma20 > 0 AND days_above_ma20 >= 3Not just above it, but above it for several consecutive days
"Breakout on volume"is_20d_breakout == 1 AND vol_vs_avg20d > 1.5New 20-day high with volume at least 1.5x the 20-day average
"Clear trend"adx_14 > 25 AND ma20_above_ma50 == 1The trend has strength and points up
"Don't chase"pct_from_high_20d >= -6 AND return_5d < 10Near the high, but no vertical run in the last 5 days
"Not right before earnings"days_to_next_earnings > 5At least 5 trading days before the next report
"The market is cooperating"market_index_vs_ma50_pct > 0The market's index is above its own 50-day average
"No falling knives"ma20_slope_5d_pct > 0The 20-day average has risen over the last 5 days

One test for every cell: could an emotionless machine answer "yes" or "no" after the close? If not, split it further.

AND narrows, OR widens

AND means "all of these must be true." Every extra AND condition removes another batch of stocks: fewer signals, but each one backed by more reasons. OR means "any one of these is enough." Every extra OR branch adds another batch: broader coverage, more uneven quality.

A hypothetical scenario: your watchlist has 200 names. "Is a 20-day breakout" might return 15 on a given day; AND "volume ratio > 1.5" might cut that to 6; AND "ADX > 25" might leave 2. Going the other way, if you join "20-day breakout" and "RSI < 35 bounce" with OR, you might get 20 or more a day, mixing two completely different market situations.

Stock Compass rules have exactly these two layers: conditions inside a group are joined with AND (innerOp), groups with OR (outerOp). A useful habit: one group per entry idea, with all its necessary conditions under AND. If you truly have two entry ideas, write two groups joined by OR and backtest each separately.

One example you can check with a calculator

Suppose a US stock closed at 52.40 dollars last Thursday, and the highest close of the prior 20 trading days was 51.80, so is_20d_breakout == 1. Volume that day was 3.2 million shares against a 20-day average of 1.9 million, so vol_vs_avg20d = 3.2 / 1.9 ≈ 1.68, above 1.5. The 20-day average sits at 49.50, so price_vs_ma20 = (52.40 − 49.50) / 49.50 ≈ 5.9%. ADX reads 28, MA20 is above MA50, the next earnings report is 23 days out, and the index is 2.1% above its 50-day average. Every buy condition is true at once; the rule fires.

Now the exit and the position. One of your exit rules is "leave if the floating loss exceeds 6%," which puts the stop at 52.40 × (1 − 0.06) ≈ 49.26, just under the 20-day average, which makes sense structurally. With a 100,000-dollar account and 1% risk per trade, the risk budget is 1,000 dollars. Risk per share is 52.40 − 49.26 = 3.14, so 1,000 / 3.14 ≈ 318 shares; round down to 300 shares, a position of 300 × 52.40 = 15,720 dollars, about 15.7% of the account.

Every figure in that paragraph can be verified on a calculator. That is what "executable" means: the trigger, the stop, and the share count are all fixed before the order, not improvised mid-session. For the sizing arithmetic see position sizing by risk per trade.

Every buy rule needs a paired exit rule

A strategy with only a buy rule is incomplete. A backtest has to know where each trade ends, or it cannot compute return, drawdown, or win rate. Live trading needs it even more: the moment you are losing money is the moment you are least able to decide on the spot.

Exit rules usually come from three sources, which can sit side by side with OR:

  1. Risk stop: floating_loss_pct > 6. The buy thesis may still stand, but price has proven you wrong.
  2. Thesis failure: price_vs_ma20 < 0 AND holding_days >= 10. The original "holding above the average" reason no longer holds.
  3. Event avoidance: days_to_next_earnings <= 2, if you do not intend to hold through the report.

Writing buy and exit as a pair also lets you check the buy rule from the other side: if the exit keeps firing almost immediately, the entry itself is too aggressive. For how to write stops and targets, see take-profit and stop-loss rules.

How to set this up in Stock Compass

Here is the complete strategy from the example: one buy group, three exit groups. Add the conditions one at a time in the strategy editor or paste this JSON directly.

{
  "name": "Volume breakout with trend filter",
  "market": "us",
  "rules": {
    "buy": {
      "v": 2,
      "outerOp": "OR",
      "groups": [
        {
          "innerOp": "AND",
          "conditions": [
            { "indicator": "is_20d_breakout", "operator": "==", "value": 1 },
            { "indicator": "vol_vs_avg20d", "operator": ">", "value": 1.5 },
            { "indicator": "adx_14", "operator": ">", "value": 25 },
            { "indicator": "ma20_above_ma50", "operator": "==", "value": 1 },
            { "indicator": "days_to_next_earnings", "operator": ">", "value": 5 },
            { "indicator": "market_index_vs_ma50_pct", "operator": ">", "value": 0 }
          ]
        }
      ]
    },
    "add": { "v": 2, "outerOp": "OR", "groups": [] },
    "trim": { "v": 2, "outerOp": "OR", "groups": [] },
    "exit": {
      "v": 2,
      "outerOp": "OR",
      "groups": [
        {
          "innerOp": "AND",
          "conditions": [
            { "indicator": "floating_loss_pct", "operator": ">", "value": 6 }
          ]
        },
        {
          "innerOp": "AND",
          "conditions": [
            { "indicator": "price_vs_ma20", "operator": "<", "value": 0 },
            { "indicator": "holding_days", "operator": ">=", "value": 10 }
          ]
        },
        {
          "innerOp": "AND",
          "conditions": [
            { "indicator": "days_to_next_earnings", "operator": "<=", "value": 2 }
          ]
        }
      ]
    }
  }
}

Buy group (all must be true):

  • is_20d_breakout == 1: close at a new 20-day high.
  • vol_vs_avg20d > 1.5: volume at least 1.5x the 20-day average.
  • adx_14 > 25: trend strength is sufficient.
  • ma20_above_ma50 == 1: medium-term direction is up.
  • days_to_next_earnings > 5: skip the week before earnings.
  • market_index_vs_ma50_pct > 0: the market index is above its 50-day average.

Exit groups (any one is enough):

  • floating_loss_pct > 6: floating loss beyond 6%, the risk stop.
  • price_vs_ma20 < 0 AND holding_days >= 10: back below the 20-day average after 10 or more days held, thesis failed.
  • days_to_next_earnings <= 2: out two days before earnings.

After saving, run a backtest and check whether trigger count, win rate, and maximum drawdown are within what you can live with. Only then attach the strategy to the daily scan. After each close it tells you which stocks met the conditions you wrote; it scans your rules, it does not recommend stocks.

Common mistakes

  • Writing the buy without the exit. A strategy with no exit cannot be backtested and has no way out in live trading.
  • Copying thresholds from someone else. ADX 25 and a 1.5x volume ratio are common starting points; different markets and different volatility levels need different numbers.
  • Stacking too many conditions. Six or seven ANDs might fire two or three times a year, too small a sample for the backtest to mean anything.
  • Using OR as insurance. Joining unrelated entry ideas with OR only hides which one is actually making money.
  • Going live as soon as it is written. Writing the rule is step one; a passed backtest is the minimum bar for trying it.

Summary

Turning stock-picking logic into buy rules comes down to replacing every "feeling" with indicator + operator + threshold. Averages judge direction, ADX judges strength, breakouts judge onset; AND narrows, OR widens; every buy gets a paired exit. If you can write it clearly you can backtest it, and only a backtest tells you whether the logic deserves real money.

FAQ

Moving averages, ADX, or breakouts — which should I use?

They solve different problems: moving averages judge direction, ADX judges trend strength, and breakouts judge whether momentum has started. Trend strategies often combine all three, for example MA20 above MA50 AND ADX > 25 AND a new 20-day high. Pick the one that matches the question you are actually asking, then add the others as filters.

Are more indicators better?

No. Every extra AND condition removes signals, and past a point the backtest has too few trades to say anything reliable. Start with two or three core conditions, backtest, and only add a filter when it fixes a specific failure you can see in the results.

Where do thresholds like ADX > 25 or volume 1.5x come from?

They are widely used conventions, not laws. A low-volatility large cap and a small cap that moves 5% a day will not share the same sensible thresholds. Treat the numbers in this guide as starting points, then check in a backtest whether moving them a little changes the results a lot; if it does, the rule is fragile.

Can I write the exit rule later, once I am in the trade?

You can, but you will be deciding under the worst possible conditions: with money on the line and a loss on the screen. Writing the exit alongside the buy also makes the backtest possible in the first place, because a backtest needs to know where every trade ends. Pair them from day one.

Does the same rule work in Hong Kong, US, and mainland China markets?

The structure carries over, the thresholds usually do not. Volume patterns, typical daily ranges, and earnings calendars differ by market, so a rule tuned on US names should be re-backtested before it is used on Hong Kong or A-shares. Stock Compass lets you set the market per strategy so each can carry its own thresholds.