Write Your Own Indicator
Last updated Nov 23, 2026
Write your own chart indicator in Candlescript, or describe it and let AI write it, then draw it on any torowick chart like the built-in ones.
Besides the built-in indicators, you can write your own in Candlescript, a short formula language made for charts. Your indicator gets the same gear, colours and pane buttons as the others, and it is saved to your account.
You write and edit indicators on a computer with a mouse and a wide screen. Phones and tablets, even held sideways, show the ones you wrote.
Write one
- Open a stock, tap Indicators above the chart, then All indicators.
- Pick My indicators on the side and tap + New. The editor opens on the right with an example to start from.
- Give your indicator a name and change the code.
- Tap Save and draw, or press Ctrl+S (⌘S on a Mac). It goes on the chart.
If something in the code is wrong, the line is marked and a message under the editor says what to fix, for example "line 2, column 7: unknown function rsii (did you mean rsi?)".
A new indicator goes on the chart and into your favorites. To change it later, tap the code button beside it in the menu or in All indicators.
Unsaved code is kept
While you write, the code is kept in this browser. If you refresh the page or close the tab before saving, the editor opens again with your changes and a note that they are back. Tap Save and draw to keep them, or Discard them to go back to the saved indicator.
Start from a built-in indicator
Every other indicator in All indicators has a code button too. It opens the indicator written in Candlescript, with your current settings, as a new copy. Change it and save it, and it joins My indicators, while the built-in one stays as it was.
Let Portia write or review it
The editor has two buttons above the code:
- Write with AI: describe what you want in plain words, for example "the RSI of the MACD" or "how far the close is from its 20-day average, in percent, as bars", then tap Write. Portia writes the script and explains how to read it. If you already have a script, she changes it as you ask.
- Review with AI: Portia reads your script and tells you what it does, any mistakes or likely bugs, and how to improve it.
When Portia suggests a script, it shows under the editor with the changed lines marked. Tap Apply to put it in the editor, or Dismiss to keep yours. Nothing changes until you tap Apply. Portia never gives buy or sell advice: she describes what an indicator shows.
Share it
Tap Share in the editor to copy a link to your indicator. Anyone signed in to torowick who opens it gets their own copy in My indicators, switched on, which they can change without touching yours.
How the language works
Each line does one thing: gives a value a name, or draws it.
len = input(14, "Length")
r = rsi(close, len)
plot(r, "RSI")
plot(sma(r, 9), "Average")
band(30, 70)
- Prices:
open,high,low,closeandvolumeare the candles.hl2is the middle of the high and low. - Names:
r = rsi(close, 14)gives a value a name to use on later lines. - Settings:
len = input(14, "Length")makes a number you can change with the gear. Addmin=andmax=to keep it in a range. - Earlier candles:
close[1]is the close one candle back. - Carrying a value: a line can read its own value on the candle before, so a total or a trend carries on from candle to candle.
obv = nz(obv[1]) + volumeadds each candle's volume to the total so far (nzgives 0 on the first candle, which has no candle before). Supertrend is written this way: open its code to see it. - Maths:
+ - * /, comparisons such as>and<=,and,or,not, andcondition ? a : b. - Drawing:
plot(value, "Title")draws a line. Addcolor="#2563EB",width=2,style="histogram",style="dots",style="step"oroffset=26(moves the line 26 candles right). - A band:
band(30, 70)shades between two levels, as RSI does. - Over the price:
overlay()draws over the candles instead of in a pane below. - Notes: anything after
//is a note to yourself.
Functions
| Function | What it gives |
|---|---|
sma(x, n), ema(x, n), wma(x, n), rma(x, n) | Averages over n candles |
rsi(x, n) | Relative strength index |
atr(n) | Average true range |
stdev(x, n) | Standard deviation over n candles |
highest(x, n), lowest(x, n) | Highest and lowest over n candles |
change(x, n), roc(x, n) | The change, and the change in percent, over n candles |
crossover(a, b), crossunder(a, b) | 1 on the candle where a crosses above (or below) b |
abs, sqrt, log, round, min, max | Number helpers |
na(x), nz(x, 0) | Whether a value is missing, and a missing value replaced |
vwma(x, n), hma(x, n) | Volume-weighted and Hull moving averages |
sum(x, n), cum(x) | The total over n candles, and the running total |
tr() | The true range of each candle |
linreg(x, n) | The least-squares line over n candles |
correlation(a, b, n) | How closely a and b move together, from -1 to 1 |
dev(x, n), median(x, n) | Mean absolute deviation and median over n candles |
percentrank(x, n) | The percent of the previous n values at or below this one |
highestbars(x, n), lowestbars(x, n) | How many candles back the highest (or lowest) value was, as 0 or less |
barssince(condition) | Candles since the condition was last true |
rsi(close, 14) gives the same numbers as the built-in RSI.
Examples
A moving average cross, over the price:
overlay()
plot(sma(close, 50), "Fast")
plot(sma(close, 200), "Slow")
How far the price is from its 20-day average, as bars:
plot(close - sma(close, 20), "Distance", style="histogram")
Limits
A script holds up to 5,000 characters and 200 lines, draws up to 10 lines and looks back up to 500 candles. You can keep up to 50 indicators of your own.
Still stuck?
Sign in and open Portia from any page in the app. Portia knows this guide and can show you where to tap.
Sign in