Academy/How Algorithms Pick Stocks & Options/Entry Timing: When to Pull the Trigger
How Algorithms Pick Stocks & OptionsLesson 3

Entry Timing: When to Pull the Trigger

A great stock at the wrong time is a losing trade. Learn how algorithms determine the exact moment to enter a position.

11 minute read
4 key takeaways

Entry Timing: When to Pull the Trigger

A stock can be high quality, cheap, and scoring top marks in your model — yet still be a losing trade if you buy at the wrong moment. Entry timing is the bridge between "I want to own this" and "I am buying right now." Algorithms need a crisp, testable rule for each entry type.

Entry Trigger Types

Trigger TypeHow It WorksBest For
BreakoutBuy when price closes above N-day highTrend-following, momentum
Pullback to MABuy when price dips to moving average in an uptrendTrend-following with better entry
RSI OversoldBuy when RSI < 30 (or 40 for less aggressive)Mean reversion
Earnings CatalystBuy X days before earnings on positive revisionEvent-driven momentum
Volatility ContractionBuy Bollinger squeeze breakoutMomentum after consolidation

The Anatomy of a Mechanical Entry Rule

Every entry rule has three components: a condition (what must be true), a confirmation (a second check to reduce false signals), and an execution price (exactly what price to fill at).

python
def should_enter(ticker):
    price    = get_close(ticker)
    high_20  = get_highest_close(ticker, 20)   # 20-day high
    sma_50   = sma(ticker, 50)
    volume   = get_volume(ticker)
    avg_vol  = average_volume(ticker, 20)

    # Condition: price breaks above 20-day high
    condition = price >= high_20

    # Confirmation 1: price is above 50-day SMA (in an uptrend)
    trend_ok  = price > sma_50

    # Confirmation 2: breakout on above-average volume (real buying)
    volume_ok = volume > avg_vol * 1.5

    return condition and trend_ok and volume_ok

# Execution: enter at next open after signal fires
# This avoids chasing intraday moves on the signal bar

Look-Ahead Bias in Entry Rules

If your signal uses today's close price and you also execute at today's close, you are cheating — you cannot know the close price before the day ends. Always execute at the NEXT open or NEXT close after the signal fires. This single mistake inflates backtests enormously.

Partial Fills and Scaling In

Rather than deploying full position size on a single entry, many algorithms scale in: buy 50% on the initial signal, then add the remaining 50% if the price holds above the entry level for 3–5 days. This reduces cost basis on positions that falter slightly before moving.

Stop Loss as Part of the Entry Rule

The entry rule and the stop loss are defined together, not separately. Before entering, the algorithm knows exactly where it will exit if wrong. The distance from entry to stop determines position size (see Track 1: Risk Management).

ATR-Based Stops

Instead of a fixed % stop, many algorithms use Average True Range (ATR) to set stops proportional to the stock's volatility. A 2×ATR stop is farther from entry on a volatile stock (TSLA) and tighter on a stable one (JNJ), keeping dollar risk constant across the portfolio.

python
def calculate_entry_package(ticker, portfolio_value, risk_pct=0.01):
    entry_price = get_next_open(ticker)
    atr         = average_true_range(ticker, 14)

    stop_price  = entry_price - 2 * atr          # 2×ATR below entry
    risk_per_share = entry_price - stop_price

    # Risk 1% of portfolio on this trade
    dollar_risk = portfolio_value * risk_pct
    shares      = int(dollar_risk / risk_per_share)

    return {
        'entry': entry_price,
        'stop':  stop_price,
        'shares': shares,
        'max_loss': dollar_risk,
    }
Key Takeaways
  • Screening and scoring tell you WHAT to buy; entry timing tells you WHEN
  • Trend confirmation prevents buying into falling knives
  • Volume confirmation filters out false breakouts
  • A defined entry rule makes the strategy fully mechanical and testable