Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
249 views5 pages

SMC AI Trading Bot Script

Uploaded by

vigneshjadhav35
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
249 views5 pages

SMC AI Trading Bot Script

Uploaded by

vigneshjadhav35
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

AI Trading Bot with SMC for XAU/USD - Video Script

Title: Build an AI Trading Bot using Smart Money Concepts (SMC) for XAU/USD in Python

[Intro Slide | 0:00 - 0:30]

"Welcome to this deep-dive tutorial on building an AI trading bot using Smart Money Concepts (SMC) for

XAU/USD, also known as gold versus the US dollar. If you're into forex or commodities trading and want

to combine institutional trading techniques with machine learning, you're in the right place."

[Slide: What You'll Learn | 0:30 - 1:00]

- How to get live gold data in Python

- Detect Smart Money structure: HH, LL, BOS, OB, FVG

- Train a machine learning model to predict trades

- Backtest the strategy

- Build your own bot logic

"By the end, you'll have a working foundation of a strategy that blends the power of price action with

predictive AI models."

[Section 1: Setup & Data Collection | 1:00 - 2:30]

Voice-over:

"First, we install the required libraries using pip. These will let us collect gold price data, visualize it, and

run our AI models."

Code:

pip install yfinance pandas numpy matplotlib scikit-learn ta

"Next, we fetch hourly XAU/USD data using Yahoo Finance."

import yfinance as yf

data = yf.download("XAUUSD=X", start="2023-01-01", end="2025-07-01", interval="1h")

data = data[['Open', 'High', 'Low', 'Close', 'Volume']].reset_index()


AI Trading Bot with SMC for XAU/USD - Video Script

[Section 2: Market Structure (HH, LL, BOS) | 2:30 - 5:00]

Voice-over:

"Now we detect swing points: higher highs and lower lows. Then, we'll track breaks of structure (BOS)."

Code:

def detect_swings(df):

df['HH'] = (df['High'] > df['High'].shift(1)) & (df['High'] > df['High'].shift(-1))

df['LL'] = (df['Low'] < df['Low'].shift(1)) & (df['Low'] < df['Low'].shift(-1))

return df

def detect_bos(df):

trend = None

last_hh = last_ll = None

bos = []

for i in range(len(df)):

row = df.iloc[i]

if row['HH']: last_hh = row['High']

if row['LL']: last_ll = row['Low']

if last_hh and row['Close'] > last_hh and trend != 'bullish':

bos.append('BOS UP')

trend = 'bullish'

elif last_ll and row['Close'] < last_ll and trend != 'bearish':

bos.append('BOS DOWN')

trend = 'bearish'

else:

bos.append("")

df['BOS'] = bos

return df

# Apply it

data = detect_swings(data)

data = detect_bos(data)
AI Trading Bot with SMC for XAU/USD - Video Script

[Section 3: Order Block Detection | 5:00 - 7:00]

Voice-over:

"Order blocks are key SMC zones where institutions place orders. We'll find the last opposite candle

before a BOS."

Code:

def detect_order_blocks(df):

bullish_obs, bearish_obs = [], []

for i in range(2, len(df)):

if df['BOS'].iloc[i] == "BOS UP":

for j in range(i-1, i-4, -1):

if df['Open'].iloc[j] > df['Close'].iloc[j]:

bullish_obs.append(df.iloc[j])

break

elif df['BOS'].iloc[i] == "BOS DOWN":

for j in range(i-1, i-4, -1):

if df['Open'].iloc[j] < df['Close'].iloc[j]:

bearish_obs.append(df.iloc[j])

break

return pd.DataFrame(bullish_obs), pd.DataFrame(bearish_obs)

bullish_ob_df, bearish_ob_df = detect_order_blocks(data)

[Section 4: Fair Value Gaps (FVG) | 7:00 - 9:00]

Voice-over:

"Next up are Fair Value Gaps or FVGs, which are imbalances that price often returns to fill."

Code:

def detect_fvgs(df):

bullish_fvgs, bearish_fvgs = [], []

for i in range(2, len(df)):


AI Trading Bot with SMC for XAU/USD - Video Script

prev = df.iloc[i-2]

curr = df.iloc[i]

if curr['Low'] > prev['High']:

bullish_fvgs.append({'Datetime': curr['Datetime'], 'GapLow': prev['High'], 'GapHigh': curr['Low']})

if curr['High'] < prev['Low']:

bearish_fvgs.append({'Datetime': curr['Datetime'], 'GapLow': curr['High'], 'GapHigh':

prev['Low']})

return pd.DataFrame(bullish_fvgs), pd.DataFrame(bearish_fvgs)

bullish_fvg_df, bearish_fvg_df = detect_fvgs(data)

[Section 5: Machine Learning Prediction | 9:00 - 12:00]

Voice-over:

"We now use these features to train a machine learning model that predicts the next price movement."

Code:

from sklearn.ensemble import RandomForestRegressor

from sklearn.model_selection import train_test_split

from sklearn.metrics import mean_squared_error

# Example feature set

data['SMA50'] = data['Close'].rolling(window=50).mean()

data['SMA200'] = data['Close'].rolling(window=200).mean()

data.dropna(inplace=True)

features = data[['Close', 'SMA50', 'SMA200']]

labels = data['Close'].shift(-1)

X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.2, shuffle=False)

model = RandomForestRegressor()

model.fit(X_train, y_train)
AI Trading Bot with SMC for XAU/USD - Video Script

predictions = model.predict(X_test)

print("MSE:", mean_squared_error(y_test, predictions))

[Section 6: Create Trade Signal | 12:00 - 13:30]

Voice-over:

"Finally, we generate a trade signal based on the AI model's prediction and combine it with SMC context."

Code:

latest_features = features.iloc[-1].values.reshape(1, -1)

next_price = model.predict(latest_features)[0]

current_price = data['Close'].iloc[-1]

if next_price > current_price:

print("AI Signal: BUY")

elif next_price < current_price:

print("AI Signal: SELL")

else:

print("AI Signal: HOLD")

[Outro | 13:30 - 14:00]

"And that’s it! You’ve now built a Smart Money Concept trading bot foundation in Python for XAU/USD.

From order blocks to fair value gaps to machine learning — all in one system."

"If you found this valuable, leave a like and comment below if you want the full deployment to

MetaTrader or TradingView via webhook."

You might also like