Help for Haiken Ashi Bars needed.

Posted By: M_D

Help for Haiken Ashi Bars needed. - 04/18/20 20:45

Hello at all,

im the new guy here. Encountered Zorro Trader the first time about 2 years ago. Since then learning lite-c and trying to code something useful (if i find the time through work and family). Mostly simple things like EMA crossover etc. I have no coding expirience beforehand.

Currently Im curious about the japanese charts (Ichimoku indicator and Haiken Ashi bars). I managed to get the Ichimoku indicator on the charts, but failed so far to change the normal bars to Haiken Ashi Bars.
In fact i just copypasted the code snippet from the help file that looks like that below,
but the result ends with:

2_haiken_ashi_bar_test compiling.......
Error in 'line 11:
'Close' undeclared identifier
< Close[0] = (Open[0]+High[0]+Low[0]+Close[0])/4;
>.

And hereĀ“s the code:

Code
function run()
{
	set(LOGFILE|PLOTNOW);
	
	BarPeriod = 1;

	// Haiken Ashi Bars
int bar(vars Open,vars High,vars Low,vars Close)
{
  Close[0] = (Open[0]+High[0]+Low[0]+Close[0])/4;
  Open[0] = (Open[1]+Close[1])/2;
  High[0] = max(High[0],max(Open[0],Close[0]));
  Low[0] = min(Low[0],min(Open[0],Close[0]));
  return 8;
}

}


I already tried #include <default.c>, did not work.
Then i tried to declare it/them before with "vars Close = priceClose();", didnt help either.
Obviously Im missing something important.
I would appreciate if someone has already worked with Special Bars and could give me a hint.
Thanks in advance.
Posted By: AndrewAMD

Re: Help for Haiken Ashi Bars needed. - 04/18/20 22:39

Quote
'Close' undeclared identifier
Zorro expects you to tell it what Close is, just like in your code samples. In this case, it's a series of close values for the current asset. You declare it like this:
Code
vars Close = series(priceClose());

Did you work your way through the entire Lite-C tutorial? I highly recommend it.
Posted By: M_D

Re: Help for Haiken Ashi Bars needed. - 04/18/20 23:07

Hi AndrewAMD,

thank you for your quick response. Yes, i have reade the manual Tutorial, Error Messages and a lot of other useful things.
As i mentioned

Originally Posted by M_D
I already tried #include <default.c>, did not work.
Then i tried to declare it/them before with "vars Close = priceClose();", didnt help either.


(^here i have forget to write the series beforehand, i just noticed. but in code was correct)
i thought this is clear to understand.
So the code with declarations looked like this:

Code
function run()
{
	set(LOGFILE|PLOTNOW);
	
	BarPeriod = 1;
	
	vars Open = series(priceOpen());
	vars High = series(priceHigh());
	vars Low = series(priceLow());
	vars Close = series(priceClose());


	// Haiken Ashi Bars
int bar(vars Open,vars High,vars Low,vars Close)
{
  Close[0] = (Open[0]+High[0]+Low[0]+Close[0])/4;
  Open[0] = (Open[1]+Close[1])/2;
  High[0] = max(High[0],max(Open[0],Close[0]));
  Low[0] = min(Low[0],min(Open[0],Close[0]));
  return 8;
}

}


Anyway it gives the same error, just with another error line number of course:

PHP Code
2_haiken_ashi_bar_test compiling.......
Error in 'line 17: 
'Close' undeclared identifier
<   Close[0] = (Open[0]+High[0]+Low[0]+Close[0])/4;
 >. 

Posted By: AndrewAMD

Re: Help for Haiken Ashi Bars needed. - 04/18/20 23:12

I just noticed that the construction of your run function is entirely wrong. int bar is a standalone function. Keep it outside of run().

Zorro will call int bar for you. That's how it changes the bar type from time-based to custom bar. That's why it's called a "user-defined bar". You (the user) are defining the bar:
https://zorro-project.com/manual/en/bar.htm
Posted By: M_D

Re: Help for Haiken Ashi Bars needed. - 04/18/20 23:21

Hey, Wow laugh
that was the trick. Worked. Thanks a Lot.

Code
	// Haiken Ashi Bars
int bar(vars Open,vars High,vars Low,vars Close)
{
  Close[0] = (Open[0]+High[0]+Low[0]+Close[0])/4;
  Open[0] = (Open[1]+Close[1])/2;
  High[0] = max(High[0],max(Open[0],Close[0]));
  Low[0] = min(Low[0],min(Open[0],Close[0]));
  return 8;
}

function run()
{
	set(LOGFILE|PLOTNOW);
	
	BarPeriod = 1;
	
	vars Open = series(priceOpen());
	vars High = series(priceHigh());
	vars Low = series(priceLow());
	vars Close = series(priceClose());
}


So means, i have to reread (again) the parts with functions in tutorial tongue
Thats a hard nut to me, to figure out where i have to put whatever to run things as i want them to.
But luckily here is this forum with encouraged and helpful zorro coders like you.
Thank you again, lesson learned. I really appreciate it.

Kind regards

M_D
© 2024 lite-C Forums