Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 61

Silver Bullet Alert Script in Python

Recommended resources

Hello! Welcome back to our journey into ICT and algorithmic trading.

In our last lesson, you built a script to find high-probability trade setups by identifying the confluence of an Optimal Trade Entry (OTE) zone and a Fair Value Gap (FVG). This taught your script where to look for a trade. Now, we're going to add the crucial dimension of when.

Today's lesson focuses on one of the specific strategies you were interested in: the ICT Silver Bullet. Our goal is to build a Python script that alerts when Silver Bullet conditions are met, which are defined by both a specific time window and a particular price action pattern. This is a powerful, time-based strategy that looks for quick moves during periods of high liquidity.

By the end of this lesson, you'll have a script that can automatically monitor the market for these specific, time-sensitive opportunities.

Understanding the Silver Bullet Strategy

The Silver Bullet is a trading model that targets high-probability setups within three distinct one-hour windows each day. The core idea is to capitalize on a liquidity sweep followed by a market structure shift that leaves behind a Fair Value Gap (FVG) for a potential entry.

The sequence of events is typically:

  1. Time Window: The market enters a specific 1-hour Silver Bullet session.
  2. Liquidity Sweep: Price moves above a recent swing high or below a recent swing low, grabbing the liquidity resting there.
  3. Displacement & FVG: After the sweep, the price moves aggressively in the opposite direction, creating a clear FVG.
  4. Entry: The entry is taken when the price retraces back into this newly formed FVG.

These images clearly illustrate the concept and a real-world example.

ICT Silver Bullet Strategy Visual Explanation
A conceptual diagram of a bearish Silver Bullet setup. Price sweeps the "Day's high" (liquidity sweep), has a Market Structure Shift (MSS) downwards, leaves an FVG, and provides a short entry.
ICT Silver Bullet Strategy Example on GBPJPY
A practical example on a GBPJPY chart. Within the 10:00-11:00 window, price sweeps liquidity below a recent low, then rallies, leaving a bullish FVG for a long entry.

Defining the Silver Bullet Conditions in Code

To automate this, we need to translate the strategy's rules into code. We will focus on two primary conditions: Time and Price.

1. The Time Condition

The Silver Bullet strategy is only valid during specific times. A great reference for this is the description of a TradingView script dedicated to this concept.

Scripts Search Results for "fvg"

This TradingView script description clearly outlines the specific time windows for the Silver Bullet strategy. We will use these times as the foundation for our script's time-based filter.

Read the section titled 'Silver Bullet' to identify the three one-hour time windows when the strategy is active. Note that these are specified in New York Time.

As you'll see in the resource, the key windows (in NY time, UTC-4/UTC-5) are:

  • 10:00 - 11:00 AM (The "AM" Silver Bullet)
  • 03:00 - 04:00 AM (Corresponds to the London Open killzone)
  • 02:00 - 03:00 PM (The "PM" Silver Bullet)

In Python, we can handle these time-based rules by ensuring our price data's index is a timezone-aware DatetimeIndex. This allows us to easily filter for data within these specific hourly windows.

2. The Price Condition

The price component involves identifying an FVG that forms after a liquidity sweep. We can leverage the smartmoneyconcepts library we've used before to help with this.

joshyattridge/smart-money-concepts

We will once again use the smartmoneyconcepts library. This time, we'll focus on its ability to identify not just FVGs, but also sessions, which can help us structure our time-based analysis.

Briefly review the 'Fair Value Gap (FVG)' section as a refresher. Then, look at the 'Sessions' section. While we will use a direct time-filtering method in our script, seeing this function shows how central the concept of sessions is in automated ICT analysis.

Our script's logic will be:

  1. Define the liquidity range (e.g., the high and low of the hour before the Silver Bullet window).
  2. During the Silver Bullet hour, monitor if this high or low is breached (the liquidity sweep).
  3. Once a sweep occurs, scan for a new FVG in the opposite direction using smc.fvg().
  4. If such an FVG appears, generate an alert.

Building the Silver Bullet Alert Script

Let's put this all together into a Python script. This script will load sample data, identify the AM Silver Bullet window, look for the sweep-then-FVG pattern, and print an alert if the conditions are met.

A quick note on timezones: Dealing with time is critical. For this script, we'll convert our data to the 'America/New_York' timezone to match the strategy's definition.

import pandas as pd
from smartmoneyconcepts import smc
import pytz # A library for handling timezones

def find_silver_bullet_signals(df: pd.DataFrame, sb_hour: int):
    """
    Scans a DataFrame for ICT Silver Bullet setups within a specific hour.

    Args:
        df (pd.DataFrame): OHLC data with a timezone-aware DatetimeIndex.
        sb_hour (int): The starting hour of the Silver Bullet window (e.g., 10 for 10:00 AM).
    """
    print(f"\n--- Scanning for Silver Bullet signals in the {sb_hour}:00 hour ---")

    # 1. Define the time windows
    liquidity_window_start = pd.to_datetime(df.index[0].date()) + pd.Timedelta(hours=sb_hour - 1)
    liquidity_window_end = liquidity_window_start + pd.Timedelta(hours=1)
    
    sb_window_start = pd.to_datetime(df.index[0].date()) + pd.Timedelta(hours=sb_hour)
    sb_window_end = sb_window_start + pd.Timedelta(hours=1)

    # Ensure timezone information is consistent
    tz = df.index.tz
    liquidity_window_start = liquidity_window_start.tz_localize(tz)
    liquidity_window_end = liquidity_window_end.tz_localize(tz)
    sb_window_start = sb_window_start.tz_localize(tz)
    sb_window_end = sb_window_end.tz_localize(tz)

    # 2. Identify the liquidity to be targeted
    liquidity_df = df[(df.index >= liquidity_window_start) & (df.index < liquidity_window_end)]
    if liquidity_df.empty:
        print(f"No data for liquidity window ({sb_hour-1}:00). Skipping.")
        return

    buy_side_liquidity = liquidity_df['high'].max()
    sell_side_liquidity = liquidity_df['low'].min()
    print(f"Liquidity Range ({sb_hour-1}:00): High={buy_side_liquidity:.5f}, Low={sell_side_liquidity:.5f}")

    # 3. Scan the Silver Bullet window for the pattern
    sb_df = df[(df.index >= sb_window_start) & (df.index < sb_window_end)].copy()
    if sb_df.empty:
        print(f"No data for Silver Bullet window ({sb_hour}:00). Skipping.")
        return

    # Add FVG data to our Silver Bullet window slice
    fvg_data = smc.fvg(sb_df)
    sb_df = pd.concat([sb_df, fvg_data], axis=1)

    buy_sweep_confirmed = False
    sell_sweep_confirmed = False

    for index, row in sb_df.iterrows():
        # Check for liquidity sweeps
        if not buy_sweep_confirmed and row['high'] > buy_side_liquidity:
            print(f"  -> Buyside liquidity swept at {index.time()} (Price: {row['high']:.5f})")
            buy_sweep_confirmed = True
        
        if not sell_sweep_confirmed and row['low'] < sell_side_liquidity:
            print(f"  -> Sellside liquidity swept at {index.time()} (Price: {row['low']:.5f})")
            sell_sweep_confirmed = True

        # After a sweep, look for an FVG in the opposite direction
        fvg_type = row['FVG']
        
        # Bearish setup: Buyside sweep followed by a bearish FVG
        if buy_sweep_confirmed and fvg_type == -1:
            print(f"\n*** ALERT: Bearish Silver Bullet Setup! ***")
            print(f"  - Time: {index.time()}")
            print(f"  - Bearish FVG detected from {row['Bottom']:.5f} to {row['Top']:.5f}")
            print(f"  - This is a potential SHORT entry opportunity.\n")
            return # Stop after finding the first signal in the window
        
        # Bullish setup: Sellside sweep followed by a bullish FVG
        if sell_sweep_confirmed and fvg_type == 1:
            print(f"\n*** ALERT: Bullish Silver Bullet Setup! ***")
            print(f"  - Time: {index.time()}")
            print(f"  - Bullish FVG detected from {row['Bottom']:.5f} to {row['Top']:.5f}")
            print(f"  - This is a potential LONG entry opportunity.\n")
            return # Stop after finding the first signal in the window

# --- Example Usage ---

# Create sample 1-minute data for EUR/USD on a specific morning
# This data simulates a liquidity sweep and FVG during the 10:00 AM window
timestamps = pd.to_datetime(pd.date_range('2023-10-10 09:00:00', '2023-10-10 10:59:00', freq='1min'))
data = {
    'open': [1.0550 - (i*0.00001) for i in range(120)],
    'high': [1.0552 - (i*0.00001) for i in range(120)],
    'low': [1.0548 - (i*0.00001) for i in range(120)],
    'close': [1.0550 - (i*0.00001) for i in range(120)],
}
ohlc_df = pd.DataFrame(data, index=timestamps)
ohlc_df.columns = ['open', 'high', 'low', 'close']

# --- Simulate the Silver Bullet Pattern ---
# 9:00-10:00: Create a clear low (sell-side liquidity)
# 10:05: Sweep that low
ohlc_df.loc['2023-10-10 10:05:00', 'low'] = ohlc_df.loc['2023-10-10 09:00:00':'2023-10-10 09:59:00']['low'].min() - 0.0001

# 10:07-10:09: Create a strong upward move that leaves a bullish FVG
ohlc_df.loc['2023-10-10 10:07:00', 'high'] = 1.05400 # Prev candle low
ohlc_df.loc['2023-10-10 10:08:00', 'low'] = 1.05410 # FVG candle (bullish)
ohlc_df.loc['2023-10-10 10:08:00', 'high'] = 1.05480
ohlc_df.loc['2023-10-10 10:09:00', 'low'] = 1.05490 # Next candle high

# Set the timezone to New York time
ny_tz = pytz.timezone('America/New_York')
ohlc_df = ohlc_df.tz_localize('UTC').tz_convert(ny_tz)

# Run the scanner for the AM Silver Bullet hour (10:00)
find_silver_bullet_signals(ohlc_df, sb_hour=10)

When you run this code, it will print out the process of identifying the liquidity range from 9-10 AM, detecting the sweep of the low just after 10 AM, and then firing an alert when it finds the bullish FVG, just as the strategy dictates.

Test your understanding!

You are watching the market during the London Open Silver Bullet window (03:00 - 04:00 NY Time). The high of the previous hour (02:00 - 03:00) was 1.25100.

At 03:15, the price wicks up to 1.25105 and then immediately sells off.
At 03:18, your script detects a bearish FVG has formed.

Based on the logic of our script, what kind of alert would be generated? A bullish signal, a bearish signal, or no signal at all? Why?

Show answer

A bearish signal would be generated.

Here's the breakdown of why:

  1. Time: The events occur within the 03:00 - 04:00 Silver Bullet window.
  2. Liquidity Sweep: The price move to 1.25105 at 03:15 constitutes a sweep of the buy-side liquidity resting above the previous hour's high of 1.25100.
  3. FVG Formation: After the sweep, a bearish FVG formed.

This sequence perfectly matches the criteria for a bearish Silver Bullet setup: a buy-side liquidity sweep followed by a displacement move that creates a bearish FVG. Our script would trigger a "Bearish Silver Bullet Setup!" alert.


Conclusion

Excellent work! You have now successfully built a Python script that automates the detection of the time-sensitive ICT Silver Bullet strategy. This is a major step in your journey toward building trading bots, as it combines time-based rules with price action analysis.

Key Takeaways:

  • The Silver Bullet strategy is defined by specific time windows and a price pattern (liquidity sweep followed by an FVG).
  • Handling timezones correctly in Python (using pytz and timezone-aware DataFrames) is essential for time-based strategies.
  • We created a logical flow: define a liquidity range, detect a sweep of that range within the SB window, and then scan for a resulting FVG.
  • The smartmoneyconcepts library continues to be a valuable tool, saving us the effort of coding FVG detection from scratch.

Preview for the Next Lesson:
So far, our scripts are excellent at generating signals. But a signal is only the first part of a trade. The next critical question is how to manage the risk. In our next lesson, we will begin the "Systematic Risk and Trade Management" module by learning how to set a stop loss based on ICT invalidation levels, such as placing it just beyond the swing low or high that created the setup.