Posted By: distribution
Zero values in BW FractalHigh series - workaround? - 10/03/20 13:07
I'm using the Bill Williams fractalHigh series. It works well when a fractal is found - PriceH1FractalHigh[0]. However when I go to access the
previous fractal to the one just found - PriceH1FractalHigh[1] it returns a 0 value. Looking at the code FractalHigh form indicators.c
this makes sense - when a fractal is not found a zero is returned. But as you can imagine this is not ideal, as it makes it difficult to access
the previous fractal high - I have to search through the series until I find the next non-zero value. This is tedious and it feels like a Zorro anti-pattern.
I've attached some code below which illustrates the issue.
Any suggestions on a workaround ?
BW fractal function def taken from indicators.c
previous fractal to the one just found - PriceH1FractalHigh[1] it returns a 0 value. Looking at the code FractalHigh form indicators.c
this makes sense - when a fractal is not found a zero is returned. But as you can imagine this is not ideal, as it makes it difficult to access
the previous fractal high - I have to search through the series until I find the next non-zero value. This is tedious and it feels like a Zorro anti-pattern.
I've attached some code below which illustrates the issue.
Any suggestions on a workaround ?
Code
#define VERBOSE 3 void fractalH1TF() { vars PriceH1FractalHigh = series(FractalHigh(series(priceHigh()),3)); printf("FOUND PriceH1FractalHigh[0] = %.5f PriceH1FractalHigh[1] = %.5f \n", PriceH1FractalHigh[0], PriceH1FractalHigh[1]); plotGraph("HTFFractalHigh", 1, 1.0002*PriceH1FractalHigh[0],TRIANGLE4, 0xE5DEDD); } function run() { set(PLOTNOW, TICKS); PlotScale = 8; Verbose = VERBOSE; BarPeriod = 60; //H1 LookBack = 24; StartDate = 20170102; EndDate = 20170201; fractalH1TF(); }
BW fractal function def taken from indicators.c
Code
var FractalHigh(var* Data,int Period) { if(Period < 3) return *Data; int Center = (Period-1)/2; if(MaxIndex(Data,Period) == Center) return Data[Center]; else return 0.; }