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

Zig-zag missing pivots #3

Open
lapphan opened this issue May 9, 2023 · 3 comments
Open

Zig-zag missing pivots #3

lapphan opened this issue May 9, 2023 · 3 comments

Comments

@lapphan
Copy link
Contributor

lapphan commented May 9, 2023

Compare to Zig Zag indicator on TradingView, live_trading_indicators's ZigZag is missing 4 pivots:

  • 2 very first pivots (6427.0 and 10540.0)
  • 2 last pivots: the last completed pivot and the incomplete pivot (31059.0 and 27423.9)

What's showing on TradingView:

image

What I've done:

#lti.py
import live_trading_indicators as lti

indicators = lti.Indicators('ccxt.binanceusdm', '2019-09-08', '2023-05-08')
ohlcv = indicators.OHLCV('BTCUSDT', '1d')
print(ohlcv)
dataframe = ohlcv.pandas()
print(dataframe.head())
zigzag = indicators.ZigZag('BTCUSDT', '1d', delta=0.5, end_points=True)
print(zigzag)
dataframe = zigzag.pandas()
dataframe = dataframe[dataframe['pivot_types'].values != 0]
print(dataframe)
#console ouput
~/live_trading_indicators$ python3 lti.py
2023-05-09 20:12:08:root:725:102 INFO Download using xxct.binanceusdm symbol BTCUSDT timeframe 1d from 2019-09-08T00:00:00.000, bars: 1339
(OHLCV data) source: ccxt.binanceusdm, symbol: BTCUSDT, timeframe: 1d
date: 2019-09-08T00:00 - 2023-05-08T00:00 (length: 1339)
empty bars: count 0 (0.00 %), max consecutive 0
Values: time, open, high, low, close, volume
        time      open      high       low     close     volume
0 2019-09-08  10000.00  10412.65  10000.00  10391.63   3096.291
1 2019-09-09  10316.62  10475.54  10077.22  10307.00  14824.373
2 2019-09-10  10307.00  10382.97   9940.87  10102.02   9068.955
3 2019-09-11  10094.27  10293.11   9884.31  10159.55  10897.922
4 2019-09-12  10163.06  10450.13  10042.12  10415.13  15609.634
(IndicatorData) source: ccxt.binanceusdm, name: ZigZag, symbol: BTCUSDT, timeframe: 1d, allowed nan
date: 2019-09-08T00:00 - 2023-05-08T00:00 (length: 1339)
Values: time, pivots, pivot_types
           time    pivots  pivot_types
1    2019-09-09       NaN            1
187  2020-03-13   3621.81           -1
584  2021-04-14  64986.11            1
619  2021-05-19  28688.00           -1
794  2021-11-10  69198.70            1
1170 2022-11-21  15443.20           -1

Please help me to get all missing pivots.

Thank you.

@hal9000cc
Copy link
Owner

I fix some bugs in ZigZag, thanks. However, I'm not sure that's all.
You can take the fixes from the master branch.

@hal9000cc
Copy link
Owner

And I also don't understand where the price value of 15443.20 comes from. I don't find that.

@lapphan
Copy link
Contributor Author

lapphan commented May 12, 2023

And I also don't understand where the price value of 15443.20 comes from. I don't find that.

The pivot 15443.20 is a correct pivot that already showed in v0.7.5 (please check #console ouput in my initial comment). You can see it at highlighted text below:

image

I also tested v0.7.5.1 and now all missing pivots are showed:

(IndicatorData) source: ccxt.binanceusdm, name: ZigZag, symbol: BTCUSDT, timeframe: 1d, allowed nan
date: 2019-09-08T00:00 - 2023-05-08T00:00 (length: 1339)
Values: time, pivots, pivot_types
           time    pivots  pivot_types
101  2019-12-18   6427.00           -1
158  2020-02-13  10540.00            1
187  2020-03-13   3621.81           -1
584  2021-04-14  64986.11            1
619  2021-05-19  28688.00           -1
794  2021-11-10  69198.70            1
1170 2022-11-21  15443.20           -1
1314 2023-04-14  31059.00            1
1323 2023-04-23  27279.70           -1

But the incomplete pivot is not correct in my opinion. Perhaps we can take the logic in TradingView's Zig Zag indicator:

  • If the last completed pivot type is a High, the incomplete pivot type will be a Low and its pivot price is the Last Bar candle LOW price.
  • If the last completed pivot type is a Low, the incomplete pivot type will be a High and its pivot price is the Last Bar candle HIGH price.

My pseudocode for more clarity:

last_bar_candle = get_last_bar_candle()

if last_pivot.type = 1 # High
    incomplete_pivot.time = last_bar_candle.time
    incomplete_pivot.type = -1 # Low
    incomplete_pivot.price = last_bar_candle.low
else if last_pivot.type = -1 # Low
    incomplete_pivot.time = last_bar_candle.time
    incomplete_pivot.type = 1 # High
    incomplete_pivot.price = last_bar_candle.high

I hope you can understand my idea. Feel free to give any feedback to me.
Thank you.

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

No branches or pull requests

2 participants