Series within loop

Posted By: tradingest

Series within loop - 10/07/18 21:39

Hi guys,

I want to calculate the Open and Close price of the candle of the previous day. To do this I use the code below but my function run() is performed each 1 min (BarPeriod = 1) and I see the same value for each minute as shown here.

Code:
vars PriceC = series(priceClose()); 
vars PriceO = series(priceOpen());


I have 2 question about the point above:

1. Is it possible to skip each minute and calculate the daily value at the previous candle only once?

2. Inserting the series within loop the message is Error041: Inconsistent series!. I see the manual but I don't understand how to avoid this problem.

Code:
if(hour() == 00)
{
while(asset(loop(Assets)))
   {
   vars O = series(priceOpen());
   vars C = series(priceClose());
   }
}



Can you help me to resolve it?

Thanks in advance
Posted By: tradingest

Re: Series within loop - 10/13/18 18:21

some reference?
Posted By: Spirit

Re: Series within loop - 10/15/18 17:03

Your code makes not really sense, why not using dayOpen and dayClose of the previous day?
Posted By: tradingest

Re: Series within loop - 10/15/18 19:54

Originally Posted By: Spirit
Your code makes not really sense, why not using dayOpen and dayClose of the previous day?


you can help me to find dayClose and dayOpen on previous day?

You must consider that the prices on my broker are UTC and I want to calculate open and close of previous day at UTC+2

Thanks
Posted By: Spirit

Re: Series within loop - 10/16/18 01:38

Yes you can set it with Startmarket and Endmarket, look here: http://manual.zorro-project.com/day.htm.
Posted By: tradingest

Re: Series within loop - 10/16/18 19:44

Hi Spirit,

thank again for your support but I don't understand how I can obtain what I want.
After your advice I created the code below:
Code:
#include <profile.c>

function run()
{

assetList("AssetsFix");
StartDate = 20181009;
EndDate = 2018;
StartMarket = 0000;
EndMarket = 2259;
LookBack = 1440;
BarPeriod = 1;

	while(asset(loop(Assets)))
		{
			var C = dayClose(UTC,1);
			var O = dayOpen(UTC,1);
		print(TO_WINDOW,"n Date: %02d-%02d-%02d %02d:%02d, %s , O = %f, C = %f",day(),month(),year(),hour(),minute(), Asset,O,C);
		}
}


I want obtain the Open and Close of the previous daily candle.
My function run is performed each 1 min (BarPeriod = 1) and in this way I can't obtain what I want.

The broker at UTC time and I want obtain the daily candle at UTC+2.

would you be kind enough to help me?

Thanks again
Posted By: Spirit

Re: Series within loop - 10/17/18 13:22

If the time zone is 2, then set the zone to 2 in the dayclose and dayopen functions.
Posted By: tradingest

Re: Series within loop - 10/17/18 13:24

Originally Posted By: Spirit
If the time zone is 2, then set the zone to 2 in the dayclose and dayopen functions.


Even if the BarPeriod = 1?
It will take the correct value?

Is it correct the code below?
Code:
var C = dayClose(UTC+2,1);
var O = dayOpen(UTC+2,1);

Posted By: Spirit

Re: Series within loop - 10/18/18 11:22

Better use CET. UTC is a #define and i think you cannot add 2 to it.
© 2024 lite-C Forums