price...() returns last bar close regardless of TimeFrame

Posted By: ozgur

price...() returns last bar close regardless of TimeFrame - 12/26/19 14:09

Hi,

I am reading through the Manual and the "price" page says

Quote

Returns the open, close, maximum and minimum price of the bar period or time frame with the selected asset. priceClose(0) returns the current price.


Then I made this very simple script below.

Code
function run()
{
	BarPeriod = 60;
	TimeFrame = 4;
	
	vars cls_series = series(priceClose(0));
	var cls_val = priceClose(0);
	
	printf("\nFrom series: %f vs Other: %f", cls_series[0], cls_val);
}


As you can see the screenshot below, priceClose() returns the last bar (1 hour TF) value instead of the last Timeframe (4 hour TF) value unless it is defined as series(). I was expecting values from both series and single variable same. Am I missing something?

Thanks a lot

Note: I also tried other price functions such as price(), priceOpen() as well, experiencing the same behaviour.

Output:
[Linked Image]

Posted By: SBGuy

Re: price...() returns last bar close regardless of TimeFrame - 12/27/19 17:18

I believe priceClose(0) is the price right now!

series() is only added at a TimeFrame of 4*60 (4 hours).

That's why the printfs are different.

At every 4 hours those 2 numbers will be the same in your printf, which appears to be the case.
Posted By: ozgur

Re: price...() returns last bar close regardless of TimeFrame - 12/27/19 21:51

Yeah, I think the manual is a bit vague though. I just wanted to check if I am doing something wrong.

Thanks.
Posted By: Zheka

Re: price...() returns last bar close regardless of TimeFrame - 12/27/19 22:11

Can you try and see what will be the value of priceOpen(0)?
Is it equal to the priceClose() of the last complete 4-hour candle, or of the last 60-min bar?
Posted By: AndrewAMD

Re: price...() returns last bar close regardless of TimeFrame - 12/28/19 00:01

Using this code:
Code
function run()
{
	StartDate = 20191101;
	EndDate = 20191227;
	BarPeriod = 60;
	TimeFrame = 4;
	assetList("AssetsFix");
	asset("EUR/USD");
	
	var p = price(0);
	var o = priceOpen(0);
	var h = priceHigh(0);
	var l = priceLow(0);
	var c = priceClose(0);
	
	vars P = series(p);
	vars O = series(o);
	vars H = series(h);
	vars L = series(l);
	vars C = series(c);
	
	if(Init)
		print(TO_CSV,"yyyy-mm-dd HH:MM,frame(0),p,P[0],o,O[0],h,H[0],l,L[0],c,C[0]\r\n");
	else
		print(TO_CSV,"%04d-%02d-%02d %2d:%2d,%d,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f\r\n",
			year(0),month(0),day(0),hour(0),minute(0),
			frame(0),p,P[0],o,O[0],h,H[0],l,L[0],c,C[0]
			);
	
}
...produces the attached CSV. It appears that priceOpen et. al. ignores frame(0), which is fine so long as you are using a series.

Attached File
ohlc.csv  (69 downloads)
Posted By: ozgur

Re: price...() returns last bar close regardless of TimeFrame - 12/28/19 00:31

Thanks Andrew.

What is the source of your EURUSD data? I see 10 - 20 pip gaps between current open vs previous close (non-series function) which is a bit concerning. This seems not to be an issue with data from series though, so may not be data related issue. Then the question is what value do price functions return when frame is 0? Could this be a bug?
Posted By: AndrewAMD

Re: price...() returns last bar close regardless of TimeFrame - 12/28/19 10:34

Look closer. Every single entry is four-bar. laugh
Posted By: Zheka

Re: price...() returns last bar close regardless of TimeFrame - 12/28/19 13:36

So, it is a 'rolling' 4-hour bar...I am not sure earlier versions had this behavior.

And this is not at all what the manual implies.

But now knowing how it works, this 'feature' might have some applications.


Posted By: ozgur

Re: price...() returns last bar close regardless of TimeFrame - 12/29/19 01:34

Yeah, it has to be that way for priceOpen() @ TimeFrame=4, otherwise it would return open price of current H4 incomplete candle.
© 2024 lite-C Forums