Logic
15 entries. What each one takes, what it returns, and a working example.
The number of bars since the condition was last true (na if it has not happened yet).
E.g. to measure how many bars have passed since the last breakout.
plot(barssince(crossover(close, sma(close, 20))))
The number of bars since the last cross-above.
The difference between source and its value n bars ago.
Measures momentum/difference; a positive value indicates an increase.
plot(change(close, 1))
The price difference between this bar and the previous one.
crossover or crossunder; use those for direction distinction.
plotshape(cross(close, sma(close, 20)), style="xcross", location="absolute")
A mark on every bar where price crosses SMA20 (regardless of direction).
A boolean series that is true on the bar where a crosses above b, and false on all other bars.
It is true only on the bar where the cross occurs. A constant number can be given instead of b (e.g. a threshold).
plotshape(crossover(close, sma(close, 20)), style="triangleup", location="belowbar", color="#26a69a")
A green triangle below the bar where price crosses above SMA20.
A boolean series that is true on the bar where a crosses below b, and false on all other bars.
It is true only on the bar where the cross occurs. It is the downward counterpart of crossover.
plotshape(crossunder(close, sma(close, 20)), style="triangledown", location="abovebar", color="#ef5350")
A red triangle above the bar where price crosses below SMA20.
E.g. cum(volume) is total volume; the basis of cumulative indicators (like obv).
plot(cum(volume))
The cumulative total volume from the start (an ever-rising line).
True if there is an uninterrupted decrease over the last length bars.
length consecutive comparisons are made; if even one does not decrease, the result is false.
plotshape(falling(close, 3), style="circle", location="abovebar", color="#ef5350")
A red circle above bars where the close fell without interruption over the last 3 bars.
A series holding the highest value over the last length bars (rolling max).
Commonly used in breakout rules: close > highest(high, 20).
plot(highest(high, 20))
The highest peak of the last 20 bars (upper breakout level).
The distance to the highest value: 0 = current bar, −k = k bars ago.
Answers the question of how long ago the peak formed (gives the location of the highest value).
plot(highestbars(high, 10))
How many bars ago the 10-bar peak was (0 = this bar, negative = past).
iff(condition, ifTrue, ifFalse)
For each bar, ifTrue or ifFalse depending on the condition (element-wise selection).
Used in place of a ternary operator; commonly used to produce a color series.
plot(close, color=iff(close > open, "#26a69a", "#ef5350"))
A line colored green on up bars and red on down bars.
A series holding the lowest value over the last length bars (rolling min).
Used for support breaks and tracking lows.
plot(lowest(low, 20))
The lowest trough of the last 20 bars (lower support level).
The distance to the lowest value: 0 = current bar, −k = k bars ago.
Answers the question of how long ago the bottom formed.
plot(lowestbars(low, 10))
How many bars ago the 10-bar trough was (0 = this bar, negative = past).
A series holding the value from n bars ago.
For comparing with the previous bar: close > prev(close, 1).
plot(prev(close, 1))
Carries the previous bar's close onto this bar (lag of 1).
True if there is an uninterrupted increase over the last length bars.
length consecutive comparisons are made; if even one does not increase, the result is false.
plotshape(rising(close, 3), style="circle", location="belowbar", color="#26a69a")
A green circle below bars where the close rose without interruption over the last 3 bars.
valuewhen(condition, source, occurrence=0)
The source value on the relevant true bar of the condition.
E.g. to remember the price at the last buy signal: valuewhen(buySignal, close, 0).
plot(valuewhen(crossover(close, sma(close, 20)), close, 0))
Carries the close from the most recent cross-above bar as a horizontal level.