Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

Using JavaScript to Build Trading Indicators in Algocdk

Algocdk v2 indicators use a plain JavaScript object, oldest-to-newest candle data, and one aligned result per candle. Learn when to use its default line renderer, custom Canvas 2D drawing, and documented backtesting workflow.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Algocdk v2 lets you write a custom indicator as a plain JavaScript object: the platform supplies candle data, your calculate(data, params) function returns one value per candle, and the built-in renderer draws those values as a line unless you provide a custom draw() function. That makes a simple indicator relatively direct to prototype, while more specialized visuals can use Canvas 2D and a separate chart pane.

How an Algocdk indicator file is structured

The Algocdk v2 Developer Docs describe each indicator file as a JavaScript object literal wrapped in ({}). In their words: “Every file is a plain JS object literal wrapped in ({}). No imports, no export default, no build step needed.” The required object fields are a display name and a calculate function. Optional fields include color, lineWidth, hasWindow2, defaultParams, and draw. The platform combines parameter defaults with any user overrides when it calls the indicator. See the Algocdk v2 Developer Docs.

A minimal conceptual shape is:

({
  name: "Example",
  color: "#4f7cff",
  lineWidth: 2,
  defaultParams: { period: 14 },
  calculate(data, params) {
    // Return one value for every candle in data.
  }
})

This is a structural sketch, not a complete trading rule: the calculation must return an output array aligned with the supplied candles.

What candle data the platform supplies

The input is an array ordered from oldest candle to newest; the last element is the current candle. Each documented candle includes open, high, low, close, time, and volume. Build calculations around that ordering rather than assuming the newest candle is at index zero.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There is an important instrument-specific limitation: Algocdk’s guide says volume is always zero on Deriv synthetic indices. For those instruments, a volume-based calculation will not have informative volume values to work with.

Return one result per candle

calculate(data, params) is called as new candle data arrives. Its returned array should have the same length as data, so each result lines up with its corresponding candle. When a calculation needs more history before it can produce a meaningful value, return null for those warm-up positions instead of shifting the remaining outputs.

For example, a period-based measure may not be defined until enough candles have accumulated. Keeping those early entries as null preserves the index relationship between the indicator and the chart.

Choose the default line or custom drawing

Use the default line for a straightforward series

If a line is all you need, omit draw() and configure color and lineWidth. The guide states: “If you skip draw(), the platform automatically draws your returned array as a line using color and lineWidth.” This is the simplest choice for a value series intended to follow the main chart.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Canvas 2D for specialized visuals

Implement optional draw() when the display needs custom shapes, bars, an oscillator treatment, or a different layout. The documented drawing function receives a Canvas 2D context, calculated values, chart offsets and spacing, a price-to-y coordinate function, and parameters. That lets the renderer map values into the chart’s geometry rather than relying on the platform’s standard line.

Put an indicator in its own pane

Set hasWindow2: true when the indicator should be shown in a separate pane instead of sharing the main price chart. The guide’s custom-drawing example writes window.window2Bounds = { y, height } at the end of drawing. This layout can suit an oscillator or other series whose scale should be visually distinct from price.

Choice Use it when What it means
Default line A normal line represents the calculated values Omit draw(); set color and lineWidth.
Custom draw on the main chart You need non-line marks or chart-specific styling Implement Canvas 2D drawing and use the chart geometry supplied to the function.
Custom draw in a second pane The indicator should have a separate visual area or scale Set hasWindow2: true; the documented example sets window.window2Bounds.

What the documented RSI example does

The official RSI example calculates close-to-close changes, separates gains and losses, seeds average gains and losses, and then smooths those averages period by period. Its early results remain null until the calculation has enough history. This describes the algorithm shown in the example; inclusion in the guide is not independent validation of its mathematical correctness or trading usefulness.

The same implementation pattern applies more broadly: identify the candle fields needed, decide how much history is required, maintain the data-to-output alignment, and choose a renderer suited to the indicator’s meaning.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to upload an indicator and evaluate a bot

Algocdk’s guide documents uploading custom indicator files through the chart’s Indicators management route. It also describes loading bots in Strategy Lab, replaying them against historical data, loading them into Digit Lab, and publishing through the bot store. Those are platform workflows, not evidence that a strategy will earn a return.

  1. Write the indicator object. Include its display name and calculation function, plus optional defaults and rendering fields required by your design.
  2. Upload it from the chart. Use the chart’s Indicators management route to load the custom JavaScript indicator, as described in the Algocdk v2 Developer Docs.
  3. Keep indicator and bot roles distinct. An indicator calculates and displays values. A bot adds signal behavior; the guide’s getSignalAt() examples can return a signal or null, and its bot examples show platform-driven trade execution.
  4. Replay a bot before considering live use. Load it in Strategy Lab and use historical replay/backtesting to inspect its behavior. A backtest is an evaluation step, not a guarantee of future or live results.

When this authoring model may fit

  • Good fit: you are comfortable with JavaScript and want a direct way to calculate chart values without a separate build step.
  • Good fit: your indicator is a simple line, or you are prepared to write Canvas 2D code for a more specific visualization.
  • Plan carefully: your formula depends on volume and you are using Deriv synthetic indices, where the guide says volume is always zero.
  • Keep expectations grounded: the platform documentation explains code structure and workflow; it does not provide measured indicator accuracy, expected returns, or proof of live performance.

If you need a refresher before writing the file, JavaScript fundamentals are useful preparation, but a programming book or other learning resource is optional rather than an Algocdk requirement.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.