Skip to main content

Is Crossunder

Warmup Window

Minimum bars needed: 2 bars (default params: 2 bars)

Single-bar comparison — works from bar 2 onward.

After the warmup window is filled, this indicator produces a new value on every incoming bar in real-time.

Real-time Indicator

Boolean check is instant.

EventLagDetail
Crossunder condition detected0 barsSingle-bar comparison

The is_crossunder function is used to determine if a crossunder occurred in the last N data points. It returns a boolean value indicating if a crossunder occurred in the last N data points. The function can be used to check for crossunders in a DataFrame that was previously calculated using the crossunder function.

def is_crossunder(
data: Union[PdDataFrame, PlDataFrame],
first_column: str = None,
second_column: str = None,
crossunder_column: str = None,
number_of_data_points: int = None,
strict: bool = True,
) -> bool:

Example

from investing_algorithm_framework import download

from pyindicators import crossunder, ema, is_crossunder

pl_df = download(
symbol="btc/eur",
market="binance",
time_frame="1d",
start_date="2023-12-01",
end_date="2023-12-25",
save=True,
storage_path="./data"
)
pd_df = download(
symbol="btc/eur",
market="binance",
time_frame="1d",
start_date="2023-12-01",
end_date="2023-12-25",
pandas=True,
save=True,
storage_path="./data"
)

# Calculate EMA and crossunders for Polars DataFrame
pl_df = ema(pl_df, source_column="Close", period=200, result_column="EMA_200")
pl_df = ema(pl_df, source_column="Close", period=50, result_column="EMA_50")
pl_df = crossunder(
pl_df,
first_column="EMA_50",
second_column="EMA_200",
result_column="Crossunder_EMA"
)

# If you want the function to calculate the crossunders in the function
if is_crossunder(
pl_df, first_column="EMA_50", second_column="EMA_200", number_of_data_points=3
):
print("Crossunder detected in Pandas DataFrame in the last 3 data points")

# If you want to use the result of a previous crossunders calculation
if is_crossunder(pl_df, crossunder_column="Crossunder_EMA", number_of_data_points=3):
print("Crossunder detected in Pandas DataFrame in the last 3 data points")

# Calculate EMA and crossunders for Pandas DataFrame
pd_df = ema(pd_df, source_column="Close", period=200, result_column="EMA_200")
pd_df = ema(pd_df, source_column="Close", period=50, result_column="EMA_50")

# If you want the function to calculate the crossunders in the function
if is_crossunder(
pd_df, first_column="EMA_50", second_column="EMA_200", number_of_data_points=3
):
print("Crossunders detected in Pandas DataFrame in the last 3 data points")

# If you want to use the result of a previous crossover calculation
if is_crossunder(pd_df, crossunder_column="Crossunder_EMA", number_of_data_points=3):
print("Crossunder detected in Pandas DataFrame in the last 3 data points")