Code Your Own Indicator and See It on the Replay Chart.
Write a short JavaScript script in the chart’s built-in editor and it becomes a normal indicator: lines on the candles or in a pane, plus buy and sell arrows where your rules fire. It follows the replay, so it never sees a candle you have not revealed yet.
All features · Build your first manual backtest
What a custom script does
Open the Indicators menu on the replay chart and choose New script. What you write is added to the chart like any built-in indicator. It appears in the legend, where you can hide, reorder or remove it, and the inputs you declare get their own settings dialog.
Scripts work with the replay, the timeframes and scrolling. As you reveal candles, the lines and arrows update.
A complete example
This is the EMA crossover script that ships in the editor. It plots two moving averages and marks a buy when the fast one crosses above the slow one, and a sell when it crosses below. It is a practice example of the syntax, not a recommended trading strategy.
// EMA crossover: buy when the fast average crosses above the slow one, sell when it crosses below.
indicator({ name: "EMA cross", overlay: true });
const fastLen = input("Fast length", 9, { min: 1, max: 200 });
const slowLen = input("Slow length", 21, { min: 2, max: 400 });
const fast = ta.ema(close, fastLen);
const slow = ta.ema(close, slowLen);
plot("Fast EMA", fast, { color: "#4f8cff" });
plot("Slow EMA", slow, { color: "#f5a524" });
signal("buy", ta.crossover(fast, slow));
signal("sell", ta.crossunder(fast, slow));What you can use in a script
- Candle data as arrays with one value per candle, oldest first: time, open, high, low, close and volume.
- indicator() to name the script and choose whether it draws on the price chart or in its own pane.
- input() and input.source() to add settings, such as a length or a price source, that you can change without editing the code.
- plot() to draw a line, and signal() to mark a buy or a sell on a candle, with optional text.
- console.log() to print values while you are testing.
- ta.sma, ta.ema, ta.rma, ta.stdev, ta.highest, ta.lowest, ta.sum, ta.shift, ta.change, ta.rsi, ta.atr, ta.tr, ta.macd, ta.bb, ta.crossover and ta.crossunder. These return the same numbers as the matching built-in indicators.
- Ordinary loops and variables, for logic that remembers what happened on earlier candles.
Five starter scripts in the editor
Pick one as a starting point and change it. All of them are practice examples.
| Starter script | What it does |
|---|---|
| EMA crossover | Two moving averages; buy when the fast one crosses above, sell when it crosses below. |
| RSI reversal | RSI in its own pane; signals when it leaves the oversold or overbought zone. |
| Channel breakout | Buy a close above the highest high of the last N candles, sell a close below the lowest low. |
| Candle-by-candle logic | A for loop with state: stay long while the close is above a moving average. |
| Blank | A minimal script to start from. |
Run, save and add to the chart
- Run (Ctrl or Cmd + Enter) checks the script against the candles on your chart. It shows errors with the line number, the lines and inputs it found, the number of signals and anything you printed with console.log.
- Save keeps the script. Save and add to chart also puts it on the chart.
- Saving again updates every copy of that script already on the chart. Colours you changed by hand are kept.
Signals mark candles. They do not place trades
A buy signal draws an arrow under the candle and a sell signal draws one above it. That is all a signal does. It does not open a simulated position, close one or calculate results.
You still decide when to place a simulated order, set a stop loss and take profit, and journal the trade yourself. Custom scripts help you see your rules on the chart. They are not automated trading and not an automated backtest.
How scripts run safely
- Your code runs in a Web Worker, away from the page. It has no access to the page, cookies or local storage.
- The worker is blocked from making network requests, so a script cannot send data anywhere.
- A run that takes longer than 2.5 seconds is stopped and the chart stays responsive. A script that timed out is not run again until you change its code or inputs.
- As with any code, read a script before you run it if someone else wrote it.
Limits
A script receives the visible candles plus up to 3,000 candles before them, never beyond the replay point. Logic that depends on where it starts, such as whether you are already long, starts at the first candle the script is given.
| Limit | Value |
|---|---|
| Script length | 40,000 characters |
| Saved scripts | 20 per browser |
| Inputs per script | 12 |
| Plotted lines per script | 8 |
| Signals per script | 3,000 |
| Run time | 2.5 seconds |
Plans, and where your scripts are saved
Custom scripts are included on every plan, including free Basic, and run on ReplayBureau’s built-in chart. Plan limits on sessions, history and instruments still apply to the replay itself.
Scripts are saved in your browser together with your other chart settings. They are not stored in your account, so they do not follow you to another browser or device, and clearing your site data removes them. Keep a copy of any script you want to keep.
Limitations
Signals from a script are drawn on historical data and are hypothetical. They are not trading advice, and a script that looks good on past candles may not perform the same way in live markets.
ReplayBureau is a simulation and analysis tool, not a broker. Simulated balances, profits and losses are not real money, and backtesting or paper-trading results do not guarantee future performance.
More about ReplayBureau
- Gold backtestingBuild a focused XAUUSD replay exercise.
- Forex backtestingTest one pair and one setup at a time.
- ES futures replayHistorical futures practice with simulated orders.
- Learning libraryGuides for a repeatable testing process.
- FeaturesReplay, simulated trading, journal, statistics and more, in one list.
- How it worksFrom creating a session to reviewing your results, step by step.
- BacktestingCandle-by-candle historical replay with simulated orders.
- Paper tradingPractise on live market prices with a simulated account.
- Trading journalAuto-filled trade facts plus your own notes and tags.
- Prop firm challenge practiceProfit target, drawdown, consistency and trading-day rules.
- Markets and dataInstruments, history windows and timeframes by plan.
- FAQAnswers about plans, data, accounts and limitations.
- PricingBasic, Essential and Plus plans compared.
- AboutWhat ReplayBureau is, and what it is not.