Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, Quad, AndrewAMD), 936 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Zero values in BW FractalHigh series - workaround? #481586
10/03/20 13:07
10/03/20 13:07
Joined: Sep 2020
Posts: 6
cockdeep
D
distribution Offline OP
Newbie
distribution  Offline OP
Newbie
D

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 ?


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.;
}

Last edited by distribution; 10/03/20 13:15.
Re: Zero values in BW FractalHigh series - workaround? [Re: distribution] #481589
10/03/20 22:27
10/03/20 22:27
Joined: Oct 2017
Posts: 56
Munich
K
kalmar Offline
Junior Member
kalmar  Offline
Junior Member
K

Joined: Oct 2017
Posts: 56
Munich
I guess the variables should be static here like in the example below

Code
function run()	
{	
StartDate = 20160101;	
EndDate = 20160331;	
BarPeriod = 1440;	
	
vars Price = series(price());	
vars Highs = series(priceHigh());	
vars Lows = series(priceLow());	
	
var fHigh = FractalHigh(Highs, 7);	// short term highs and lows
var fLow = FractalLow(Lows, 7);	
static var fHighCurrent, fLowCurrent;	// fractal values are retained between runs ...
if (fHigh != 0) fHighCurrent = fHigh;	// ... and are changed whenever a non-zero value is returned by FractalHigh() ...
if (fLow !=0) fLowCurrent = fLow;	// ...  or FractalLow()
	
plot("Recent High", fHighCurrent, MAIN|DOT, BLUE);	
plot("Recent Low", fLowCurrent, MAIN|DOT, RED);	
}	

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
D
distribution Offline OP
Newbie
distribution  Offline OP
Newbie
D

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 ?

Code

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
D
danatrader Offline
Senior Member
danatrader  Offline
Senior Member
D

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.htm


https://zorro-trader.com/manual/en/series.htm

Static 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
D
distribution Offline OP
Newbie
distribution  Offline OP
Newbie
D

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.

Code
// 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]);
    }
}



Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1