Download MetaTrader 5

capturing latest high/low in ZigZag

To add comments, please log in or register
Dannoo007
195
Dannoo007  

Hello Boys

I am trying to extract the latest high and latest low painted on the chart by the ZigZag indicator at any moment. Unlike other indicators, the problem with this fellow is that... the number of bars to be counted back is not fixed, it can also skip to Bar0 and start moving again within Bar0 if previous high/low is crossed.

is iCustom the way to do it?

double ZigLatestHigh =iCustom(symbol,timeframe,"ZigZag",???,???); 
double ZigLatestLow  =iCustom(symbol,timeframe,"ZigZag",???,???); 

Any tips much appreciated.

D.

whroeder1
15585
whroeder1  
double ZigLatestHigh =iCustom(symbol,timeframe,"ZigZag",???,???); 
double ZigLatestLow  =iCustom(symbol,timeframe,"ZigZag",???,???); 

Are you actually looking at other "symbol,timeframe"s? Simplify, trade the current chart (otherwise you can't use Bars, High[], etc.)

ZigZag has only 1 buffer to read.

for(int iBar = 1; iBar < Bars; iBar++) if(
   iCustom(NULL,0, "ZigZag", 0, iBar) != 0) break;
int iZig1 = iBar;
for(iBar--; iBar < Bars; iBar++) if(
   iCustom(NULL,0, "ZigZag", 0, iBar) != 0) break;
int iZig2 = iBar;
double h1 = High[iZig1],
       h2 = High[iZig2];
double ZigLatestHigh = (h1 > h2) ? h1 : h2,
       ZigLatestLow  = (h1 > h2) ? Low[iZig2] : Low[iZig1];
Dannoo007
195
Dannoo007  

Hi WHRoeder,

Thanks a lot, that "Ternary Operator ?" is so sleek! - good to learn new things ;)

Many thanks for support!

D.

whroeder1
15585
whroeder1  
Dannoo007: that "Ternary Operator ?" is so sleek! - good to learn new things ;)
Welcome to the past. "initial development of C occurred at AT&T Bell Labs between 1969 and 1973"
Keith Watford
Moderator
10569
Keith Watford  
WHRoeder:

Are you actually looking at other "symbol,timeframe"s? Simplify, trade the current chart (otherwise you can't use Bars, High[], etc.)

ZigZag has only 1 buffer to read.



for(int iBar = 1; iBar < Bars; iBar++) if(
   iCustom(NULL,0, "ZigZag", 0, iBar) != 0) break;
int iZig1 = iBar;
for(iBar--; iBar < Bars; iBar++) if(
   iCustom(NULL,0, "ZigZag", 0, iBar) != 0) break;
int iZig2 = iBar;
double h1 = High[iZig1],
       h2 = High[iZig2];
double ZigLatestHigh = (h1 > h2) ? h1 : h2,
       ZigLatestLow  = (h1 > h2) ? Low[iZig2] : Low[iZig1];

Should iBar-- be iBar++ ?

Tjipke de Vries
6371
Tjipke de Vries  

Read https://www.mql5.com/en/forum/144092/page2#854926

discussed so many times.....

To add comments, please log in or register