BarIndex() of Test Start Date and Test End Date

I’d like to iterate from Test Start Date to Test End Date

In pseudo-code it would be like:

myStart = BarIndex ( Status("RangeFromDate") )  );
myEnd   = BarIndex ( Status("RangeToDate")   )  ) + 1;

for( i = myStart; i < myEnd; i++ ) { };

I’ve searched the User Guide & forum, & tried a few methods without success.

Any tips on what to put in the BarIndex() calls are appreciated.

And Happy Thanksgiving to all esp, the US board members.

1 Like

I’d like to iterate from Test Start Date to Test End Date

Just do this

bir = Status( "barinrange" );

for( i = 0; i < BarCount; i++) {
	if( bir[i] ) { // if code iterates within range from-to of analysis toolbar
		// then do something
	}
}
3 Likes

How about something like this:

myStart = LastValue(ValueWhen(Status("FirstBarInRange"), BarIndex());
myEnd = LastValue(ValueWhen(Status("LastBarInRange"), BarIndex());
2 Likes

You guys are good!

Thanks for the help.

I wound up using @mradtke 's suggestion – nice and clean –

myStart = LastValue(ValueWhen(Status("FirstBarInRange"), BarIndex()));
myEnd   = LastValue(ValueWhen(Status("LastBarInRange"),  BarIndex()));

for( i = myStart; (i <= myEnd); i++ ) {	
  //myCode
}

@stevo713

How is that nice and clean? It is neither one nor is it the other one nor is it flexible. It is rather bad idea doing it that way. If that one is nicer and cleaner than using “barinrange” status code then I seem to have accidentally jumped into a parallel universe (Sam Beckett, are you there? Or “Sliders” perhaps?) where nice and clean have different meanings.

Just imagine, you would have to do two loops if you want to iterate through entire barcount for one code section in addition to your analysis range iteration approach. In addition such approach is bloated and unnecessary over-complication.

// BAD idea

myStart = LastValue(ValueWhen(Status("FirstBarInRange"), BarIndex()));
myEnd   = LastValue(ValueWhen(Status("LastBarInRange"),  BarIndex()));

for( i = myStart; (i <= myEnd); i++ ) {	
  //your first code iterating bars of range
}

for( i = 0; i < Barcount; i++ ) {	
  //your other code (requiring) looping entire barcount or whatever
}

compared to flexible loop

// Good and the real nice and clean one

bir = Status( "barinrange" );

for( i = 0; i < BarCount; i++) {
	// code iterating entire barcount or whatever

	if( bir[i] ) { // your code iterating bars of analysis range
		// then do something
	}
	// or code here iterating entire barcount or whatever
}

So it would have made more sense (to me) if you would have written “I prefer doing things like so” (less nicer, less cleaner, less flexible). Then personally I wouldn’t have any reason to argue about it (and with less hairs standing up) and begging your pardon.

Just so many rather bad (code) ideas on the Internet.

Sorry, but really.

BTW,

1 + 1 = 2
-1000 + 1004 - 2 = 2 

I wonder which one is nicer and cleaner.

3 Likes