Skip to main content
Skip to main content

Customize a built-in indicator

addScript("EMA") is great for defaults. When you need your periods, colors, or wiring — still no custom math required. You copy the built-in recipe, edit fields, and pass it back in.

What you are building

For example: MACD with faster settings (8 / 21 / 5) instead of the library defaults.

Clone, edit, add

const macd = structuredClone(chart.getScripts().MACD);

macd.inputs.FPERIOD.value = 8;
macd.inputs.SPERIOD.value = 21;
macd.inputs.SGPERIOD.value = 5;

chart.addScript("MACD", macd);

Always clone with structuredClone (or JSON.parse(JSON.stringify(...))). Objects from getScripts() are shared templates — editing them directly causes weird bugs.

See advanced wiring live

Some indicators read another indicator's output (for example “trade when EMA crosses SMA”). The showcase below demonstrates those patterns:

Preset
What it wires

Two moving-average outputs are rewired into CROSS so the strategy follows EMA/SMA intersections instead of the default MACD pair.

CROSS.LINE = "seriesId:EMA"; CROSS.SIGNAL = "seriesId:SMA"
Live MDX exampleStrategyseries -> strategy1000 candlesBTC/USD fixture
Loading chart…

Full explanations: Programmatic wiring.

Update an indicator already on the chart

chart.updateIndicator(scriptId, updatedDefinition);

Use this when the user changes a setting in your settings panel.

When built-ins are not enough

If you need a completely new formula that does not exist in the catalog, that is a maintainer task: Custom indicator authoring.

What is next?