Hello friends,
I hope you are being profitable and consistent every day with the new version (XU-20250224 Setup) of “XARD - Simple Trend Following Trading System”, but today the topic for a study and I hope to read your contributions on this indicator, and the indicator decide to approach this week is
XU v65m-ZZ1 Line.mq4 and
XU v65m-ZZ2 Line.mq4 . Because it's we have in open source and it's meant to help us better understand decision making, depend the timeframe we choose.
So many times we have the temptation (including my self ;p) to remove ZigZag indicators, because we are looking for a clean template, and forget the implications for that one, and because of that is a nice topic to start a share ideas with all of you.
Some information is provided from ChatGPT.
This is how visible the ZZ1 indicator is on the chart.
Legend 1.1: This is what we look like overall with the indicator
XU v65m-ZZ1 Line.mq4 appear in our chart
We don't have the option of choosing the values via the input menu, but we'll talk about that later in this post
Legend 1.2: The configuration of Input menu
This is where you can choose the colors and size of the lines.
Legend 1.3: The configuration of Colors menu
About ZZ1: And let's have a look at the code using ChatGPT to study it better and how we can make improvements
Code: Select all
#property link "https://forex-station.com/post1294848283.html#p1294848283"
#property description "THIS IS A FREE INDICATOR WITH NO TIME RESTRICTIONS"
#property description " "
#property description "Welcome to the XARD UNIVERSE"
#property description " "
#property description "Let the light shine and illuminate your trading world"
#property description "and with it secure your financial prosperity"
#property indicator_chart_window
#property indicator_buffers 3
Explanation
Meta-information for the Indicator
[*] `#property link`: The URL points to a Forex community website that contains more details about this indicator, possibly a discussion or version update.
[*] `#property description`: These properties provide information about the indicator’s purpose. It mentions the indicator is free, has no time restrictions, and encourages a message of financial prosperity.
Indicator Characteristics
[*] `#property indicator_chart_window`: This property places the indicator on the main chart window, as opposed to a separate window like other indicators such as oscillators.
[*] `#property indicator_buffers 3`: Specifies that three buffers (arrays) will be used for storing the indicator data.
- 2. Variable Declaration and External Parameters
Code: Select all
#define Version "XU v65m-ZZ1 Line"
string Name=WindowExpertName(), MyName="XU v65m-ZZ1 Line", indicatorFileName;
extern string Indicator = Version;
int ExtDepth = 144 - 1, ExtWidth = 16, ExtLabel = 0;
double zz[], zzH[], zzL[];
Explanation
Indicator Version and Name Management
[*] `#define Version "XU v65m-ZZ1 Line"`: A simple macro defines the version of the indicator.
[*] `string Name = WindowExpertName()`: Retrieves the name of the currently running Expert Advisor or indicator.
[*] `string MyName = "XU v65m-ZZ1 Line"`: Hardcoded string for the indicator’s name.
[*] `indicatorFileName`: Although declared, this variable is not used in the code, possibly intended for future use or modifications.
External Parameters
[*] `extern string Indicator = Version;`: This allows the user to specify the version name of the indicator when calling it, though this is set to the default version `XU v65m-ZZ1 Line`.
Variable Declarations
[*] `ExtDepth = 144 - 1`: The look-back period (or depth) for detecting price highs and lows. The default is set to 143 (144 - 1) periods. It’s an important parameter controlling how many bars the indicator will consider when calculating the highs and lows.
[*] `ExtWidth = 16`: The width of the lines drawn on the chart, defining the thickness of the visual representation of the indicator.
[*] `ExtLabel = 0`: A flag for displaying labels on the chart, although it’s not effectively used in this code.
[*] `double zz[], zzH[], zzL[]`: These are arrays (buffers) for storing the indicator's main data:
[*] `zz[]`: Stores the calculated main indicator values.
[*] `zzH[]`: Stores the local high values (local maxima).
[*] `zzL[]`: Stores the local low values (local minima).
- 3. Initialization (`init()` Function)
Code: Select all
int init(){
if(Period() == PERIOD_M1) { ExtDepth = (144 / 4) * 5 - 1; }
if(Period() == PERIOD_M15) { ExtDepth = (144 / 4) * 3 - 1; }
SetIndexBuffer(0, zz);
SetIndexStyle(0, DRAW_SECTION, 0, ExtWidth, C'145,125,88');
SetIndexEmptyValue(0, 0.0);
SetIndexBuffer(1, zzH);
SetIndexStyle(1, DRAW_NONE);
SetIndexEmptyValue(1, 0.0);
SetIndexBuffer(2, zzL);
SetIndexStyle(2, DRAW_NONE);
SetIndexEmptyValue(2, 0.0);
IndicatorShortName(MyName);
return(0);
}
Explanation
Period-Based Depth Adjustment
- The first two `if` statements adjust the depth (`ExtDepth`) based on the chart’s period:
- For **M1 (1-minute)** charts, the depth is increased to make it more sensitive to recent price action.
- For **M15 (15-minute)** charts, the depth is reduced to smooth out short-term fluctuations and focus on broader trends.
Setting Index Buffers and Styles
[*] `SetIndexBuffer(0, zz)`: Associates the `zz[]` buffer with index 0. This is the main data buffer for the indicator.
[*] `SetIndexStyle(0, DRAW_SECTION, 0, ExtWidth, C'145,125,88')`: Defines how the `zz[]` data is visualized. The `DRAW_SECTION` style creates a line, and `ExtWidth` determines its thickness. The color is set using RGB values (145, 125, 88), a yellow-brown color.
[*] `SetIndexEmptyValue(0, 0.0)`: Specifies that a value of `0.0` in the buffer represents an "empty" or invalid point.
Buffers for Local Highs and Lows
[*] Buffers `zzH[]` and `zzL[]` are set with `DRAW_NONE`, meaning they won’t be displayed on the chart, but are used for internal calculations.
Indicator Name
[*] `IndicatorShortName(MyName)`: This assigns a human-readable name to the indicator, which will appear in the indicator list in MetaTrader 4.
- 4. Main Calculation (`start()` Function)
Code: Select all
int start(){
if(Name == MyName){
int i, shift, pos, lasthighpos, lastlowpos, curhighpos, curlowpos;
double curlow, curhigh, lasthigh, lastlow, min, max;
ArrayInitialize(zz, 0.0);
ArrayInitialize(zzL, 0.0);
ArrayInitialize(zzH, 0.0);
lasthighpos = Bars;
lastlowpos = Bars;
lastlow = Low[Bars];
lasthigh = High[Bars];
for(shift = Bars - ExtDepth; shift >= 0; shift--){
curlowpos = Lowest(NULL, 0, MODE_LOW, ExtDepth, shift);
curlow = Low[curlowpos];
curhighpos = Highest(NULL, 0, MODE_HIGH, ExtDepth, shift);
curhigh = High[curhighpos];
// Low detection logic
if(curlow >= lastlow){
lastlow = curlow;
} else {
if(lasthighpos > curlowpos){
zzL[curlowpos] = curlow;
min = 100000;
pos = lasthighpos;
for(i = lasthighpos; i >= curlowpos; i--){
if(zzL[i] == 0.0) continue;
if(zzL[i] < min){
min = zzL[i];
pos = i;
}
zz[i] = 0.0;
}
zz[pos] = min;
}
lastlowpos = curlowpos;
lastlow = curlow;
}
// High detection logic
if(curhigh <= lasthigh){
lasthigh = curhigh;
} else {
if(lastlowpos > curhighpos){
zzH[curhighpos] = curhigh;
max = -100000;
pos = lastlowpos;
for(i = lastlowpos; i >= curhighpos; i--){
if(zzH[i] == 0.0) continue;
if(zzH[i] > max){
max = zzH[i];
pos = i;
}
zz[i] = 0.0;
}
zz[pos] = max;
}
lasthighpos = curhighpos;
lasthigh = curhigh;
}
}
if(ExtLabel > 0) Metka();
} else {
Comment("\n The name of this indicator cannot be changed\n ''XU v65m-ZZ1 Line''");
}
return(0);
}
Explanation
Local Variable Initialization
The function declares several variables:
[*] `lasthighpos`, `lastlowpos`: These store the positions of the last high and low.
[*] `curlowpos`, `curhighpos`: These store the positions of the current local low and high.
[*] `curlow`, `curhigh`, `lasthigh`, `lastlow`: These variables store the current and last local price values.
[*] `min`, `max`: Temporary variables used to find the lowest and highest values within the search range.
Buffer Initialization
[*] `ArrayInitialize(zz, 0.0)`, `ArrayInitialize(zzL, 0.0)`, `ArrayInitialize(zzH, 0.0)`: These functions initialize the `zz[]`, `zzL[]`, and `zzH[]` buffers to `0.0`.
Loop to Calculate Local Highs and Lows
[*] The `for`
loop starts from `Bars - ExtDepth` and iterates backward through the historical bars.
[*] The **local low** (`curlow`) is identified using the `Lowest()` function, and the **local high** (`curhigh`) is identified using the `Highest()` function, both within the look-back period (`ExtDepth`).
Local Low Logic
[*] If the current low is greater than or equal to the last low, the loop continues. If a new lower low is found, the program checks the previous highs and stores the lowest value.
Local High Logic
[*] If the current high is greater than or equal to the last high, the loop continues. If a new higher high is found, the program checks the previous lows and stores the highest value.
- 5. Labeling Function (`Metka()` Function)
Code: Select all
void Metka() {
int metka = 0;
for(int shift = Bars - ExtDepth; shift >= 0; shift--){
if(zz[shift] > 0){
if(zzH[shift] > 0) { metka = 2; zzL[shift] = 0; shift--; }
else { metka = 1; zzH[shift] = 0; shift--; }
}
if(metka == 0) { zzH[shift] = 0; zzL[shift] = 0; }
else if(metka == 1){
if(zzH[shift] > 0) metka = 0;
zzL[shift] = 0;
}
else if(metka == 2){
if(zzL[shift] > 0) metka = 0;
zzH[shift] = 0;
}
}
}
Explanation
Function Purpose
[*] The `Metka()` function is used to clean up and label the local high and low values stored in the buffers.
[*] The logic ensures that the calculated local highs and lows are correctly assigned in the `zzH[]` and `zzL[]` buffers. If a certain condition is met (i.e., a local high or low is encountered), it sets flags (`metka`) to either `1` or `2`, ensuring only one value is kept for the local high or low.
The "XU v65m-ZZ1 Line" indicator analyzes historical price action by identifying local price highs and lows, which can serve as critical support or resistance levels for traders. The depth of analysis is adjustable based on the timeframe, with specialized buffers storing the values for visualization. This indicator is valuable for traders looking for potential price reversal points based on recent price behavior.
About ZZ2: And let's have a look at the code using ChatGPT to study it better and how we can make improvements
Legend 2.1: This is what we look like overall with the indicator
XU v65m-ZZ2 Line.mq4 appear in our chart
We don't have the option of choosing the values via the input menu, but we'll talk about that later in this post
Legend 2.2: The configuration of Input menu
This is where you can choose the colors and size of the lines.
Legend 2.3: The configuration of Colors menu
- 1. Introduction to the Indicator
The script defines a custom indicator designed to be applied within MetaTrader 4 (MT4), a popular trading platform. The indicator, named "XU v65-ZZ2 Line," is a variation of a **ZigZag indicator** used to identify local peaks (highs) and troughs (lows) within a financial asset’s price chart. ZigZag indicators are commonly used in technical analysis to filter out market noise and help traders visualize significant price movements.
- 2. Code Breakdown and Analysis
Code: Select all
#property link "https://forex-station.com/post1294848283.html#p1294848283"
#property description "THIS IS A FREE INDICATOR WITH NO TIME RESTRICTIONS"
#property description " "
#property description "Welcome to the XARD UNIVERSE"
#property description " "
#property description "Let the light shine and illuminate your trading world"
#property description "and with it secure your financial prosperity"
#property indicator_chart_window
#property indicator_buffers 3
Explanation:
#property link: This property specifies a URL pointing to a webpage for further discussion or details related to the indicator.
#property description: Multiple description fields are used to provide information to the user when they view the indicator's properties in the MT4 platform. These properties do not affect the functionality of the code but serve as metadata for the users.
#property indicator_chart_window: Indicates that the indicator will be displayed directly on the main chart window of the trading platform rather than in a separate sub-window.
#property indicator_buffers 3: Specifies that the indicator will utilize three buffers (arrays) to store data that will be plotted on the chart.
- 2.2 Variable Initialization and Setup
Code: Select all
#define Version "XU v65m-ZZ2 Line"
string Name = WindowExpertName(), MyName = "XU v65m-ZZ2 Line", indicatorFileName;
extern string Indicator = Version;
int ExtDepth = 36 - 1, ExtWidth = 6, ExtLabel = 0;
double zz[], zzH[], zzL[];
Explanation:
#define Version: The `Version` macro defines the version of the indicator, which is useful for tracking updates or for informational purposes.
`Name`: This variable holds the name of the current Expert Advisor or indicator script.
`MyName`: The name of the indicator is hardcoded for consistency and later used to check whether the current instance of the indicator is the expected one.
External Variables:
`Indicator`: Defines the version of the indicator for user customization.
`ExtDepth`: Represents the "depth" of the ZigZag calculation, which determines how many bars back to look for significant peaks and troughs. It's initialized with a default value of 35.
`ExtWidth`: Specifies the thickness of the ZigZag line, which will be drawn on the chart.
`ExtLabel`: Controls whether labels or markers are displayed (set to 0 here, meaning no labels).
Buffers:
`zz[]`: This buffer will store the calculated ZigZag line values that will be plotted on the chart.
`zzH[]` and `zzL[]`: Buffers for storing the highest and lowest points (peaks and troughs) of the ZigZag, which are used for further analysis but are not drawn by default.
- 2.3 Initialization Function** (`int init()`)
Code: Select all
int init() {
if (Period() == PERIOD_M1) { ExtDepth = (36 / 4) * 5 - 1; }
if (Period() == PERIOD_M15) { ExtDepth = (36 / 4) * 3 - 1; }
SetIndexBuffer(0, zz);
SetIndexStyle(0, DRAW_SECTION, 0, ExtWidth, clrSnow);
SetIndexEmptyValue(0, 0.0);
SetIndexBuffer(1, zzH);
SetIndexStyle(1, DRAW_NONE);
SetIndexEmptyValue(1, 0.0);
SetIndexBuffer(2, zzL);
SetIndexStyle(2, DRAW_NONE);
SetIndexEmptyValue(2, 0.0);
IndicatorShortName(MyName);
return (0);
}
Explanation:
Adjusting `ExtDepth` Based on Timeframe: The indicator adjusts the `ExtDepth` value based on the current chart's time period (M1 or M15). This ensures that the calculation for ZigZag points is appropriately adapted to different chart granularities:
[*] For the M1 timeframe, `ExtDepth` is increased to make the indicator more sensitive to shorter-term price movements.
[*] For the M15 timeframe, `ExtDepth` is adjusted to smooth out the ZigZag and reduce noise.
Buffer Setup:
`SetIndexBuffer(0, zz)`: Initializes the primary buffer (`zz[]`) to store the actual ZigZag line data.
`SetIndexStyle(0, DRAW_SECTION, 0, ExtWidth, clrSnow)`: Configures the style of the ZigZag line. The line is drawn as a series of segments (`DRAW_SECTION`), and it is colored `clrSnow` with a width of `ExtWidth`.
`SetIndexEmptyValue(0, 0.0)`: Sets the default value of `0.0` for empty buffer slots, ensuring gaps are represented correctly in the chart.
Buffers for Highs and Lows:
`SetIndexBuffer(1, zzH)`: The buffer for storing high ZigZag points is initialized but not drawn (`DRAW_NONE`).
`SetIndexBuffer(2, zzL)`: Similarly, the buffer for storing low ZigZag points is initialized but not drawn.
Indicator Name: Sets the indicator's short name to be displayed in the MetaTrader terminal.
- 2.4 Main Calculation and Logic** (`int start()`)
Code: Select all
int start() {
if (Name == MyName) {
int i, shift, pos, lasthighpos, lastlowpos, curhighpos, curlowpos;
double curlow, curhigh, lasthigh, lastlow, min, max;
ArrayInitialize(zz, 0.0);
ArrayInitialize(zzL, 0.0);
ArrayInitialize(zzH, 0.0);
lasthighpos = Bars;
lastlowpos = Bars;
lastlow = Low[Bars];
lasthigh = High[Bars];
for (shift = Bars - ExtDepth; shift >= 0; shift--) {
curlowpos = Lowest(NULL, 0, MODE_LOW, ExtDepth, shift);
curlow = Low[curlowpos];
curhighpos = Highest(NULL, 0, MODE_HIGH, ExtDepth, shift);
curhigh = High[curhighpos];
// --- Low Logic ---
if (curlow >= lastlow) {
lastlow = curlow;
} else {
if (lasthighpos > curlowpos) {
zzL[curlowpos] = curlow;
min = 100000;
pos = lasthighpos;
for (i = lasthighpos; i >= curlowpos; i--) {
if (zzL[i] == 0.0) continue;
if (zzL[i] < min) {
min = zzL[i];
pos = i;
}
zz[i] = 0.0;
}
zz[pos] = min;
}
lastlowpos = curlowpos;
lastlow = curlow;
}
// --- High Logic ---
if (curhigh <= lasthigh) {
lasthigh = curhigh;
} else {
if (lastlowpos > curhighpos) {
zzH[curhighpos] = curhigh;
max = -100000;
pos = lastlowpos;
for (i = lastlowpos; i >= curhighpos; i--) {
if (zzH[i] == 0.0) continue;
if (zzH[i] > max) {
max = zzH[i];
pos = i;
}
zz[i] = 0.0;
}
zz[pos] = max;
}
lasthighpos = curhighpos;
lasthigh = curhigh;
}
}
if (ExtLabel > 0) Metka();
} else {
Comment("\n The name of this indicator cannot be changed\n ''XU v65m-ZZ2 Line''");
}
return (0);
}
Explanation:
Initialization:
[*] The function initializes various variables such as `shift`, `pos`, and price-related variables (`curlow`, `curhigh`, `lasthigh`, `lastlow`) to track price movements over time.
Main Loop:
[*] A loop iterates backward from the most recent price bar (`Bars - ExtDepth`) to determine the highest and lowest prices over the defined depth (`ExtDepth`).
Low Calculation: For each iteration, the indicator compares the current low price (`curlow`) with the last recorded low (`lastlow`). If a new low is found, it updates the `zzL[]` buffer and resets previous values within the range.
High Calculation: Similarly, it compares the current high price (`curhigh`) with the last recorded high (`lasthigh`). If a new high is found, it updates the `zzH[]` buffer and resets previous values.
[*] The algorithm effectively tracks peaks and troughs and stores these points in the appropriate buffers (`zzH[]` for highs and `zzL[]` for lows).
Code: Select all
void Metka() {
int metka = 0;
for (int shift = Bars - ExtDepth; shift >= 0; shift--) {
if (zz[shift] > 0) {
if (zzH[shift] > 0) {
metka = 2;
zzL[shift] = 0;
shift--;
} else {
metka = 1;
zzH[shift] = 0;
shift--;
}
}
if (metka == 0) {
zzH[shift] = 0;
zzL[shift] = 0;
} else if (metka == 1) {
if (zzH[shift] > 0) metka = 0;
zzL[shift] = 0;
} else if (metka == 2) {
if (zzL[shift] > 0) metka = 0;
zzH[shift] = 0;
}
}
}
Explanation:
- The `Metka` function is a secondary logic block that processes the `zz[]`, `zzH[]`, and `zzL[]` buffers to handle transitions between peaks and troughs.
- It ensures that after identifying a new peak or trough, the appropriate array is updated while resetting other values to prevent conflicting signals. This function adds a layer of verification to the ZigZag calculation process, ensuring consistency.
This code defines a customized ZigZag indicator for the MetaTrader 4 platform, with logic to track the price movements of an asset, identifying significant highs and lows within a user-defined depth. The indicator adapts to different time frames, providing flexibility for traders who prefer to analyze different granularities of the market. With its three buffers for storing ZigZag data, it helps traders identify support and resistance levels, often used in conjunction with other indicators for technical analysis.
And now the two zigzags together are on a higher timeframe than I normally trade, but just to show you.
A personal opinion about this indicator
Whether you're taking your first steps in studying this strategy, or you're at a more advanced level, this indicator, like all the others, is important when making decisions about managing your positions.
Be smart, observe all the elements, if you're undecided, wait and watch and take your notes, because the pattern you're looking for has been repeating itself forever and will continue to do so, there's no need to complicate things, it's all there in front of you.
If you like to play with settings, the
XU v65m is a great start, because the code is open, and can personalize your settings. But for ready to use and works very well in lower timeframe like (M1 or M5) the last versions is very effective and impressive results, but you know train your mind and body.
I hope you all can contribute to growing together, and your ideas and vision about ZigZags.
And for finish, today is NFP, and if not trading, i wish to you an excellent weekend and take some rest and enjoy the beautiful things you have in life.