Using Worksheets to Build Custom Indicators

New in Trader Beta 1.210702, Worksheets allow a person with (almost) no programming skills to compose new plots by combining existing indicators and features. Worksheets are an extension of custom Indicators. We can start a new Worksheet by selecting it from the Indicators dropdown on any chart:

When you begin a new Worksheet, you’ll be presented with this modal:

Here, you can add expressions to your Worksheet. An expression is simply an existing indicator or a combination of existing indicators combined using some mathematical operation (like addition, subtraction, etc), and defined with a Plot specification (the options below the expression). Some supported operations include:

  • Any of the JavaScript native Math object functions, such as Math.abs or Math.min.
  • Ternary expressions such as sma(10) < ema(10) ? ema(10) : sma(10)
  • Indicators as parameters to indicators, such as sma(ema(10))

To get some help with parameters and what indicators are available as expressions, start typing. Once you’ve entered some text, code-completion will attempt to search for the most relevant indicators based on your entry.

For advanced users looking to make their indicators available in Worksheets, the parameters shown in the code-completion form are named based on the names that you provide on your indicator’s module.exports object’s params field.

When you select a specific indicator while code completion is active, you’ll get additional information about that indicator. This includes a human-readable name and all the possible variations of parameters for that indicator.

A Note About Params: Notice in the image above that percentB has both period and input parameters. The value for input can be another indicator, but period cannot. We can only use other indicators as the input, not the parameters that expect single values.

Composing Multiple Indicators

To add additional indicators, click the Add More link.

As you add more expressions, you can come up with interesting things. Here’s a variation on the Alligator indicator written as a Worksheet in about 1 minute:

Advanced Features

Additional to composing indicators with ease, you can provide indicators as parameters to other indicators:

If we look at this image we can see some excellent examples of how to combine these features. Let’s look closer at some of these expressions and plot specifications:

  • In expression #2 (top), we see the combination of an sma indicator with the less-than operator. In the plot specification ‘How To Plot’ is set to Coloring. This is a powerful combination for coloring bars under a certain condition.
  • In expression #3 (middle) we see an sma being applied as a parameter to the outer sma expression, as well as an arithmetic operation (-atr(10)) being applied to the result of that expression. We can combine our indicator expressions at will, however we like.
  • In expression #4 (bottom) we see a plain number. This will just create a line at that price on the X-axis.

We hope that Worksheets will open up a new way for Traders to build unique studies without having to be particularly code-savvy, maximizing creativity while minimizing overhead and planning. Worksheets are a great way to scaffold an idea, or gauge interactions between different trends, or even just play around and discover new possibilities - be creative!

Alexander, do you know where I may find a list or guide to common charting/plotting functions or indicators available via Worksheet? I want to automate the plotting of Overnight highs & Low or other recent highs/lows. Sounds simple, if I know the functions and some very basic syntax.

Any indicator that you can use from the Trader application can be used as a function in Worksheets. The best resource is just to play with indicators on the Trader app. Any indicator available will also show up in the intellisense hints.

You’ll see a details box that tells you about the possible parameters and gives you some details about the indicator in question.

Here’s an example of highs and lows using Price Channel:



Thank you for the response. Very helpful.

Hi. Thanks for the provided information. I have been testing out a few setups within the "Worksheet and was wondering if there is a way to add a arrow or an indicator of some sort within the “Worksheet”.

ex: If "Expression #1 thru Expression #3 intersect the same candle at the same time add a specified colour arrow, dot over the candle or area.

Thanks in advance

Hi @KE_vf,

You could certainly do that within a worksheet, but you’d have to write a custom indicator to make the arrow.

If you are adverse to writing code, you could always use Bar Color as an alternative with whatever your condition for drawing the arrow would be. Then the bar would just be highlighted instead of having an arrow drawn.

If you’re code-savvy and want specifically this behavior, follow the CI Graphics tutorial - it’s almost what you want to do already; it teaches you how to draw dots or exclamation bubbles over select bars.

Hope this helps!

Good morning.
Your Bar Color alternative would be perfect for what I was looking to do. Can you tell me how I would would change the color if ex: “Expressions 1-4” intersect the same candle?

Thanks for your reply.

If you want to use values from indicators in expressions 1 through 3 you’ll have to use the same indicators again in the next expression, with logical operators to make the return a boolean value.

ind1(params) === ind2(params) && ind1(params) === ind3(params) && ...

where indN would be the indicator(s) you used for that particular expression. Your conditions are probably more complicated than that in reality, but the concept is there. The other thing you need to do to color bars is choose the ‘Coloring’ option from the ‘How to plot’ dropdown for the expression you want to have color the bars.

As an added FYI - from what you are describing, you may find === is not sufficient - you’re looking to compare the last and next values most likely (to see if there is a crossover between your existing expressions’ values), which you might still have to write a custom indicator for. The reality of === is that it will only highlight bars where your expressions’ indicators all share the same Y value at the given X (you’ll find it’s a once-in-a-blue-moon kind of situation and you’ll definitely miss crossovers).

My suggestion would be to look through the community custom indicators and see if you can find an indicator that does what you want already - there are tons of custom indicators in circulation. You can use a custom indicator in a Worksheet just the same as any other indicator.

I think I understand the basic logic you’ve layed out. In your ex is (params) the x/y location value? If so how would I define coordinates?

I did look through the custom indicators and have been monitoring them for a while but I found nothing that does what I’m looking for. So I got feed up and decided to try and see if I could tackle it.

I understand that I would miss some crosses with the setup but I do typically get 1-3 times a day where all my perimeters are satisfied. Leaning on my strong suits I made it a statistical problem; I added my defined signals, variables and defined outcomes to a spreadsheet that I backtested 5 months of data looking between 8:30am -2:30pm. As a engineer I’m great with data and statistics just not the best at coding .lol

I do appreciate the time you’ve taken to assist me.

That’s a very mathematically sound approach, it definitely sounds like you’ve put a lot of thought into this! In my pseudo-worksheet example, (params) refers to the parameters you pass to the indicators in question.

So for example in sma(36) - simple moving average over 36 bar period - (36) is the (params) section and sma is indN.

params are different for different indicators, but the hints you see when you start typing (this is called ‘intellisense’) are designed to help you understand what params you need to call the indicator.

I was trying your suggestion. I added a new expression and added the logic like below. It didn’t show anything. I usually use Heikin Ashi so I switched it to bars but I still didn’t see the color change.
I also tried using the “Coloring” option from the available “How to plot” options.
wma (15) === sma(5) wma (15) === sma (12)

I’ve uploaded a screen shot of the chart to show a bar where the logic should have been satisfied.

FYI…I’m using shifts on the MAs.
Do you have any suggestions?


I’ve been playing with this idea, and you’re probably not going to get this working very well with worksheets alone. You’ll likely need a custom indicator anyway. But what you mainly need to detect when lines crossover and which direction they crossover is the current and previous values of that indicator line. So if you’re using predefined indicators, you can always copy them and then change how they return values. The return of map(d) can be an object. You just need to include a plots object in your indicator’s module.exports object that maps 1-to-1 with the names of the values on the map(d) return object. So for example:

    map(d) {
        let retval = {
            current: d.value(),
            previous: this.previous || 0
        this.previous = d.value()
        return retval

//and in exports
module.exports = {
    plots: {
        current: predef.styles.solidLine('#8cecff'), //default colors of plotted values
        previous: predef.styles.solidLine('#ffce8c')

If you did that, you could still use worksheets to composite them, you just need to use the values instead of the raw indicator function. So here would be an example worksheet expression:

expr #1:
myInd(myParams).previous < myInd2(myParams2).previous
mode: coloring
color: gray

expr #2
myInd(myParams).current > myInd2(myParams2).current
mode: coloring
color: gray

When using MA lines, these two in combination will create a logical exclusion between two lines to find positive crossovers (which could indicate uptrend). It will highlight a rare bar as its natural color and gray out the rest, so you can easily see the crossover bar. You can reverse the GT and LT on current and previous values to find negative crossovers (although I must say, this logic seems better at detecting long positions). I tested this with a custom SMA that tracks current and prev values instead of just current value.

So I’m trying to do what you described above. As a test I opened “Code Explorer” went to “Bulitin” and copied the wma.js. I then did file new and created KS_WMA and copied the default info and made the suggested changes.

I’ve been looking around the indicators and tried adding it in the worksheet but I don’t see it anywhere. Where would I find it?

change the imports at the top like this: const predef = require('./tools/predef');

Just need to drop the first . in the ../.

Then it will show up either at the top level of the indicators dropdown, or under the folder specified under tags in the module.exports object.

okay thanks…I’m going to test tonight