Trailing Stop using Last Down Bar


Can anybody please help.

I am trying to script a trailing Stop Loss which uses the last Down Bar. As per the attached diagram.

I have used LOW() <= LAST(BARTYPES().Lower Also tried other variations like CrossesUnder and Crosses.

However the “LAST()” function does not work as I think!

Does anyone know what does?

Also would like to know how to correctly use LAST() function.

Thanks in anticipation,



Hi Lester,

LAST() plots the latest value of the tool or price. See here for examples:

To get the value of the last low of a lower bar (including an outside bar) use the VALUEWHEN() function:

V1 = BARTYPES().Lower or BARTYPES().Outside;

So the stop formula would be when the low value of the lower/outside bar is lower than the previous:

// Identify lower & outside bars;
V1 = BARTYPES().Lower or BARTYPES().Outside;
//Get the low value when V1 is true
//Signal when low is lower
V2 IsDown

The blue line is the low value and the red Show Bars are when they are lower: