Better way to get number of days high

I have a function to get the number of days high that can range from 5-day high to 260-day high. Here is my ugly code.

function getNumDaysHigh(Data, pct_threshold)
{
	NumDays_10=260;
	NumDays_9=200;
	NumDays_8=150;
	NumDays_7=100;
	NumDays_6=80;
	NumDays_5=60;
	NumDays_4=40;
	NumDays_3=35;
	NumDays_22=25;
	NumDays_2=20;
	NumDays_11=15;
	NumDays_1=10;
	NumDays_0=5;

	NumDaysHigh = IIf(Data>(pct_threshold * HHV(Data,NumDays_10) ), true_part = NumDays_10, 
						IIf(Data>( pct_threshold * HHV(Data,NumDays_9) ), true_part = NumDays_9, 
							IIf(Data>( pct_threshold * HHV(Data,NumDays_8) ), true_part = NumDays_8, 
								IIf(Data>( pct_threshold * HHV(Data,NumDays_7) ), true_part = NumDays_7, 
									IIf(Data>( pct_threshold * HHV(Data,NumDays_6) ), true_part = NumDays_6, 
										IIf(Data>( pct_threshold * HHV(Data,NumDays_5) ), true_part = NumDays_5, 
											IIf(Data>( pct_threshold * HHV(Data,NumDays_4) ), true_part = NumDays_4, 
												IIf(Data>( pct_threshold * HHV(Data,NumDays_3) ), true_part = NumDays_3, 
													IIf(Data>( pct_threshold * HHV(Data,NumDays_22) ), true_part = NumDays_22, 
														IIf(Data>( pct_threshold * HHV(Data,NumDays_2) ), true_part = NumDays_2, 
															IIf(Data>( pct_threshold * HHV(Data,NumDays_11) ), true_part = NumDays_11, 
																IIf(Data>( pct_threshold * HHV(Data,NumDays_1) ), true_part = NumDays_1, 
																NumDays_0 
																)
															)
														) 
													)
												)
											)
										)
									)
								)
							)							
						)	
					 ); 
					  
	return NumDaysHigh;
}

It is obviously ugly. Another limitation with my function is it can only return certain numbers like 260, 200, 150 ...

What I would prefer is to return numbers ranging from 10, 11, 12 ... all the way to 1024 (with increments of 1). I can't do that with my implementation because the nested IIF loop will be too huge and unmanageable.

Any elegant way to improve my ugly code? Thanks.

Something like

Data = Close ;

for ( i = 1; i < 1100; i++ )
	{
		VarSetText( "NumDays"+i, NumToStr( HHV( Data, i ) ) ) ;
	}
	
	Filter = 1 ;
	
	AddColumn( Close,  "Close", 1.2 ) ; 
	
	AddtextColumn( NumDays1, "NumDays1" ) ; 
	AddtextColumn( NumDays10, "NumDays10" ) ; 
	AddtextColumn( NumDays100, "NumDays100" ) ; 
	AddtextColumn( NumDays1000, "NumDays1000" ) ; 
3 Likes