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

ZIGZAG : Backtesting safe mode boolean flag. #874

Open
wants to merge 17 commits into
base: development
Choose a base branch
from

Conversation

80sVectorz
Copy link

@80sVectorz 80sVectorz commented Jan 7, 2025

Original problem

Currently, the zigzag indicator can't be used for back-testing purposes, as the pivot indices are placed before their actual detection would have happened.
A column that shows at what bar index the pivot was confirmed would be fantastic. The column could either have the absolute index or an offset. Along with the disregard of lag in pivot detection, there's the bigger issue of zigzag swing points moving when lower or higher pivots are detected.

Solution

To solve the issue, I've implemented a new back testing mode into the existing zigzag implementation.
When the new backtest_mode boolean flag is enabled, the function uses a modified version of the existing nb_find_zigzags.
This function run from front to back instead of from back to front, making it easy to track changes to existing zigzag swings.
The new function includes any raising or lowering of the swing points as new entries. Those entries should be treated as updates and not as new zigzag points.

After the zigzag points are found, an offset equal to half the pivot detection window or floor(legs/2) is added to the existing offset parameter. This ensures the lag of detecting pivots is accounted for.

VoaiiXqN23

Other changes

Along with the main feature came some other changes:

  • Improved the code readability / understandability, mostly in the form of docstrings and comment lines.
  • Fixed offset not working due to the use of the non-existent np.shift instead of np.roll

Personal ramblings

At first, this seemed like a very daunting task. But after deciphering the code, the solution did come to me pretty quickly.
I did trip up on the nb_find_zigzags function using a reversed approach quite a lot.
Overall, a fun and good challenge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant