### Install smartmoneyconcepts Package Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Install the smartmoneyconcepts package using pip. This is the first step to using the library. ```bash pip install smartmoneyconcepts ``` -------------------------------- ### Full Market Structure Analysis Pipeline Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt This example demonstrates combining multiple Smart Money Concepts indicators, including swing pivots, break of structure (BOS)/change of character (CHOCH), fair value gaps (FVG), order blocks (OB), liquidity, retracements, previous highs/lows, and sessions, into a comprehensive market analysis pipeline. ```python import pandas as pd from smartmoneyconcepts import smc # Load data df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # Step 1 — Compute swing pivots (foundation for most other indicators) swing_hl = smc.swing_highs_lows(df, swing_length=5) # Step 2 — Market structure signals bos_choch = smc.bos_choch(df, swing_hl, close_break=True) # Step 3 — Supply/demand zones fvg = smc.fvg(df, join_consecutive=True) ob = smc.ob(df, swing_hl, close_mitigation=False) # Step 4 — Liquidity pools and retracements liq = smc.liquidity(df, swing_hl, range_percent=0.01) ret = smc.retracements(df, swing_hl) # Step 5 — Contextual filters prev_hl = smc.previous_high_low(df, time_frame="1D") london_ses = smc.sessions(df, session="London") # Merge everything onto the base DataFrame full = pd.concat([df, swing_hl, bos_choch, fvg, ob, liq, ret, prev_hl, london_ses], axis=1) # Example signal: bullish CHoCH during London session near an active bullish OB signal_mask = ( (full["CHOCH"] == 1) & (full["Active"] == 1) & # London session (full["BrokenLow"] == 0) # day's low not yet broken ) print(full[signal_mask][["CHOCH", "Level", "OB", "Active"]].head()) ``` -------------------------------- ### Define Custom Trading Sessions Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Use the `smc.sessions` function to define custom trading sessions with specified start and end times, and time zone. This is useful for analyzing specific market overlap periods. ```python import pandas as pd from smartmoneyconcepts import smc # Assuming 'df' is your DataFrame with time-series data # Example: London session candles london_candles = london[london["Active"] == 1] print(f"London session candles: {len(london_candles)}") # Custom session example (e.g., Asian overlap 02:00–05:00 UTC+2) custom = smc.sessions( df, session="Custom", start_time="02:00", end_time="05:00", time_zone="UTC+2" ) print(custom[custom["Active"] == 1][["High", "Low"]].tail()) ``` -------------------------------- ### Get Previous High and Low Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Retrieves the previous high and low for a specified time frame. Requires OHLC data as input. ```python smc.previous_high_low(ohlc, time_frame = "1D") ``` -------------------------------- ### Get Previous Period High and Low Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Resamples data to a higher timeframe to retrieve the previous period's high and low. It also tracks if the current period has broken these levels. Supported timeframes include '15min', '1h', '4h', '1D', 'W', '1M'. ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # Supported time_frame values: "15min", "1h", "4h", "1D", "1M" prev_hl_daily = smc.previous_high_low(df, time_frame="1D") prev_hl_weekly = smc.previous_high_low(df, time_frame="W") # PreviousHigh: prior period's high # PreviousLow: prior period's low # BrokenHigh: 1 once price has traded above PreviousHigh within the current period # BrokenLow: 1 once price has traded below PreviousLow within the current period print(prev_hl_daily.tail()) # Combine with original data df_enriched = pd.concat([df, prev_hl_daily], axis=1) # Candles where today's low swept yesterday's low swept_low = df_enriched[df_enriched["BrokenLow"] == 1] ``` -------------------------------- ### Import smc Module Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Import the smc module to begin using its financial indicator functions. Ensure your data is in the correct OHLC format. ```python from smartmoneyconcepts import smc ``` -------------------------------- ### Load and Prepare OHLCV Data with pandas Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Load OHLCV data into a pandas DataFrame and set a datetime index. Ensure columns are lowercase ('open', 'high', 'low', 'close', 'volume'). Volume is required for the `ob()` method. ```python import pandas as pd from smartmoneyconcepts import smc # Load OHLCV data (e.g., from a CSV, broker API, or yfinance) df = pd.read_csv("EURUSD_15M.csv") df = df.set_index("Date") df.index = pd.to_datetime(df.index) # Required columns: open, high, low, close, volume (volume needed for ob()) print(df.columns) # Index(['open', 'high', 'low', 'close', 'volume'], dtype='object') ``` -------------------------------- ### Identify Order Blocks (OB) with Volume Analysis Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Identifies Order Blocks (OB) using price and swing high/low data. Requires volume data and can be configured to mitigate OBs based on wicks or closes. Useful for finding potential support/resistance zones. ```python import pandas as pd from smartmoneyconcepts import smc # ob() requires volume data df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) swing_hl = smc.swing_highs_lows(df, swing_length=5) # close_mitigation=False: OB is mitigated when price wicks through it ob = smc.ob(df, swing_hl, close_mitigation=False) # OB: 1 = bullish OB, -1 = bearish OB, NaN = none # Top: upper boundary of the order block # Bottom: lower boundary of the order block # OBVolume: combined volume (current + 2 prior candles) # MitigatedIndex: candle index where OB was mitigated (NaN = still active) # Percentage: OB strength (0–100); higher = more balanced volume active_bullish_obs = ob[(ob["OB"] == 1) & (ob["MitigatedIndex"].isna())] print(active_bullish_obs[["OB", "Top", "Bottom", "Percentage"]].tail()) ``` -------------------------------- ### Detect Liquidity Pools Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Detects liquidity pools by grouping nearby swing highs or lows. These clusters represent areas where stop-loss orders accumulate. The `range_percent` parameter controls how close pivots must be to be grouped. ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) swing_hl = smc.swing_highs_lows(df, swing_length=5) # range_percent: fraction of the full high-low range used to group nearby pivots liquidity = smc.liquidity(df, swing_hl, range_percent=0.01) # Liquidity: 1 = bullish liquidity pool (buy-side), -1 = bearish (sell-side) # Level: average price level of the clustered pivots # End: index of the last swing point in the cluster # Swept: index of the candle that swept the liquidity (0 = not yet swept) unswept_buyside = liquidity[(liquidity["Liquidity"] == 1) & (liquidity["Swept"] == 0)] print(f"Active buy-side liquidity pools: {len(unswept_buyside)}") print(unswept_buyside[["Liquidity", "Level", "End"]].head()) ``` -------------------------------- ### Detect Liquidity Levels Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Detects liquidity levels in OHLC data using swing high/low data. Adjust range_percent to define the proximity for liquidity detection. ```python smc.liquidity(ohlc, swing_highs_lows, range_percent = 0.01) ``` -------------------------------- ### Identify Order Blocks (OB) Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Identifies potential order blocks using swing high/low data. Set close_mitigation to True to consider candle closes for mitigation. ```python smc.ob(ohlc, swing_highs_lows, close_mitigation = False) ``` -------------------------------- ### smc.sessions — Trading Session Windows Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Marks each candle as active or inactive within specified trading sessions (Sydney, Tokyo, London, New York, and their kill zones). It also tracks the running session high and low and supports timezone-aware data and custom session windows. ```APIDOC ## `smc.sessions` — Trading Session Windows ### Description Marks each candle as active or inactive within a specified trading session (Sydney, Tokyo, London, New York, and their kill zones). Also tracks the running session high and low. Supports timezone-aware data and fully custom session windows. ### Usage ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # Built-in sessions: "Sydney", "Tokyo", "London", "New York", # "Asian kill zone", "London open kill zone", # "New York kill zone", "london close kill zone" london = smc.sessions(df, session="London", time_zone="UTC") ``` ``` -------------------------------- ### Liquidity Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Detects liquidity zones where multiple highs or lows exist within a small price range. Returns liquidity status, level, end index, and swept index. ```APIDOC ## Liquidity ### Description Liquidity is when there are multiply highs within a small range of each other. Or multiply lows within a small range of each other. ### Method `smc.liquidity(ohlc, swing_highs_lows, range_percent = 0.01)` ### Parameters #### Path Parameters None #### Query Parameters - **swing_highs_lows** (DataFrame) - Required - provide the dataframe from the swing_highs_lows function - **range_percent** (float) - Optional - the percentage of the range to determine liquidity (default: 0.01) ### Request Example ```python smc.liquidity(ohlc, swing_highs_lows, range_percent = 0.01) ``` ### Response #### Success Response (200) - **Liquidity** (int) - 1 if bullish liquidity, -1 if bearish liquidity - **Level** (float) - the level of the liquidity - **End** (int) - the index of the last liquidity level - **Swept** (int) - the index of the candle that swept the liquidity ``` -------------------------------- ### Calculate Retracement Percentages Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt The `smc.retracements` function calculates how far price has retraced from the most recent swing extreme. It provides the current and deepest retracement percentages within a trending leg. Requires pre-computed swing highs and lows. ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) swing_hl = smc.swing_highs_lows(df, swing_length=5) ret = smc.retracements(df, swing_hl) # Direction: 1 = bullish leg (retracing down), -1 = bearish leg (retracing up) # CurrentRetracement%: current retracement % from the most recent swing extreme # DeepestRetracement%: deepest retracement % seen during the current leg print(ret[ret["Direction"] != 0].tail()) # Direction CurrentRetracement% DeepestRetracement% # 2023-03-14 13:30:00 1.0 38.2 61.8 # Find candles retracing between 50% and 61.8% (golden pocket) in a bullish leg golden_pocket = ret[ (ret["Direction"] == 1) & (ret["CurrentRetracement%"] >= 50) & (ret["CurrentRetracement%"] <= 61.8) ] print(f"Golden pocket entries: {len(golden_pocket)}") ``` -------------------------------- ### Calculate Fair Value Gap (FVG) Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Calculates Fair Value Gaps in OHLC data. Set join_consecutive to True to merge consecutive FVGs. ```python smc.fvg(ohlc, join_consecutive=False) ``` -------------------------------- ### Detect Fair Value Gaps (FVG) with smc.fvg Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Identifies bullish (1.0) or bearish (-1.0) Fair Value Gaps. The `join_consecutive` parameter can merge adjacent FVGs of the same type. The output includes 'FVG', 'Top', 'Bottom', and 'MitigatedIndex'. ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # Standard FVG detection fvg = smc.fvg(df, join_consecutive=False) # FVG: 1 = bullish FVG, -1 = bearish FVG, NaN = none # Top: upper boundary of the gap # Bottom: lower boundary of the gap # MitigatedIndex: index of the candle that filled/mitigated the gap (0 = unmitigated) active_fvgs = fvg[fvg["FVG"].notna()] print(active_fvgs.head()) # FVG Top Bottom MitigatedIndex # 2023-01-02 04:00:00 1.0 1.06923 1.06891 47.0 # 2023-01-02 07:15:00 -1.0 1.06834 1.06801 112.0 # Join consecutive FVGs of the same type into one zone fvg_merged = smc.fvg(df, join_consecutive=True) unmitigated = fvg_merged[(fvg_merged["FVG"].notna()) & (fvg_merged["MitigatedIndex"] == 0)] print(f"Unmitigated FVGs: {len(unmitigated)}") ``` -------------------------------- ### Mark Trading Session Windows Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Marks candles within specified trading sessions (e.g., London, New York) and their kill zones. Supports timezone-aware data and custom session windows. Tracks running session high and low. ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # Built-in sessions: "Sydney", "Tokyo", "London", "New York", # "Asian kill zone", "London open kill zone", # "New York kill zone", "london close kill zone" london = smc.sessions(df, session="London", time_zone="UTC") ``` -------------------------------- ### Calculate Retracements Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Calculates the retracement percentage from a given swing high or low. Requires a DataFrame containing swing high/low data. ```python smc.retracements(ohlc, swing_highs_lows) ``` -------------------------------- ### Analyze Trading Sessions Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Determines which candles fall within a specified trading session. Supports predefined sessions or custom start/end times. Time zone can be specified. ```python smc.sessions(ohlc, session, start_time, end_time, time_zone = "UTC") ``` -------------------------------- ### smc.ob — Order Blocks Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Identifies Order Blocks (OB), which are price ranges representing significant institutional order concentration before a strong impulsive move. Bullish OBs act as potential support, while bearish OBs act as potential resistance. The function includes volume analysis and mitigation tracking. ```APIDOC ## `smc.ob` — Order Blocks ### Description Identifies Order Blocks (OB) — price ranges representing areas of significant institutional order concentration, found just before a strong impulsive move through the previous swing high or low. Bullish OBs are potential support zones; bearish OBs are potential resistance zones. Includes volume analysis and mitigation tracking. ### Usage ```python import pandas as pd from smartmoneyconcepts import smc # ob() requires volume data df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) swing_hl = smc.swing_highs_lows(df, swing_length=5) # close_mitigation=False: OB is mitigated when price wicks through it ob = smc.ob(df, swing_hl, close_mitigation=False) # OB: 1 = bullish OB, -1 = bearish OB, NaN = none # Top: upper boundary of the order block # Bottom: lower boundary of the order block # OBVolume: combined volume (current + 2 prior candles) # MitigatedIndex: candle index where OB was mitigated (NaN = still active) # Percentage: OB strength (0–100); higher = more balanced volume active_bullish_obs = ob[(ob["OB"] == 1) & (ob["MitigatedIndex"].isna())] print(active_bullish_obs[["OB", "Top", "Bottom", "Percentage"]].tail()) ``` ### Output Example ``` OB Top Bottom Percentage 2023-03-10 14:00:00 1.0 1.07234 1.07198 72.4 ``` ``` -------------------------------- ### Fair Value Gap (FVG) Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Calculates Fair Value Gaps, which occur when there's a significant price imbalance. Returns FVG status, top, bottom, and mitigation index. ```APIDOC ## Fair Value Gap (FVG) ### Description A fair value gap is when the previous high is lower than the next low if the current candle is bullish. Or when the previous low is higher than the next high if the current candle is bearish. ### Method `smc.fvg(ohlc, join_consecutive=False)` ### Parameters #### Path Parameters None #### Query Parameters - **join_consecutive** (bool) - Optional - if there are multiple FVG in a row then they will be merged into one using the highest top and the lowest bottom ### Request Example ```python smc.fvg(ohlc, join_consecutive=False) ``` ### Response #### Success Response (200) - **FVG** (int) - 1 if bullish fair value gap, -1 if bearish fair value gap - **Top** (float) - the top of the fair value gap - **Bottom** (float) - the bottom of the fair value gap - **MitigatedIndex** (int) - the index of the candle that mitigated the fair value gap ``` -------------------------------- ### Retracement Calculation Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md This method calculates the percentage of a retracement from a given swing high or low point. ```APIDOC ## retracements ### Description Calculates the percentage of a retracement relative to the swing high or low. ### Method Signature ```python smc.retracements(ohlc, swing_highs_lows) ``` ### Parameters #### Path Parameters - **ohlc** (DataFrame) - The OHLC data to analyze. - **swing_highs_lows** (DataFrame) - A DataFrame containing swing highs and lows, typically generated by the `swing_highs_lows` function. ### Returns - **Direction** (int) - 1 for a bullish retracement, -1 for a bearish retracement. - **CurrentRetracement%** (float) - The current retracement percentage from the swing high or low. - **DeepestRetracement%** (float) - The deepest retracement percentage observed from the swing high or low. ``` -------------------------------- ### smc.liquidity — Liquidity Levels Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Detects liquidity pools by grouping multiple swing highs (or lows) that cluster within a configurable price range. These clusters represent areas where stop-loss orders accumulate and are susceptible to being 'swept' by institutional price action. ```APIDOC ## `smc.liquidity` — Liquidity Levels ### Description Detects liquidity pools by grouping multiple swing highs (or lows) that cluster within a configurable price range of each other. These clusters represent areas where stop-loss orders accumulate and are susceptible to being "swept" by institutional price action. ### Usage ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) swing_hl = smc.swing_highs_lows(df, swing_length=5) # range_percent: fraction of the full high-low range used to group nearby pivots liquidity = smc.liquidity(df, swing_hl, range_percent=0.01) # Liquidity: 1 = bullish liquidity pool (buy-side), -1 = bearish (sell-side) # Level: average price level of the clustered pivots # End: index of the last swing point in the cluster # Swept: index of the candle that swept the liquidity (0 = not yet swept) unswept_buyside = liquidity[(liquidity["Liquidity"] == 1) & (liquidity["Swept"] == 0)] print(f"Active buy-side liquidity pools: {len(unswept_buyside)}") print(unswept_buyside[["Liquidity", "Level", "End"]].head()) ``` ### Output Example ``` Liquidity Level End 2023-02-06 08:00:00 1.0 1.07456 215.0 ``` ``` -------------------------------- ### Previous High and Low Calculation Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md This method returns the previous high and low of a specified time frame, along with indicators for whether the price has broken these levels. ```APIDOC ## previous_high_low ### Description Returns the previous high and low of the given time frame, and indicates if these levels have been broken. ### Method Signature ```python smc.previous_high_low(ohlc, time_frame = "1D") ``` ### Parameters #### Path Parameters - **ohlc** (DataFrame) - The OHLC data to analyze. - **time_frame** (str) - The time frame for analysis. Accepted values: "15m", "1H", "4H", "1D", "1W", "1M". Defaults to "1D". ### Returns - **PreviousHigh** (float) - The previous high of the specified time frame. - **PreviousLow** (float) - The previous low of the specified time frame. - **BrokenHigh** (int) - 1 if the price has broken the previous high, 0 otherwise. - **BrokenLow** (int) - 1 if the price has broken the previous low, 0 otherwise. ``` -------------------------------- ### Detect Break of Structure (BOS) and Change of Character (CHoCH) Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Detects market structure changes using swing high/low data. Set close_break to True to use candle closes for mitigation. ```python smc.bos_choch(ohlc, swing_highs_lows, close_break = True) ``` -------------------------------- ### Hide Credit Message Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Hides the credit message that appears upon importing the library. This is set as an environment variable. ```bash export SMC_CREDIT=0 ``` -------------------------------- ### Detect Swing Highs and Lows using smc.swing_highs_lows Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Identifies significant swing pivots. Use `swing_length` to define the window size. The output DataFrame contains 'HighLow' (1.0 for high, -1.0 for low) and 'Level' (price of the pivot). ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) swing_hl = smc.swing_highs_lows(df, swing_length=5) # HighLow: 1.0 = swing high, -1.0 = swing low, NaN = not a pivot # Level: price of the pivot point, NaN otherwise print(swing_hl[swing_hl["HighLow"].notna()].head(10)) # HighLow Level # 2023-01-02 -1.0 1.06812 # 2023-01-03 1.0 1.07245 # 2023-01-04 -1.0 1.06534 # ... # Filter only swing highs swing_highs = swing_hl[swing_hl["HighLow"] == 1] # Filter only swing lows swing_lows = swing_hl[swing_hl["HighLow"] == -1] ``` -------------------------------- ### Order Blocks (OB) Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Identifies Order Blocks (OB), areas with high market order volume. Returns OB status, top, bottom, volume, and strength percentage. ```APIDOC ## Order Blocks (OB) ### Description This method detects order blocks when there is a high amount of market orders exist on a price range. ### Method `smc.ob(ohlc, swing_highs_lows, close_mitigation = False)` ### Parameters #### Path Parameters None #### Query Parameters - **swing_highs_lows** (DataFrame) - Required - provide the dataframe from the swing_highs_lows function - **close_mitigation** (bool) - Optional - if True then the order block will be mitigated based on the close of the candle otherwise it will be the high/low. (default: False) ### Request Example ```python smc.ob(ohlc, swing_highs_lows, close_mitigation = False) ``` ### Response #### Success Response (200) - **OB** (int) - 1 if bullish order block, -1 if bearish order block - **Top** (float) - top of the order block - **Bottom** (float) - bottom of the order block - **OBVolume** (int) - volume + 2 last volumes amounts - **Percentage** (float) - strength of order block (min(highVolume, lowVolume)/max(highVolume,lowVolume)) ``` -------------------------------- ### Detect Break of Structure (BOS) and Change of Character (CHoCH) Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Detects market structure continuation (BOS) or reversal (CHoCH) signals. Requires pre-computed swing highs/lows. The `close_break` parameter determines if structure is broken by a candle close. Output includes 'BOS', 'CHOCH', and 'Level'. ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # swing_highs_lows must be computed first swing_hl = smc.swing_highs_lows(df, swing_length=5) # close_break=True: structure is broken when candle closes beyond the level bos_choch = smc.bos_choch(df, swing_hl, close_break=True) # BOS: 1 = bullish BOS, -1 = bearish BOS, NaN = none # CHOCH: 1 = bullish CHoCH, -1 = bearish CHoCH, NaN = none # Level: price level of the broken structure ``` -------------------------------- ### Session Identification Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md This method identifies which candles fall within a specified trading session and provides session high and low points. ```APIDOC ## sessions ### Description Determines which candles fall within a specified trading session and returns the session's high and low points. ### Method Signature ```python smc.sessions(ohlc, session, start_time, end_time, time_zone = "UTC") ``` ### Parameters #### Path Parameters - **ohlc** (DataFrame) - The OHLC data to analyze. - **session** (str) - The session to check. Accepted values: "Sydney", "Tokyo", "London", "New York", "Asian kill zone", "London open kill zone", "New York kill zone", "london close kill zone", "Custom". - **start_time** (str) - The start time of the session in "HH:MM" format. Required only for "Custom" sessions. - **end_time** (str) - The end time of the session in "HH:MM" format. Required only for "Custom" sessions. - **time_zone** (str) - The time zone of the candles. Format examples: "UTC+0", "GMT+0". Defaults to "UTC". ### Returns - **Active** (int) - 1 if the candle is within the session, 0 otherwise. - **High** (float) - The highest point reached during the session. - **Low** (float) - The lowest point reached during the session. ``` -------------------------------- ### Hide Credit Message Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md This command allows users to hide the credit message that appears when the library is first imported. ```APIDOC ## Hide Credit Message ### Description Hides the credit message displayed upon importing the library. ### Command ```bash export SMC_CREDIT=0 ``` ``` -------------------------------- ### Identify Swing Highs and Lows Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Identifies swing highs and lows in OHLC data based on a specified swing_length. This is crucial for other indicators like BOS and Liquidity. ```python smc.swing_highs_lows(ohlc, swing_length = 50) ``` -------------------------------- ### smc.swing_highs_lows Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Identifies significant swing high and swing low pivots in price action. It analyzes a symmetric window around each candle to determine if it's a pivot point. ```APIDOC ## smc.swing_highs_lows — Detect Swing Highs and Lows ### Description Identifies significant swing high and swing low pivots in price action by finding candles whose high (or low) is the highest (or lowest) within a symmetric window of `swing_length` candles on each side. Consecutive same-direction pivots are resolved by keeping only the more extreme one. ### Parameters - **df** (pandas.DataFrame) - Required - DataFrame with OHLC(V) data and a datetime index. - **swing_length** (int) - Optional - The number of candles on each side to consider for identifying a pivot. Defaults to 5. ### Returns pandas.DataFrame - A DataFrame with the same index as the input, containing: - **HighLow** (float): 1.0 for swing high, -1.0 for swing low, NaN otherwise. - **Level** (float): The price of the pivot point, NaN otherwise. ### Request Example ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) swing_hl = smc.swing_highs_lows(df, swing_length=5) # HighLow: 1.0 = swing high, -1.0 = swing low, NaN = not a pivot # Level: price of the pivot point, NaN otherwise print(swing_hl[swing_hl["HighLow"].notna()].head(10)) ``` ### Response Example ``` # Output snippet for swing_hl[swing_hl["HighLow"].notna()].head(10): # HighLow Level # 2023-01-02 -1.0 1.06812 # 2023-01-03 1.0 1.07245 # 2023-01-04 -1.0 1.06534 # ... ``` ``` -------------------------------- ### Identify Bullish CHoCH and Bearish BOS Signals Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Filters a DataFrame to identify bullish Change of Character (CHoCH) and bearish Break of Structure (BOS) signals. Useful for analyzing market structure shifts. ```python bullish_choch = bos_choch[bos_choch["CHOCH"] == 1] bearish_bos = bos_choch[bos_choch["BOS"] == -1] print(f"Bullish CHoCH signals: {len(bullish_choch)}") print(f"Bearish BOS signals: {len(bearish_bos)}") print(bullish_choch[["CHOCH", "Level", "BrokenIndex"]].head()) ``` -------------------------------- ### Break of Structure (BOS) & Change of Character (CHoCH) Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Detects Break of Structure (BOS) and Change of Character (CHoCH) events, indicating shifts in market structure. Returns the type of event, level, and the index of the breaking candle. ```APIDOC ## Break of Structure (BOS) & Change of Character (CHoCH) ### Description These are both indications of market structure changing. ### Method `smc.bos_choch(ohlc, swing_highs_lows, close_break = True)` ### Parameters #### Path Parameters None #### Query Parameters - **swing_highs_lows** (DataFrame) - Required - provide the dataframe from the swing_highs_lows function - **close_break** (bool) - Optional - if True then the break of structure will be mitigated based on the close of the candle otherwise it will be the high/low. (default: True) ### Request Example ```python smc.bos_choch(ohlc, swing_highs_lows, close_break = True) ``` ### Response #### Success Response (200) - **BOS** (int) - 1 if bullish break of structure, -1 if bearish break of structure - **CHOCH** (int) - 1 if bullish change of character, -1 if bearish change of character - **Level** (float) - the level of the break of structure or change of character - **BrokenIndex** (int) - the index of the candle that broke the level ``` -------------------------------- ### smc.previous_high_low — Previous Period High and Low Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Resamples input data to a higher time frame to return the prior completed period's high and low for each base-timeframe candle. It also tracks cumulative breaks above the previous high or below the previous low within the current period. ```APIDOC ## `smc.previous_high_low` — Previous Period High and Low ### Description Resamples the input data to a higher time frame and returns the prior completed period's high and low for each base-timeframe candle. Also tracks whether price has cumulatively broken above the previous high or below the previous low within the current period. ### Usage ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # Supported time_frame values: "15min", "1h", "4h", "1D", "W", "1M" prev_hl_daily = smc.previous_high_low(df, time_frame="1D") prev_hl_weekly = smc.previous_high_low(df, time_frame="W") # PreviousHigh: prior period's high # PreviousLow: prior period's low # BrokenHigh: 1 once price has traded above PreviousHigh within the current period # BrokenLow: 1 once price has traded below PreviousLow within the current period print(prev_hl_daily.tail()) # Combine with original data df_enriched = pd.concat([df, prev_hl_daily], axis=1) # Candles where today's low swept yesterday's low swept_low = df_enriched[df_enriched["BrokenLow"] == 1] ``` ### Output Example ``` PreviousHigh PreviousLow BrokenHigh BrokenLow 2023-03-15 21:45:00 1.07345 1.06891 0 1 ``` ``` -------------------------------- ### smc.bos_choch Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Detects Break of Structure (BOS) and Change of Character (CHoCH) signals. BOS indicates continuation of market structure, while CHoCH signals a potential reversal. ```APIDOC ## smc.bos_choch — Break of Structure and Change of Character ### Description Detects Break of Structure (BOS) — continuation signals where market structure extends in the prevailing direction — and Change of Character (CHoCH) — reversal signals where market structure shifts direction. Both signals are identified by analysing sequences of four consecutive swing pivots and are only recorded once the structure level is broken by a subsequent candle. ### Parameters - **df** (pandas.DataFrame) - Required - DataFrame with OHLC(V) data and a datetime index. - **swing_hl** (pandas.DataFrame) - Required - DataFrame containing swing high/low pivot information, typically generated by `smc.swing_highs_lows`. - **close_break** (bool) - Optional - If True, structure is considered broken when a candle closes beyond the level. Defaults to True. ### Returns pandas.DataFrame - A DataFrame with the same index as the input, containing: - **BOS** (float): 1.0 for bullish BOS, -1.0 for bearish BOS, NaN otherwise. - **CHOCH** (float): 1.0 for bullish CHoCH, -1.0 for bearish CHoCH, NaN otherwise. - **Level** (float): The price level of the broken structure. ### Request Example ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # swing_highs_lows must be computed first swing_hl = smc.swing_highs_lows(df, swing_length=5) # close_break=True: structure is broken when candle closes beyond the level bos_choch = smc.bos_choch(df, swing_hl, close_break=True) # BOS: 1 = bullish BOS, -1 = bearish BOS, NaN = none # CHOCH: 1 = bullish CHoCH, -1 = bearish CHoCH, NaN = none # Level: price level of the broken structure print(bos_choch.head()) ``` ``` -------------------------------- ### smc.fvg Source: https://context7.com/joshyattridge/smart-money-concepts/llms.txt Detects Fair Value Gaps (FVG) in the price action. An FVG occurs when there is an imbalance between buying and selling pressure, indicated by a gap between the high of one candle and the low of the next. ```APIDOC ## smc.fvg — Fair Value Gap ### Description A Fair Value Gap (FVG) occurs when a bullish candle's previous candle high is below the next candle's low (bullish FVG), or a bearish candle's previous candle low is above the next candle's high (bearish FVG). The `join_consecutive` parameter merges adjacent FVGs of the same direction into a single wider zone. ### Parameters - **df** (pandas.DataFrame) - Required - DataFrame with OHLC(V) data and a datetime index. - **join_consecutive** (bool) - Optional - If True, merges adjacent FVGs of the same direction. Defaults to False. ### Returns pandas.DataFrame - A DataFrame with the same index as the input, containing: - **FVG** (float): 1.0 for bullish FVG, -1.0 for bearish FVG, NaN otherwise. - **Top** (float): The upper boundary of the FVG. - **Bottom** (float): The lower boundary of the FVG. - **MitigatedIndex** (int): The index of the candle that filled/mitigated the gap (0 if unmitigated). ### Request Example ```python import pandas as pd from smartmoneyconcepts import smc df = pd.read_csv("EURUSD_15M.csv", index_col="Date", parse_dates=True) # Standard FVG detection fvg = smc.fvg(df, join_consecutive=False) active_fvgs = fvg[fvg["FVG"].notna()] print(active_fvgs.head()) # Join consecutive FVGs of the same type into one zone fvg_merged = smc.fvg(df, join_consecutive=True) unmitigated = fvg_merged[(fvg_merged["FVG"].notna()) & (fvg_merged["MitigatedIndex"] == 0)] print(f"Unmitigated FVGs: {len(unmitigated)}") ``` ### Response Example ``` # Output snippet for active_fvgs.head(): # FVG Top Bottom MitigatedIndex # 2023-01-02 04:00:00 1.0 1.06923 1.06891 47.0 # 2023-01-02 07:15:00 -1.0 1.06834 1.06801 112.0 ``` ``` -------------------------------- ### Swing Highs and Lows Source: https://github.com/joshyattridge/smart-money-concepts/blob/master/README.md Identifies swing highs and lows within a specified lookback period. Returns the swing type and level. ```APIDOC ## Swing Highs and Lows ### Description A swing high is when the current high is the highest high out of the swing_length amount of candles before and after. A swing low is when the current low is the lowest low out of the swing_length amount of candles before and after. ### Method `smc.swing_highs_lows(ohlc, swing_length = 50)` ### Parameters #### Path Parameters None #### Query Parameters - **swing_length** (int) - Optional - the amount of candles to look back and forward to determine the swing high or low (default: 50) ### Request Example ```python smc.swing_highs_lows(ohlc, swing_length = 50) ``` ### Response #### Success Response (200) - **HighLow** (int) - 1 if swing high, -1 if swing low - **Level** (float) - the level of the swing high or low ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.