Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TedMar, AndrewAMD), 1,043 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help for Haiken Ashi Bars needed. #479698
04/18/20 20:45
04/18/20 20:45
Joined: Apr 2020
Posts: 7
Germany
M
M_D Offline OP
Newbie
M_D  Offline OP
Newbie
M

Joined: Apr 2020
Posts: 7
Germany
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.

Re: Help for Haiken Ashi Bars needed. [Re: M_D] #479700
04/18/20 22:39
04/18/20 22:39
Joined: Feb 2017
Posts: 1,729
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,729
Chicago
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.

Re: Help for Haiken Ashi Bars needed. [Re: M_D] #479701
04/18/20 23:07
04/18/20 23:07
Joined: Apr 2020
Posts: 7
Germany
M
M_D Offline OP
Newbie
M_D  Offline OP
Newbie
M

Joined: Apr 2020
Posts: 7
Germany
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;
 >. 


Last edited by M_D; 04/18/20 23:13.
Re: Help for Haiken Ashi Bars needed. [Re: M_D] #479702
04/18/20 23:12
04/18/20 23:12
Joined: Feb 2017
Posts: 1,729
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,729
Chicago
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

Re: Help for Haiken Ashi Bars needed. [Re: M_D] #479703
04/18/20 23:21
04/18/20 23:21
Joined: Apr 2020
Posts: 7
Germany
M
M_D Offline OP
Newbie
M_D  Offline OP
Newbie
M

Joined: Apr 2020
Posts: 7
Germany
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

Last edited by M_D; 04/18/20 23:28.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1