ITMScript
Outputs
The statements that draw or record a result, what each one takes, and why a study that gives no output is refused.
A study gives its result through outputs. Six statements draw or record. A study with no output at all is refused.
| Statement | Gives |
|---|---|
plot | A line, columns, a histogram or another style of a series. |
plotshape | A marker on each bar where a condition is true. |
hline | A horizontal line at a fixed level. |
fill | The space between two plots. |
bgcolor | A tint behind the bars. |
alertcondition | A record of the bars where a condition is true. |
plot
plot takes a series and a label. The options are color, width, style, offset and pane. The width is a whole number from 1 to 8. The styles are listed on the colours and styles page.
A plot's colour may change bar by bar: a colour name, a hex value, an input of the colour kind, or a condition that picks between them. The colour of a fill and of a background may change bar by bar in the same way. A level's colour is one colour for the whole study.
This study draws one average. The line is green on a bar where the close is above the average and red on every other bar.
//@itmscript 2
study("Per bar colour", overlay=true)
avg = ta.sma(close, 20)
plot(avg, "Average", color=close > avg ? color.green : color.red, width=2, style=line)offset=n draws the plot n bars ahead of the bar it is read on, with n a whole number from 0 to 500. n may be a number, the name of an int input, or arithmetic over int inputs and numbers, as in offset=shift - 1. The value is read when the study compiles, from the inputs the study runs with, and it must come to a whole number from 0 to 500. Tidy writes an arithmetic shift as a name on the line above the plot, and the plot reads that name. The offset moves the line and changes no value. The last n values are drawn after the last bar, in the places the chart will have next. The time and sessions page says where those are. A negative offset is refused. To use a value from n bars ago, read it with x[n]. An Ichimoku cloud draws its two leading spans 26 bars ahead this way.
//@itmscript 2
study("Lead line", overlay=true)
shift = input.int(26, "Shift", min=1, max=100)
plot(ta.sma(close, 20), "Average", color=color.blue, offset=shift - 1)A condition that cannot be worked out on a bar picks the second colour, the one after the colon. A comparison with an earlier bar cannot be worked out on the first bar that has a value, so that bar takes the second colour.
A level is at one place, so it takes one colour. Giving a level a colour that changes from bar to bar is refused. The message says that a per-bar colour goes on plot, plotshape, fill and bgcolor.
//@itmscript 2
study("Per bar colour", overlay=true)
hline(50, "Mid", color=close > open ? color.green : color.red)plotshape
plotshape takes a condition and marks the bars where it is true. The options are style, location, color and text. Its colour may be a condition that picks between two colours, as a plot's may. Each marker takes the colour of its own bar.
//@itmscript 2
study("Marks", overlay=true)
plotshape(close > ta.highest(high[1], 20), style=triangleup, location=belowbar, color=color.green, text="High")hline
hline draws a level. The level is a number or an input, because it sits at one place for the whole study.
//@itmscript 2
study("Level", overlay=false)
level = input.float(70, "Level", min=0, max=100)
plot(ta.rsi(close, 14), "RSI", color=color.purple, width=2, style=line)
hline(level, "Overbought", color=color.gray, style=dashed)fill
fill takes the names of two plots, not two series. Give each plot a name first. A fill's colour may be a condition that picks between two colours, as a plot's may. The band is drawn in the colour its own bars pick.
//@itmscript 2
study("Zone", overlay=false)
top = plot(70, "Top", color=color.gray, width=1, style=line)
bottom = plot(30, "Bottom", color=color.gray, width=1, style=line)
fill(top, bottom, color=color.new(color.purple, 90))bgcolor
bgcolor tints the bars where its colour is not missing. Its colour is a condition, so the tint appears on the bars you choose and nowhere else. The tint is drawn behind the bars and runs the full height of the pane.
//@itmscript 2
study("Tint", overlay=true)
bgcolor(close > open ? color.new(color.green, 92) : na)alertcondition
alertcondition takes a condition, a title and a message. It records the bars where the condition is true. It does not send anything by itself.
//@itmscript 2
study("Cross alert", overlay=true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
alertcondition(ta.crossover(fast, slow), "Cross up", "The fast average crossed above the slow one")Other spellings and refused keys
A statement reads only the keys listed for it. A key it does not read is refused, and the message lists the ones it does. It is never dropped without a word.
//@itmscript 2
study("Smooth", overlay=true)
plot(close, "Close", smooth=2)A few other spellings are accepted, such as title= for a label and linewidth= for a width. They are listed with the styles.
An empty study
A study that draws, alerts and gives no readout is refused. Add one of the statements above.
//@itmscript 2
study("Nothing", overlay=true)
avg = ta.sma(close, 20)The words value, events, periods, screen, table and field give numbers and rows for readouts and tables. They are not covered on this page.