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

Re: Function NTHighestBar in Tradestation has a bug



PureBytes Links

Trading Reference Links

Here's the code from good old reliable TS4. 

"It ain't broke..... let's fix it." :-)

-- 
  Dennis

{ *******************************************************************

	Study		: NthHighestBar
	
	Last Edit	: 7/7/95

	Provided By	: Omega Research, Inc. (c) Copyright 1995

********************************************************************}
inputs: Nth(NumericSimple),Price(NumericSeries),Length(NumericSimple);
array: PriceArray[25](0),BarNumArray[25](0);
vars : X(0),Y(0),Z(0);

if Nth <= Length  And Nth <= 25
then begin
	for X = 0 to Length-1 
	begin
		PriceArray[X] = Price[X];
		BarNumArray[X] = X;
	end;
	for X = 0 To Nth-1 
	begin
		for Y =  X+1 To Length-1 
		begin
			if PriceArray[Y] > PriceArray[X] 
			then begin
				Value1 = PriceArray[X];
				PriceArray[X] = PriceArray[Y];
				PriceArray[Y] = Value1;
				Value1 = BarNumArray[X];
				BarNumArray[X] = BarNumArray[Y];
				BarNumArray[Y] = Value1;
			end;
		end;
	end;
	NthHighestBar = BarNumArray[Nth-1] + CurrentBar - BarNumber;
end
else
	NthHighestBar = -1;

-- 
  Dennis