donchian inside an asset loop

Posted By: Cheulmen

donchian inside an asset loop - 02/15/18 16:44

Hi, I'm trying to calculate inside a loop the DCHannel() to test if there has been or not a breakout, but I'm getting an error 041. I'm using a portfolio system, this is an excerpt:

function run()
{
int N = assetList("Assets");
for (i=0; i<N; i++);
{
asset(Assets[i]);
vars Prices = series(priceClose());

DChannel(50);

vars upb = series (rRealUpperBand);

if (Prices[0] > upb[1])
enterLong();
}
}

What am I doing wrong? I just want to compare the current price of a specific asset with some TA indicator (a Donchian channel in the example) for that asset, to decide if enter or not in the trade. I checked the manual but still I don't understand what's happening.
Posted By: Zheka

Re: donchian inside an asset loop - 02/15/18 18:20

Your script compiles and runs fine on my end, without errors.

Error 041 is about "series declaration" (look under remarks for "series()" in the manual). So, try declaring series before if and for () statements.
Posted By: AndrewAMD

Re: donchian inside an asset loop - 02/15/18 18:37

I really don't know what you did wrong, because I'm not getting any errors.

Side note: your code would be cleaner if you used the loop function as follows:
Code:
function run()
{
	assetList("AssetsFile.csv");
	while(loop(Assets))
	{
		asset(Loop1);
		vars Prices = series(priceClose());
		DChannel(50);
		vars upb = series (rRealUpperBand);
		if (Prices[0] > upb[1])
		enterLong(); 
	}
}

Posted By: Cheulmen

Re: donchian inside an asset loop - 02/15/18 19:49

Yes, the script compiles correctly, but when I run it the error appears. The problem if I declare the series outside the for(), is that, as I understand, the rRealUpperBand is not going to belong to each one of the Assets[i]. Actually if I declare it outside the for(), probably Zorro won't be able to determine which is the asset that it should calculate.
Posted By: AndrewAMD

Re: donchian inside an asset loop - 02/15/18 20:18

This error cannot be replicated.

Post your exact c file, post your asset csv file, name your broker.
Posted By: Cheulmen

Re: donchian inside an asset loop - 02/15/18 22:13

Yes, it seems something in my script, two of you already said that it works, so I'll have to figure out whats wrong. I understand that if it can't be replicated, it can't be fixed.

I sincerely thank you for your help, I know that you're trying to help, but I don't want to post the script, it is my trading strategy (this was an attempt to improve it) laugh

Thanks again AndrewAMD & Zheka.
© 2024 lite-C Forums