Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

80
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda