[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Help needed for "Highest / Lowest value of the last n-bars" problem



PureBytes Links

Trading Reference Links

I wrote this code, which pretty much seems to do what exactly I need. 
I put it her incase somebody else needs it. Please note that the 
backward iterations take some time so saving, syntax checking, 
plotting whatsoever takes longer than usual. Any code optimization 
for faster calculation is highly welcome if shared. I think 
calculation would be much faster with array notation and formulation 
but I couldn't think of one, so please enjoy.

TestArray = MA(C,15);
HighestOf[0] = LowestOf[0] = 0;
for (i=1; i < BarCount; i++)
{
	j = 0;
	do
	{
		Mode1Hit = TestArray[i - j] < TestArray[i] AND 
TestArray[i-j-1] >= TestArray[i];
		Mode2Hit = TestArray[i - j] > TestArray[i] AND 
TestArray[i-j-1] <= TestArray[i];
		j++;
	} while (!Mode1Hit AND !Mode2Hit AND j+1 < i);
	
	if (Mode1Hit)
	{
		HighestOf[i] = j;
		LowestOf[i] = 0;
	}
	if (Mode2Hit)
	{
		HighestOf[i] = 0;
		LowestOf[i] = j;
	} else {
		if ((TestArray[i]-TestArray[i-1]) > 0)
		{
		HighestOf[i] = j;
		LowestOf[i] = 0;
		}
		
		if ((TestArray[i]-TestArray[i-1]) < 0)
		{
			LowestOf[i] = j;
			HighestOf[i] = 0;
		}
	}
}

Plot(TestArray,"Test Array = MA Close 15",colorBlack,styleLine);
Plot(HighestOf,"Highest of Last...",colorGreen,styleDashed + 
styleOwnScale);
Plot(LowestOf,"Lowest of Last...",colorRed,styleDashed + 
styleOwnScale);



Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.15/581 - Release Date: 12/9/2006 3:41 PM