Please help. Indicator not working

let lastLow = null;
let lastHigh = null;

function onData(data) {
if (!lastLow) {
lastLow = data.low;
lastHigh = data.high;
return;
}

if (data.low > lastLow) {
chart.setBackgroundColor(“green”);
} else if (data.high < lastHigh) {
chart.setBackgroundColor(“red”);
}

lastLow = data.low;
lastHigh = data.high;
}

Hi, try this code script: Your JavaScript script seems mostly correct, but there are some syntax errors and a small logic issue. Here’s the corrected version:

let lastLow = null;
let lastHigh = null;

function onData(data) {
    if (!lastLow) {
        lastLow = data.low;
        lastHigh = data.high;
        return;
    }

    if (data.low > lastLow) {
        chart.applyOptions({ layout: { backgroundColor: 'green' } });
    } else if (data.high < lastHigh) {
        chart.applyOptions({ layout: { backgroundColor: 'red' } });
    }

    lastLow = data.low;
    lastHigh = data.high;
}

Changes made:

  1. Replaced curly quotes (“ ”) with straight quotes (" ") to ensure proper syntax.
  2. Used chart.applyOptions() to change the chart background color. The setBackgroundColor method might not be directly available; instead, you can use applyOptions to update chart options.

Make sure the chart variable is properly defined and accessible in your environment. This script assumes that there’s a chart object with an applyOptions method.

let lastLow = null;
let lastHigh = null;

function onData(data) {
if (!lastLow) {
lastLow = data.low;
lastHigh = data.high;
return;
}

if (data.low > lastLow) {
    chart.applyOptions({ layout: { backgroundColor: 'green' } });
} else if (data.high < lastHigh) {
    chart.applyOptions({ layout: { backgroundColor: 'red' } });
}

lastLow = data.low;
lastHigh = data.high;

}