How to Build a Trading Strategy Using Mboum Technical Indicators

Algorithmic trading is the process of using computer programs to follow a defined set of instructions for placing a trade. These instructions are often based on timing, price, quantity, or a mathematical model. Unlike subjective manual trading, algorithmic trading allows for automated, disciplined execution based on hard data.

In this tutorial, we will build a classic "Golden Cross" trading strategy using Python. This strategy generates a buy signal when a short-term moving average crosses above a long-term moving average, indicating potential upward momentum. We will utilize Mboum's specialized technical indicator endpoints to retrieve the necessary data without calculating complex mathematics manually.

👉 To follow along and generate your own API key, visit: https://mboum.com/pages/api


The Data Source

To execute a Golden Cross strategy, we need to compare two specific data points:

  • 50-day Simple Moving Average (SMA)

  • 200-day Simple Moving Average (SMA)

We will use the Technical Indicator SMA endpoint. This endpoint calculates the simple moving average for a specific ticker over a defined time period and interval, returning the data ready for immediate analysis.

Endpoint

GET /v1/markets/indicators/sma

Documentation: https://docs.mboum.com#stocks-options-GETapi-v1-markets-indicators-sma

Key Parameters

  • ticker – The symbol of the asset (e.g., AAPL or BTC-USD)

  • interval – The time interval between data points (e.g., 1d for daily candles)

  • time_period – The number of data points used to calculate the average (e.g., 50 or 200)

  • series_type – The price point to use, typically close

  • limit – How many of the latest values to return (1 to 1000, default 50)

The Response

The response has a meta object that echoes your request and a body list. Each item in body holds a Unix timestamp in seconds and the value, keyed by the indicator name (SMA here). The list runs from oldest to newest, so the last item is the latest value. This is the real response for AAPL with time_period=50 and limit=2, with meta trimmed:

{
  "meta": { "symbol": "AAPL", "interval": "1d", "time_period": "50" },
  "body": [
    { "timestamp": 1795444200, "SMA": 342.127 },
    { "timestamp": 1795530600, "SMA": 342.582 }
  ]
}

If there is no data to return, the API answers with HTTP 200 and "success": false plus a message, and invalid parameters return HTTP 422. The script below checks for both.


Python Example: The Golden Cross Strategy

The following Python script fetches the 50-day and 200-day SMA values for Apple (AAPL). It compares the two most recent values of each average to detect a fresh crossover.

import requests
import json

# Configuration
API_KEY = "YOUR_AUTH_KEY"
BASE_URL = "https://api.mboum.com/v1/markets/indicators/sma"
TICKER = "AAPL"

def get_sma_data(ticker, period, interval="1d"):
    """
    Fetches SMA data for a specific period (e.g., 50 or 200).
    """
    headers = {
        "Authorization": f"Bearer {API_KEY}"
    }
    params = {
        "ticker": ticker,
        "interval": interval,
        "series_type": "close",
        "time_period": str(period),
        "limit": "2" # The previous value and the latest value
    }
    
    response = requests.get(BASE_URL, headers=headers, params=params)
    
    if response.status_code == 200:
        return response.json()
    else:
        print(f"Error fetching SMA {period}: {response.status_code}")
        return None

def last_two(response):
    """
    The response is {"meta": {...}, "body": [...]}. Each item in body is
    {"timestamp": ..., "SMA": ...}, ordered oldest to newest.
    Returns [previous, latest], or None when the API returned no data.
    """
    if response.get("success") is False or len(response.get("body", [])) < 2:
        return None
    return [item["SMA"] for item in response["body"][-2:]]

def evaluate_strategy():
    # Fetch SMA 50 (Short-term trend)
    sma_50_response = get_sma_data(TICKER, 50)
    
    # Fetch SMA 200 (Long-term trend)
    sma_200_response = get_sma_data(TICKER, 200)

    if not sma_50_response or not sma_200_response:
        print("Failed to retrieve indicator data.")
        return

    sma_50 = last_two(sma_50_response)
    sma_200 = last_two(sma_200_response)
    if not sma_50 or not sma_200:
        print("The API returned no indicator values.")
        return

    prev_50, current_50 = sma_50
    prev_200, current_200 = sma_200

    print(f"Analysis for {TICKER}:")
    print(f"SMA 50: {prev_50:.2f} -> {current_50:.2f} | SMA 200: {prev_200:.2f} -> {current_200:.2f}")

    # Logic Comparison: a cross is a change between two candles
    if prev_50 <= prev_200 and current_50 > current_200:
        print("Signal: BUY (Golden Cross Detected)")
    elif prev_50 >= prev_200 and current_50 < current_200:
        print("Signal: SELL (Death Cross Detected)")
    elif current_50 > current_200:
        print("Signal: HOLD (SMA 50 is above SMA 200, no new cross)")
    else:
        print("Signal: HOLD (SMA 50 is below SMA 200, no new cross)")

if __name__ == "__main__":
    evaluate_strategy()

Understanding the Logic

The script above performs two distinct API calls to the /v1/markets/indicators/sma endpoint. By modifying the time_period parameter, we treat the API as a calculation engine. This reduces the load on your application, as you do not need to fetch historical candle data and perform the rolling average mathematics locally.

The limit parameter is set to 2 because a cross is an event, not a state. SMA 50 sitting above SMA 200 only says which line is on top. A golden cross means SMA 50 was at or below SMA 200 on the previous candle and is above it on the latest one, so the script needs two values from each series. If you were backtesting this strategy, you would raise the limit (up to 1000) and step through the values in pairs.

Here is the output for AAPL on November 24, 2026. SMA 50 was already above SMA 200, so there was no new cross:

Analysis for AAPL:
SMA 50: 342.13 -> 342.58 | SMA 200: 303.60 -> 303.99
Signal: HOLD (SMA 50 is above SMA 200, no new cross)

Data Interpretation

  • Trend: Bullish
    Condition: SMA 50 was at or below SMA 200 on the previous candle and is above it now (golden cross)
    Action: Buy signal

  • Trend: Bearish
    Condition: SMA 50 was at or above SMA 200 on the previous candle and is below it now (death cross)
    Action: Sell signal

Reliable data latency is critical here. Using the 1d (daily) interval is standard for Golden Cross strategies, but for high-frequency trading, you might switch the interval to 5m or 15m to capture intraday momentum.


Practical Use Cases

This logic serves as the foundation for several sophisticated applications:

  • Paper Trading
    Before risking capital, you can run this script daily against a portfolio of tickers (using a loop) to track theoretical performance.

  • Alerting System
    You can integrate this logic into a Discord bot or Slack webhook. When the if condition triggers a "Buy" signal, the script pushes a notification to your phone.

  • Screener Integration
    Instead of checking one stock, you can iterate through a list of tickers obtained from the /v2/markets/screener endpoint and identify only those currently in a Golden Cross state.

By leveraging Mboum's Technical Indicator endpoints, developers can abstract away the complexity of mathematical calculations and focus on strategy logic. Whether you are building a simple alerting bot or a complex automated trading system, accurate and easily accessible indicator data is the first step.

👉 Start building your strategy today: https://mboum.com/pages/api