Skip to content

Commit 5239356

Browse files
committed
Add has any lower then threshold instructions
1 parent d228cdf commit 5239356

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pip install pyindicators
4242
* [Is Crossunder](#is-crossunder)
4343
* [Is Downtrend](#is-downtrend)
4444
* [Is Uptrend](#is-uptrend)
45+
* [has_any_lower_then_threshold](#has_any_lower_then_threshold)
4546

4647
## Indicators
4748

@@ -764,7 +765,7 @@ if is_crossunder(
764765
print("Crossunders detected in Pandas DataFrame in the last 3 data points")
765766

766767
# If you want to use the result of a previous crossover calculation
767-
if is_crossunder(pd_df, crossover_column="Crossunder_EMA", number_of_data_points=3):
768+
if is_crossunder(pd_df, crossunder_column="Crossunder_EMA", number_of_data_points=3):
768769
print("Crossunder detected in Pandas DataFrame in the last 3 data points")
769770
```
770771

@@ -851,3 +852,40 @@ pd_df = download(
851852
print(is_up_trend(pl_df))
852853
print(is_up_trend(pd_df))
853854
```
855+
856+
#### has_any_lower_then_threshold
857+
858+
The `has_any_lower_then_threshold` function checks if any value in a given column is lower than a specified threshold within the last N data points. This is useful for detecting when an indicator or price falls below a critical level.
859+
860+
```python
861+
def has_any_lower_then_threshold(
862+
data: Union[pd.DataFrame, pl.DataFrame],
863+
column,
864+
threshold,
865+
strict=True,
866+
number_of_data_points=1
867+
) -> bool:
868+
...
869+
```
870+
871+
Example
872+
873+
```python
874+
import pandas as pd
875+
from pyindicators.indicators.utils import has_any_lower_then_threshold
876+
877+
# Example DataFrame
878+
prices = pd.DataFrame({
879+
'Close': [100, 98, 97, 99, 96, 95, 97, 98, 99, 100]
880+
})
881+
882+
# Check if any of the last 5 closes are below 97
883+
result = has_any_lower_then_threshold(prices, column='Close', threshold=97, number_of_data_points=5)
884+
print(result) # Output: True
885+
```
886+
887+
Below is a chart showing the threshold and the points where the condition is met:
888+
889+
![has_any_lower_then_threshold](https://github.com/coding-kitties/PyIndicators/blob/main/static/images/indicators/has_any_lower_then_threshold.png)
890+
891+
In this chart, the red line represents the threshold, and the highlighted points are where the `Close` value is below the threshold in the last N data points.

0 commit comments

Comments
 (0)