Using Worksheets to Build Custom Indicators

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.