Detet the trend using ZigZag - page 2

 
Tiofelo Teles #:

Here's my code! Sometimes it takes time to show the direction of the "trend" even though it has already found new tops and bottoms in the chart. Any improvement will be welcome. Thanks

Learn optimising meanwhile you are learning coding. 

You should also find support and resistance levels in order to say it is a trend
 
_MAHA_ #: Learn optimising meanwhile you are learning coding. You should also find support and resistance levels in order to say it is a trend

The OP's thread has nothing to do with optimisation or defining support and resistance. It is a code related query by the OP. Please don't interject.

 
_MAHA_ #:
Learn optimising meanwhile you are learning coding. 

You should also find support and resistance levels in order to say it is a trend

Thanks for the answer! Note that the code says "Zig Zag trend" and not "Price trend"

 
Fernando Carreiro #:

The following is sample code for Fractals, but it can easily be adapted for zigzag. Instead of using the upper and lower fractals, just look for swing points and detect if it is an upper or lower by simply comparing to the high or low price of that bar. If the swing point is the same as the high, then it is the upper, and if it is the same as the low, it is the lower.

EDIT: Please note that it is MQL4 code and not MQL5, but it just serves as a sample for you to adapt the logic for the zigzag.


Dear Fernando Carreiro, thanks for the reply! I will have a look at the code provided in detail  and try to apply it. Thanks
 
Fernando Carreiro #:

The OP's thread has nothing to do with optimisation or defining support and resistance. It is a code related query by the OP. Please don't interject.

I've just checked his code, and suggested him to focus on optimising while learning coding. Also once a trend reach a certain support or resistance level, it is no longer a trend. Since Zigzag will signal if a new higher or a new lower appears. So that might be the end of the trend ...

Btw I sometimes use zigzag for the sup&res lvls
 
_MAHA_ #:
I've just checked his code, and suggested him to focus on optimising while learning coding. Also once a trend reach a certain support or resistance level, it is no longer a trend. Since Zigzag will signal if a new higher or a new lower appears. So that might be the end of the trend ...

Btw I sometimes use zigzag for the sup&res lvls

Thanks for the answer. I will take your suggestion into consideration.