Your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
- Usually people who can't code don't receive free help on this forum.
- If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
- To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Book and Documentation
- Remember also, that you can debug your code with MetaEditor's own debugging functionality.
- If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
- Finally, you also have the option to hire a programmer in the Freelance section.
If you want purely accurate swing detection then you will achieve that with enormous delay, because true swings have to be confirmed and are after the fact.
Is zigzag method the only accurate way to identify swing highs/lows at the moment?
I would say it is the best way, but I also made something called "magzag" which is a new approach to making the zigzag quantitative instead of being based on arbitrary price action.
There is also something called Fractals which really is nothing but a weaker version of the zigzag as it is based on turning points but has no input parameters.
I attached a market structure indicator which is also essentially finding the swing highs and lows without using zigzag logic and doesn't repaint
I would say it is the best way, but I also made something called "magzag" which is a new approach to making the zigzag quantitative instead of being based on arbitrary price action.
There is also something called Fractals which really is nothing but a weaker version of the zigzag as it is based on turning points but has no input parameters.
I attached a market structure indicator which is also essentially finding the swing highs and lows without using zigzag logic and doesn't repaint
Hi, thanks so much for the reply and the input! when you mentioned "doesn't repaint", what does that mean?
The attached indicator was written by another coder who reserved its copyright to Metaquotes. For the life of me, I can't remember who coded it.
Anyway, the indicator draws arrows at significant swing highs and lows based on a simple input bars period. As Conor Mcnamara already alluded in this thread, pinpointing significant highs and lows relies on price history and therefore, inherently lags. Even the original ZigZag indicator was intended to be used for identifying waves in price history. Note that unlike the ZigZag indicator, the indicator below does not alternate its drawing of swings. Instead, each arrow is drawn based on its surrounding price bars.
I would separate the problem into two layers:
- Confirmed swing points.
- Internal structure points.
If you mix both in one rule, the indicator usually becomes noisy or starts repainting. A confirmed swing needs right-side bars, so it will always have some delay. Internal points can be detected earlier, but they should be treated as lower-confidence structure until price confirms them.
A simple confirmed swing high/low function can start like this:
bool IsSwingHigh(const int i,const double &high[],int depth) { for(int k=1;k<=depth;k++) { if(high[i] <= high[i-k]) return false; if(high[i] <= high[i+k]) return false; } return true; } bool IsSwingLow(const int i,const double &low[],int depth) { for(int k=1;k<=depth;k++) { if(low[i] >= low[i-k]) return false; if(low[i] >= low[i+k]) return false; } return true; }
After that, I would not classify HH/HL/LL/LH from every candle. Store only accepted pivots first, then compare the last accepted pivot with the previous pivot of the same type.
For internal structure, use a smaller depth and add validation rules, for example:
- minimum distance from the previous pivot;
- minimum candle range or ATR fraction;
- break of a previous internal high/low;
- do not accept two consecutive highs or lows unless the new one is more extreme.
You can keep the data in a small structure:
struct PivotPoint
{
datetime time;
double price;
int type; // 1 high, -1 low
bool major;
}; The important part is to decide what you want from the indicator. If you want non-repainting structure, accept the delay. If you want earlier internal points, mark them as provisional and update them until confirmation. Trying to make them early and final at the same time is usually where the logic becomes unstable.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use

Hi,
I'm new to MQL5 and would like to make an indicator that identify the swing & internal points of the chart. I read that in order for you to find the swing/internal points then you need to identify the HH/HL/LL/LH of the chart. I want to collect some algorithm ideas on how to do this. Thanks!