BARSTRUE Script

I am having trouble with BARSTRUE so that every bar for custom indicators is below 1.00 for the last 10 bars. So far I have below but is not performing correctly. Can someone please assist? Thanks

R1 = ANY CUSTOM INDICATOR
BARSTRUE(R1, LOOKBACK=10) < 1.00

Hi,

R1 in your example needs to be a Boolean result before it can be used with the BarsTrue function.

Quick example code:

//Set Custom Criteria
V1 = CLOSE() > OPEN() ;
V2 = VOLUME() IsUp;
V3 = CLOSE() > MA(BARS=20) ;
V4 = ADX() IsUp ;
//Add Criteria Together
V5 = V1 + V2 + V3 + V4;
//Less than 1 of the 4 criteria are True
R1 = V5 < 1;
//How many times in the last 10 bars has R1 been true
BARSTRUE(R1, LOOKBACK=10)

The result on a Show View would look like this:

Ex2

You can see the highest result returned was 4 out of 10 days R1 was true.

Apologies, should of mentioned this is for a scan so wouldn’t I need to implement:

BARSTRUE(R1, LOOKBACK=10) < 1.00

as I am also not sure how to add Boolean to a MA script like:

MA1 = MA(BARS=21, STYLE=Exponential, CALC=Close);

In your first script example, that scan would only return a pass if the number of bars that met the criteria over the last 10 days was zero.

If you look at the example in my reply you can see that the BarsTrue (when using a look back period of 10) will procedure a result that oscillates between 0 and 9. A result of zero means none of the bars checked passed the criteria, and 9 means all bars checked passed the criteria.

For the simplest example, set the criteria to be Close() > Open() and use that with BarsTrue(), the output will change between 0 to 9.

Ex3

To use it with a scan i’d just need to adjust the BarsTrue line to output a Boolean result. For example:

V1 = CLOSE() > OPEN() ;
BARSTRUE(V1, LOOKBACK=10) > 5

Would mean the criteria would have to have passed 5 out of 10 bars to pass.

With your second script, the line would output the Moving Average value. To convert it to a Boolean you have to setup a rule. I’m not sure what you’re looking for but some common examples are

Close() > MA()

or

MA() IsUp

Anything that returns a 1 or 0 result will work with BarsTrue()

https://help.optuma.com/kb/faq.php?id=1118

GOT IT! Thanks so much