smartmoneyconcepts Python Library

repository·master·Indexed 23 days ago

https://github.com/joshyattridge/smart-money-concepts

A Python library providing technical indicators inspired by Inner Circle Trader (ICT) concepts. It includes tools for detecting Order Blocks, Fair Value Gaps (FVG), Market Structure shifts (BOS and CHoCH), Swing Highs and Lows, Liquidity levels, and Trading Sessions. The library operates on pandas DataFrames containing OHLC data.

Tokens
1.4K
Snippets
4
Records
11
Agent score
34%

What's inside smartmoneyconcepts

  1. Detect Break of Structure (BOS) and Change of Character (CHoCH)

    master

    Identifies shifts in market structure.

    Parameters:

    • ohlc (DataFrame): The input OHLC data.
    • swing_highs_lows (DataFrame): The DataFrame output from the smc.swing_highs_lows() function.
    • close_break (bool): If True, the break is determined by the candle's close. If False, it is determined by the candle's high/low.

    Returns (DataFrame columns):

    • BOS: 1 if bullish break of structure, -1 if bearish break of structure.
    • CHOCH: 1 if bullish change of character, -1 if bearish change of character.
    • Level: The price level of the BOS or CHoCH.
    • BrokenIndex: The index of the candle that broke the level.
  2. Identify Order Blocks (OB)

    master

    Detects price ranges where significant market orders are suspected to exist.

    Parameters:

    • ohlc (DataFrame): The input OHLC data.
    • swing_highs_lows (DataFrame): The DataFrame output from the smc.swing_highs_lows() function.
    • close_mitigation (bool): If True, the order block is considered mitigated based on the candle close; otherwise, it uses the high/low.

    Returns (DataFrame columns):

    • OB: 1 if bullish order block, -1 if bearish order block.
    • Top: Top of the order block.
    • Bottom: Bottom of the order block.
    • OBVolume: Volume calculated as volume + 2 last volumes amounts.
    • Percentage: Strength of the order block (min(highVolume, lowVolume)/max(highVolume,lowVolume)).
  3. Calculate Retracements

    master

    Calculates the percentage of retracement from recent swing highs or lows.

    Parameters:

    • ohlc (DataFrame): The input OHLC data.
    • swing_highs_lows (DataFrame): The DataFrame output from the smc.swing_highs_lows() function.

    Returns (DataFrame columns):

    • Direction: 1 if bullish retracement, -1 if bearish retracement.
    • CurrentRetracement%: The current retracement percentage from the swing high or low.
    • DeepestRetracement%: The deepest retracement percentage recorded from the swing high or low.
    smc.retracements(ohlc, swing_highs_lows)
  4. Identify Swing Highs and Lows

    master

    Identifies local price extremes based on a lookback/lookahead window.

    Parameters:

    • ohlc (DataFrame): The input OHLC data.
    • swing_length (int): The number of candles to look at before and after the current candle to determine if it is a swing point.

    Returns (DataFrame columns):

    • HighLow: 1 if a swing high, -1 if a swing low.
    • Level: The price level of the swing high or low.
  5. Get Previous High and Low

    master

    Retrieves the high and low prices from a specified previous timeframe.

    Parameters:

    • ohlc (DataFrame): The input OHLC data.
    • time_frame (str): The timeframe to reference. Supported values: 15m, 1H, 4H, 1D, 1W, 1M.

    Returns (DataFrame columns):

    • PreviousHigh: The high of the previous timeframe.
    • PreviousLow: The low of the previous timeframe.
    • BrokenHigh: 1 if price has broken the previous high, 0 otherwise.
    • BrokenLow: 1 if price has broken the previous low, 0 otherwise.
  6. Calculate Fair Value Gaps (FVG)

    master

    Detects Fair Value Gaps where a price imbalance exists between candles.

    Parameters:

    • ohlc (DataFrame): The input OHLC data.
    • join_consecutive (bool): If True, multiple consecutive FVGs are merged into one using the highest top and lowest bottom.

    Returns (DataFrame columns):

    • FVG: 1 if bullish FVG, -1 if bearish FVG.
    • Top: The top price level of the gap.
    • Bottom: The bottom price level of the gap.
    • MitigatedIndex: The index of the candle that mitigated the gap.
    smc.fvg(ohlc, join_consecutive=False)
  7. Identify Trading Sessions

    master

    Determines which candles fall within specific trading sessions or kill zones.

    Parameters:

    • ohlc (DataFrame): The input OHLC data.
    • session (str): The session name. Options: Sydney, Tokyo, London, New York, Asian kill zone, London open kill zone, New York kill zone, london close kill zone, or Custom.
    • start_time (str): Required only for Custom sessions. Format: "HH:MM".
    • end_time (str): Required only for Custom sessions. Format: "HH:MM".
    • time_zone (str): The timezone of the candles (e.g., "UTC+0" or "GMT+0"). Defaults to "UTC".

    Returns (DataFrame columns):

    • Active: 1 if the candle is within the session, 0 otherwise.
    • High: The highest price point reached during the session.
    • Low: The lowest price point reached during the session.
  8. Detect Liquidity levels

    master

    Identifies areas where multiple highs or lows exist within a tight price range.

    Parameters:

    • ohlc (DataFrame): The input OHLC data.
    • swing_highs_lows (DataFrame): The DataFrame output from the smc.swing_highs_lows() function.
    • range_percent (float): The percentage of the range used to determine if highs/lows are close enough to be considered liquidity.

    Returns (DataFrame columns):

    • Liquidity: 1 if bullish liquidity, -1 if bearish liquidity.
    • Level: The price level of the liquidity.
    • End: The index of the last liquidity level.
    • Swept: The index of the candle that swept the liquidity.