Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct unit tests for time index indicators and fixed previous_high_low function #44

Merged
merged 4 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions smartmoneyconcepts/smc.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,19 @@ def previous_high_low(cls, ohlc: DataFrame, time_frame: str = "1D") -> Series:
currently_broken_low = False
last_broken_time = None
for i in range(len(ohlc)):
# remove rows with nan values (ignoring weekends)
resampled_previous_index = np.where(
resampled_ohlc.index < ohlc.index[i]
)[0]
if len(resampled_previous_index) <= 1:
previous_high[i] = np.nan
previous_low[i] = np.nan
continue
resampled_previous_index = resampled_previous_index[-1]
resampled_previous_index = resampled_previous_index[-2]

if last_broken_time != resampled_previous_index:
currently_broken_high = False
currently_broken_low = False
last_broken_time = resampled_previous_index

previous_high[i] = resampled_ohlc["high"].iloc[resampled_previous_index]
previous_low[i] = resampled_ohlc["low"].iloc[resampled_previous_index]
Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
def df():
test_instrument = "EURUSD"
instrument_data = f"{test_instrument}_15M.csv"
return pd.read_csv(
df = pd.read_csv(
os.path.join("tests/test_data", test_instrument, instrument_data)
)

df = df.set_index("Date")
df.index = pd.to_datetime(df.index)
return df

@pytest.fixture
def fvg_result_data():
Expand Down
Binary file modified tests/test.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading