|
Zero values in BW FractalHigh series - workaround?
#481586
10/03/20 13:07
10/03/20 13:07
|
Joined: Sep 2020
Posts: 6 cockdeep
distribution
OP
Newbie
|
OP
Newbie
Joined: Sep 2020
Posts: 6
cockdeep
|
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 ?
#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
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.;
}
Last edited by distribution; 10/03/20 13:15.
|
|
|
Re: Zero values in BW FractalHigh series - workaround?
[Re: distribution]
#481592
10/04/20 13:28
10/04/20 13:28
|
Joined: Sep 2020
Posts: 6 cockdeep
distribution
OP
Newbie
|
OP
Newbie
Joined: Sep 2020
Posts: 6
cockdeep
|
I appreciate the response Kalmar. I'd like fHighCurrent and fLowCurrent to be a series. Code below, but Zorro crashes. Have I missed something ?
function run()
{
set(PLOTNOW, TICKS);
PlotScale = 8;
StartDate = 20160101;
EndDate = 20160331;
BarPeriod = 60;
LookBack = 3;
vars Price = series(price());
vars Highs = series(priceHigh());
vars Lows = series(priceLow());
var fHigh = FractalHigh(Highs, 3); // short term highs and lows
var fLow = FractalLow(Lows, 3);
static vars fLowCurrent = series(), fHighCurrent = series(); // fractal values are retained between runs ...
if(fHigh != 0){
fHighCurrent[0] = fHigh;
plot("Recent High", fHighCurrent[0], MAIN|DOT, BLUE);
printf(" fHighCurrent[0] = %.5f, fHighCurrent[1] = %.5f \n ", fHighCurrent[0], fHighCurrent[1]);
}
if(fLow !=0){
fLowCurrent[0] = fLow;
plot("Recent Low", fLowCurrent[0], MAIN|DOT, RED);
printf(" fLowCurrent[0] = %.5f, fLowCurrent[1] = %.5f \n ", fLowCurrent[0], fLowCurrent[1]);
}
}
|
|
|
Re: Zero values in BW FractalHigh series - workaround?
[Re: distribution]
#481594
10/04/20 13:35
10/04/20 13:35
|
Joined: Mar 2019
Posts: 357
danatrader
Senior Member
|
Senior Member
Joined: Mar 2019
Posts: 357
|
You have to shift static series manually. Static series should be defined globally, not within the run function. https://zorro-trader.com/manual/en/shift.htmhttps://zorro-trader.com/manual/en/series.htmStatic series (defined with a negative length) are not automatically shifted, but can be shifted by script with the shift function. Script-shifted static series can be used for excluding certain time periods from indicators, such as out-of-market hours or periods with high or low volatility. They can also be used for shifting a series by arriving price ticks in the tick function. Not shifted static series can store additional asset-dependent variables. Usage examples can be found in the SpecialBars script or in the SAR code in indicators.c.
Last edited by danatrader; 10/04/20 13:39.
|
|
|
Re: Zero values in BW FractalHigh series - workaround?
[Re: distribution]
#481603
10/05/20 18:34
10/05/20 18:34
|
Joined: Sep 2020
Posts: 6 cockdeep
distribution
OP
Newbie
|
OP
Newbie
Joined: Sep 2020
Posts: 6
cockdeep
|
Thanks for the feedback. The following works well. However, I can't seem to get the fHighCurrent & fLowCurrent to work as Global vars.. Even if I place them in a seperate function outside of run.
// Uncomment for crash.
//vars fHighCurrent = series(0, -LookBack);
//vars fLowCurrent = series(0, -LookBack);
function run()
{
set(PLOTNOW, TICKS);
PlotScale = 8;
StartDate = 20160101;
EndDate = 20160331;
BarPeriod = 60;
LookBack = 50;
vars Price = series(price());
vars Highs = series(priceHigh());
vars Lows = series(priceLow());
var fHigh = FractalHigh(Highs, 3); // short term highs and lows
var fLow = FractalLow(Lows, 3);
vars fHighCurrent = series(0, -LookBack);
vars fLowCurrent = series(0, -LookBack);
if(fHigh != 0){
shift(fHighCurrent, fHigh, LookBack);
plot("Recent High", fHighCurrent[0], MAIN|DOT, BLUE);
printf(" fHighCurrent[0] = %.5f, fHighCurrent[1] = %.5f \n ", fHighCurrent[0], fHighCurrent[1]);
}
if(fLow !=0){
shift(fLowCurrent, fLow, LookBack);
plot("Recent Low", fLowCurrent[0], MAIN|DOT, RED);
printf(" fLowCurrent[0] = %.5f, fLowCurrent[1] = %.5f \n ", fLowCurrent[0],fLowCurrent[1]);
}
}
|
|
|
|