Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

78
Views
Moving Average Crossover Histogram

working on my first javascript indicator for Tradovate. So far everything seems to work great without any bugs. That said, I'd like to make two changes:

  • Histogram to plot > 0 (green) only if period1Avg is greater than the HIGH of period2Avg.
  • Histogram to plot < 0 (green) only if period1Avg is less than the LOW of period2Avg.

This would inherently mean that some sections of the histogram would not plot (i.e. value of 0).

Any assistance on how to edit the script to reflect these changes would be much appreciated!

const predef = require("./tools/predef");
const meta = require("./tools/meta");
const SMA = require("./tools/SMA");
const EMA = require("./tools/EMA");
const WMA = require("./tools/WMA");

class TEMP {
    init() {
        switch(this.props.period1type) {
          case "Simple":
              this.period1Avg = SMA(this.props.period1);
              break;
          case "Exponential":
              this.period1Avg = EMA(this.props.period1);
              break;
          case "Weighted":
              this.period1Avg = WMA(this.props.period1);
              break;        
          default:
              this.period1Avg = SMA(this.props.period1);          
        }
        switch(this.props.period2type) {
          case "Simple":
              this.period2Avg = SMA(this.props.period2);
              break;
          case "Exponential":
              this.period2Avg = EMA(this.props.period2);
              break;
          case "Weighted":
              this.period2Avg = WMA(this.props.period2);
              break;        
          default:
              this.period2Avg = SMA(this.props.period2);          
        }
    }

    map(d) {
        const value = d.value();
        const diff = this.period1Avg(value) - this.period2Avg(value);
        const plotColor = { color: diff > 0 ? "green" : "red" };
        return {
            value: diff,
            style: { value: plotColor }
        };
    }
}

module.exports = {
    name: "TEMP",
    description: "TEMP",
    calculator: TEMP,
    params: {
        period1: predef.paramSpecs.period(8),
        period1type: predef.paramSpecs.enum({value1: "Simple", value2: "Exponential", value3: "Weighted"}),
        period2: predef.paramSpecs.period(34),
        period2type: predef.paramSpecs.enum({value1: "Simple", value2: "Exponential", value3: "Weighted"})
    },
    tags: [predef.tags.MovingAverage],
    inputType: meta.InputType.BARS,
    areaChoice: meta.AreaChoice.NEW,
    plots: {
        value: { displayOnly: true }
    },
    plotter: predef.plotters.histogram
};

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!