Download MetaTrader 5
To add comments, please log in or register
How to test a program before buying?
Dannoo007
195
Dannoo007 2014.02.28 14:36 

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
13656
whroeder1 2014.02.28 17:44  
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 2014.02.28 20:52  

Hi WHRoeder,

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

Many thanks for support!

D.

whroeder1
13656
whroeder1 2014.03.01 01:30  
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
8027
Keith Watford 2014.03.01 08:23  
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
6284
Tjipke de Vries 2014.03.01 08:32  

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

discussed so many times.....

/
To add comments, please log in or register