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
0 registered members (), 1,119 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
Page 1 of 5 1 2 3 4 5
price() clarification #434441
12/18/13 15:38
12/18/13 15:38
Joined: May 2013
Posts: 245
S
swingtraderkk Offline OP
Member
swingtraderkk  Offline OP
Member
S

Joined: May 2013
Posts: 245
price()

Quote:
Returns the mean price of a bar, i.e. the average of all ticks the currently selected asset that fall into the bar period. This is normally the preferred price for indicators because it is less susceptible to random fluctuations and makes systems more robust and independent on the data feed.


In back testing:

1) on 1 min bars does price() return (high+low+open+close)/4 ?

2) on higher BarPeriods does it average each tick (i.e. each 1 min high low open close) or average a stored mean value of 1 min prices?

3) if it averages stored mean values, does it always use all available 1 min values or does it average say 30 min mean prices when calculating a 60 min mean price?

4) How does it handle higher Barperiods that may span many minutes where there are no 1 min data points at all, e.g. at weekends, or times of low activity where no ticks are received during a 1 min period and there is no HLOC?

5) Does use of TimeFrame change any of the answers above, or does price() return exactly the same values when using Timeframe as the equivalent Barperiod? i.e. does barperiod 60; price() return exactly the same values as barperiod 5; timeframe 12; price()?

In live trading, I assume this is much simpler in that zorro runs this averaging for each actual tick received with a timestamp that falls inside the Barperiod / Timeframe in question. i.e. sum of prices of all ticks/no. ticks received

Re: price() clarification [Re: swingtraderkk] #434446
12/18/13 17:42
12/18/13 17:42
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It's always the average of (high+low)/2 of all available ticks inside the bar period. 1-min bars can have 1 or more ticks, dependent on simulation or trade mode. TimeFrame just averages over all bar periods inside the time frame.

Re: price() clarification [Re: jcl] #434488
12/19/13 13:03
12/19/13 13:03
Joined: May 2013
Posts: 245
S
swingtraderkk Offline OP
Member
swingtraderkk  Offline OP
Member
S

Joined: May 2013
Posts: 245
Thanks jcl,

That helps but I'm still a little confused on terminology.

1) Average price to me from other platforms implied:
(high+low+open+close)/4
while (high+low)/2 was something I'd previously called a mid price.
Can this be clarified in the manual?

2) For backtesting when we use price() and our price data is the provided 1 minute tick structs with a HLOC, on barperiod = 1 then price() returns (high+low)/2 which is in my mind a mid price? Is this correct?

3) What happens when there is a gap i.e. no tick struct for a minute or minutes available at all?
Does zorro execute run() for a bar with no tick structs?
What does zorro plot? a gap?
What does zorro return when asked for price() for a specific minute it does not have a tick struct for, does it return null, an error or simply price() for the previous or next available tick struct?
How do indicators react to these gaps?

4) Still in backtesting, if barperiod is higher than 1 e.g. 5, then can you confirm that price() returns an average of the 5 x 1 min tick structs i.e.
((Min 1 :(high+low)/2) + (Min 2 :(high+low)/2) .... + (Min 5 :(high+low)/2))/5
This to me is close to a true average and provides superior smoothing to previous definitions of average such as (high+low+open+close)/4.
Can you also confirm that if that 5 min period in time contains more or less than five tick structs then the denominator is the actual number of tick structs available for that 5 minute period and the numerator is the sum of the midpoints (high+low)/2) for those tick structs?

5) In live trading, can I assume that the ticks received by zorro are single close prices i.e. there is no High Low or Open, so (high+low)/2) is actually close, therefore even at Barperiod = 1 in live trading price() returns a true average of all ticks received in that minute?

6) Does zorro then store each tick received as a tick struct back to the bar file? or does it store that minute's data summarised as a single HLOC in the Bar file?

7) What does zorro return for price() for a period in live trading where no ticks are received?

Thanks again for any help you can give.

Re: price() clarification [Re: swingtraderkk] #434493
12/19/13 15:21
12/19/13 15:21
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
1) I don't know what (high+low+open+close)/4 is called, but it is definitely not an average.

2) yes

3) price curves have no gaps; in backtests missing data is just skipped on the time axis.

4) yes

5) yes

6) it stores HLOC only

7) the last received average price.


Re: price() clarification [Re: jcl] #434499
12/19/13 16:25
12/19/13 16:25
Joined: May 2013
Posts: 245
S
swingtraderkk Offline OP
Member
swingtraderkk  Offline OP
Member
S

Joined: May 2013
Posts: 245
great thanks jcl, cleared a lot of things up for me.

only a few left:

a) Does zorro execute run() for a bar with no tick structs in backtest or is it skipped?
b) What does zorro return when asked for price() for a specific minute it does not have a tick struct for, does it return null, an error or simply price() for the previous or next available tick struct? e.g if I try to use timeoffset to get an opening or closing price of an exchange what happens if there is no tick struct for that bar?
c) Do indicators skip bars with no tick structs or use last price received?

Re: price() clarification [Re: swingtraderkk] #434501
12/19/13 16:56
12/19/13 16:56
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Any bar has always a price. There is no point in the price curve with no price. Any gaps, such as weekends, are only visible on the time axis, not in the price curve.

Re: price() clarification [Re: jcl] #435109
01/03/14 00:38
01/03/14 00:38
Joined: Aug 2013
Posts: 22
P
pipclown Offline
Newbie
pipclown  Offline
Newbie
P

Joined: Aug 2013
Posts: 22
I'll borrow this thread as well for some other questions regarding priceXXX()

When backtesting on 1-minute data, I observe some strange behavior where priceOpen() almost always equals priceHigh(). Same for priceClose() == priceLow().

However, when you look at the structs stored in the .bar history file you can clearly see much more different values for open, high, low and close.
Its as if priceOpen() and priceHigh() are identical for BarPeriod = 1 when backtesting.

Try this script:
Code:
int numBars = 0;
int numOpenHighNonMatching = 0;
int numCloseLowNonMatching = 0;

function run() {
	StartDate = 20070101;
	EndDate = 20070630;
	LookBack = 0;
	BarPeriod = 1;
	asset("EUR/USD");
	
	if (is(INITRUN)) {
		numBars = 0;
		numOpenHighNonMatching = 0;
		numCloseLowNonMatching = 0;
	}

	numBars++;
	
	if (priceOpen() != priceHigh()) {
		numOpenHighNonMatching++;
	}
	
	if (priceClose() != priceLow()) {
		numCloseLowNonMatching++;
	}
	
	
	if (is(EXITRUN)) {
		printf("\nNum bars received: %d\n", numBars - 1);
		printf("\nTotal non-matching: %d", numOpenHighNonMatching + numCloseLowNonMatching);
	}
}



For me that script outputs,
Code:
BackTest: bar_export EUR/USD 2007
Num bars received: 151067
Total non-matching: 43



Looking at the raw .bar files, I would expect non-matching to be much higher, even for BarPeriod = 1.
Naturally, turning up BarPeriod to say 60 or higher shows more normal and different values.

Do Zorro handle prices at BarPeriod = 1 differently compared to higher periods?

I also noticed that bars at the beginning of the year (those last in .bar file) are sometimes skipped for some reason?

Maybe I've just misunderstood something, but I've been scratching my head over this one for over 2 hours laugh
Thanks!

Last edited by pipclown; 01/03/14 00:38.
Re: price() clarification [Re: pipclown] #435119
01/03/14 07:59
01/03/14 07:59
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
No, BarPeriod 1 is not handled differently. It's however possble that the price functions return other values as in raw data, due to sampling. Bars are aligned, raw ticks aren't. For instance, if you have a price tick in raw data at 08:00:30 and the next one at 08:01:30, the 08:01:00..08:02:00 bar is sampled from 2 ticks.

There are also no bars skipped AFAIK. Maybe you mean the lookback period?


Re: price() clarification [Re: jcl] #435129
01/03/14 10:13
01/03/14 10:13

A
acidburn
Unregistered
acidburn
Unregistered
A



Good detective work pipclown!

May I suggest that this gets investigated deeper, jcl, because this looks like a serious problem to me.

Also I'm now completely confused with all this ticks/bars terminology. So far I thought that Zorro's history files contained only 1 minute OHLC bars. If that's right, then the above script reveals that something is really not OK with the history data.

And I also thought that using the word 'tick' in Zorro is just play of words. The real tick in forex represents a price change. So every time bid and/or ask changes and there is a transaction, the tick records new (bid, ask) values plus the exact time when it happened. That translates to tens of ticks for every 1 min bar nowadays. I just don't see how all those ticks compressed could translate to most of the 1min bars with no wicks (as demonstrated by pipclown).

I might be wrong, and I'll soon run the tests to prove or disprove my theory, but something's very fishy here...

Re: price() clarification [Re: ] #435130
01/03/14 10:22
01/03/14 10:22

A
acidburn
Unregistered
acidburn
Unregistered
A



OK, to add to my previous post, the only possible reason that most of those 1min bars could have been wickless is because it was 2007. and the market was moving much slower then. Pending further analysis...

Page 1 of 5 1 2 3 4 5

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1