Crossover
Minimum bars needed: 2 bars (default params: 2 bars)
Compares current bar vs previous bar. No rolling window — works from bar 2 onward.
✅ After the warmup window is filled, this indicator produces a new value on every incoming bar in real-time.
Crossover detection is instant — no additional smoothing is applied.
| Event | Lag | Detail |
|---|---|---|
| Crossover detected | 0 bars | Compares current vs previous bar values |
The crossover function is used to calculate the crossover between two columns in a DataFrame. It returns a new DataFrame with an additional column that contains the crossover values. A crossover occurs when the first column crosses above or below the second column. This can happen in two ways, a strict crossover or a non-strict crossover. In a strict crossover, the first column must cross above or below the second column. In a non-strict crossover, the first column must cross above or below the second column, but the values can be equal.
def crossover(
data: Union[PdDataFrame, PlDataFrame],
first_column: str,
second_column: str,
result_column="crossover",
number_of_data_points: int = None,
strict: bool = True,
) -> Union[PdDataFrame, PlDataFrame]:
Example
from investing_algorithm_framework import download
from pyindicators import crossover, ema
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 crossover 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 = crossover(
pl_df,
first_column="EMA_50",
second_column="EMA_200",
result_column="Crossover_EMA"
)
pl_df.show(10)
# Calculate EMA and crossover 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")
pd_df = crossover(
pd_df,
first_column="EMA_50",
second_column="EMA_200",
result_column="Crossover_EMA"
)
pd_df.tail(10)

The image above uses the following parameters:
| Parameter | Value |
|---|---|
first_column | SMA_50 |
second_column | SMA_200 |