Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

85
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda