Hey everyone,
I've been using the ZigZag indicator in my strategy and now need to reimplement it in a new environment. I get the overall concept, but I need more details about the implementation of the this indicator, especially the calculation of the first point.
Can anyone explain the algorithm or criteria used to determine the first point?
I roughly thought that he does it as follows:
Initialization:
- Define the threshold value as a percentage or absolute value that determines the minimum price movement required to identify a new zigzag point.
- Set the initial start_point to the first bar's closing price.
- Initialize min_price and max_price to the start_point.
Iteration:
- Iterate through each bar's closing price in the given period.
- For each bar, update the min_price and max_price if the current closing price is lower than min_price or higher than max_price, respectively.
- If the price moves above the max_price + threshold or below the min_price - threshold, mark this as the first zigzag point.
Recording the Point:
- Record the closing price of the bar that triggered the threshold breach as the first zigzag point.
The truth is that I want to achieve the same result seen in my backtests, including the fact that the indicator does not appear to change its segments present in a backtest, even when the start or end of the backtest is altered. I wonder if there is any calculation involving bars that are not present behind the scenes.
I've been using the ZigZag indicator in my strategy and now need to reimplement it in a new environment. I get the overall concept, but I need more details about the implementation of the this indicator, especially the calculation of the first point.
Can anyone explain the algorithm or criteria used to determine the first point?
I roughly thought that he does it as follows:
Initialization:
- Define the threshold value as a percentage or absolute value that determines the minimum price movement required to identify a new zigzag point.
- Set the initial start_point to the first bar's closing price.
- Initialize min_price and max_price to the start_point.
Iteration:
- Iterate through each bar's closing price in the given period.
- For each bar, update the min_price and max_price if the current closing price is lower than min_price or higher than max_price, respectively.
- If the price moves above the max_price + threshold or below the min_price - threshold, mark this as the first zigzag point.
Recording the Point:
- Record the closing price of the bar that triggered the threshold breach as the first zigzag point.
The truth is that I want to achieve the same result seen in my backtests, including the fact that the indicator does not appear to change its segments present in a backtest, even when the start or end of the backtest is altered. I wonder if there is any calculation involving bars that are not present behind the scenes.
Rename
ZigZag comes from the PeakTroughCalculator and the first point appears when price movement has confirmed either a peak or a trough.
In a trading strategy, you must use assignWhenConfirmed: true to avoid peeking. Setting it to false is only useful to identify the actual peaks/troughs in the BarHistory.
In a trading strategy, you must use assignWhenConfirmed: true to avoid peeking. Setting it to false is only useful to identify the actual peaks/troughs in the BarHistory.
Your Response
Post
Edit Post
Login is required