Need help in writing a list with numbers in sequence

I am looking for a convenient way to write a list containing numbers in sequence.

For example, I am going to write

High1 = Max(Ref(H,-1),Ref(H,-2));
High2 = Max(High1, Ref(H,-3));
High3 = Max(High2, Ref(H,-4));
High4 = Max(High3, Ref(H,-5));
High29 = Max(High28, Ref(H,-30));

The result of High1 ~ High29 will be used with ParamList.

Instead of writing the above list line by line,
is it possible to re-write in a more smart way such as for loop?

That may help

HV = HHV(high,Cum(1)-int((cum(1)/29))*29);


T = "";
for ( i = 0; i <= 29; i++)
	T += NumToStr(HV[i],1.2,False)+"\n"+"|";

paramlist("Parameter Name",T,0);

As for using Max() or Min()...

See here

So in your case

function VarGetMax( varname, num ) {
    /// How to use:
    /// @link
    local n, maxall;
    maxall = -1e9;
    for ( n = 1; n <= num; n++ )
        maxall = Max( maxall, VarGet( varname + n ) );
    return maxall;

maxn = Param( "Number of previous Bar Highs", 30, 1, 50, 1);

for ( n = 1; n <= maxn; n++ ) {
  VarSet( "High" + n, Ref(H, -n));
  printf( "%g High%g variable: %g\n", n, n, VarGet( "High" + n ) );

// Overall maximum High
getmax = VarGetMax( "High", maxn );
printf( "\nMax. of %g Variables: %g", maxn, getmax );

BUT... why doing such way here in this case since just a single function HHV() is required to get highest high value of a past number of bars?

maxn = Param( "Number of previous Bar Highs", 30, 1, 50, 1);
getmax = Ref(HHV(H, maxn), -1);
printf( "\nMax. of %g Variables: %g", maxn, getmax );

So I do not understand why you want to use Max() function here.

On the other hand if you want to store each iteration then...

num = 30;
for ( n = 2; n <= num; n++ ) {	
	VarSet( "High" + (n-1), Ref(HHV(H, n), -1));	

You can not store variable arguments to Param* functions. Params are not designed for such things. Param* are cached and expect their arguments to be pre defined -> fix. For example in your case if you keep Param window opened and you scroll chart then such list won't change.
Don't do that. It is road to disaster.

@Sebastian, you are misusing Param*. Don't do that.


Thanks @fxshrat for the precious info :sunflower:

1 Like

Many thanks for detailed explanation.
It is above my head so I need to study more.
Thanks for all of you.