CodeWitch:
Post the code if you need help.
Heya,
I'm currently working towards my own ZigZag indicator.
Right now it just looks for a bullish candle followed by a bearish one and vice versa. It then stores a high or low in the indicator buffer.
Even though the logic is simple, the indicator sometimes stores a value even when there's no 'pivot'. Some 'pivots' are also missed.
Can anybody help out? I can't figure out what's causing this. I attached the indicator below.
Thank you!
Okay, I edited my post to include the code. You can also find it in the attachments
- Direction is a variable value from the previous iteration, which means you can't process bar zero more than once, ever. Put it in a buffer so you can restore it, or only process bar zero once, or save and restore them when processing bar zero.
- You are processing all bars per tick. Code it properly so it only recomputes bar zero (after the initial run.)
How to do your lookbacks correctly. - Unlike MT4's Open/Close/etc., the variables open/close/etc do not have a direction defined. Where do you set them as series before using them?To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
https://www.mql5.com/en/docs/basis/function/events#oncalculate2
whroeder1:
Thanks for the help. I'll try and apply your tips tomorrow!
- Direction is a variable value from the previous iteration, which means you can't process bar zero more than once, ever. Put it in a buffer so you can restore it, or only process bar zero once, or save and restore them when processing bar zero.
- You are processing all bars per tick. Code it properly so it only recomputes bar zero (after the initial run.)
How to do your lookbacks correctly. - Unlike MT4's Open/Close/etc., the variables open/close/etc do not have a direction defined. Where do you set them as series before using them?
I managed to create an indicator that draws like it's supposed to. I left 'direction' out, but the simpler logic seems to work fine.
Thanks for helping!
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Heya,
I'm currently working towards my own ZigZag indicator.
Right now it just looks for a bullish candle followed by a bearish one and vice versa. It then stores a high or low in the indicator buffer.
Even though the logic is simple, the indicator sometimes stores a value even when there's no 'pivot'. Some 'pivots' are also missed.
Can anybody help out? I can't figure out what's causing this. I attached the indicator below.
Thank you!