How to write a custom indicator — the formula language and strategies in Trading

In Trading you can write your own indicator — a few lines of formulas, no programming needed. Trading strategies are written in the same language: the tester checks them on the symbol’s history and shows the trades and a report.

Open the editor Ready-made examples

Two script languages

  • Pine Script — compatible with TradingView: paste your ready-made TradingView script into the editor as is — the editor recognizes it by the //@version=… line. How to bring over a Pine Script script →
  • The Trading formula language — simpler, for those writing a script for the first time: a few lines of formulas, no programming. The rest of this page is about it.

Where to open the editor

Open Trading and press the “ƒx” button — “My indicators” — in the chart’s top bar; on a narrow screen it may sit in the “More” menu. The other way is the “Indicators” dialog: the “My indicators” group comes first there, and the “Write your own indicator…” line opens the editor.

On the left of the window are “New indicator”, your saved scripts and the examples; on the right — the name, the formula field, the error line and the parameter fields. The “?” button opens a cheat sheet: series, operators and every function; clicking a name inserts it into the text.

The editor is free and works without signing in: scripts are kept in your browser. Once you sign in, they open on any device — along with your tabs and drawings.

Your first indicator in a minute

  1. Open the editor — the button below opens it straight away with a template for a new indicator.
  2. The field already holds a template — the average of closing prices over 20 candles, drawn over the chart:
    overlay(true)
    len = input(20, "Length", 1, 500)
    plot(sma(close, len), "SMA", "orange")
  3. Press “Apply to chart” — an orange line appears on the chart.
  4. A “Length” field has appeared under the text: put 50 instead of 20 — the line is recalculated without editing the text.
  5. Add a second line — plot(sma(close, 100), "SMA 100", "purple") — and press “Apply to chart” again. The editor checks the text as you type: if a line has an error, it is highlighted, and the message under the field says what is wrong.
    overlay(true)
    len = input(20, "Length", 1, 500)
    plot(sma(close, len), "SMA", "orange")
    plot(sma(close, 100), "SMA 100", "purple")
  6. Type a name and press “Save”: the indicator appears in the “My indicators” list and in the “Indicators” dialog — you can put it on any chart.

Open the editor with a template

How a script works

A script is made of two kinds of lines: name = formula gives a name to a value, and a function call such as plot(…) draws or sets something. A formula is calculated over all the candles of the chart at once: it is a series — one number per candle.

// candle body and its average size over 20 candles
body = close - open
size = sma(abs(body), 20)
big = abs(body) > 2 * size   // a candle twice the usual size
hist(body, "Body", color = body > 0 ? "green" : "red")
marker(big, "up", "Big")

Candle series

openOpen price of the candle
highHigh of the candle
lowLow of the candle
closeClose price of the candle
volumeVolume; na if the symbol has no volume
hl2Middle of the candle: (high + low) / 2
hlc3Typical price: (high + low + close) / 3
ohlc4Average of the candle’s four prices
timeCandle time in milliseconds since 1970 (UTC)
indexNumber of the candle in order, from zero
trTrue range: the largest of high - low and the distances from the previous close to the high and the low

Past values

close[1] is the close of the previous candle, close[5] — five candles back. You can take the past of any formula the same way: sma(close, 20)[1]. On the first candles, where there is no past yet, there is no value — na.

Operators and conditions

Arithmetic — + - * / % and ^ (power). Comparisons — == != < <= > >=. Conditions are joined with the words and, or, not. Choice — condition ? a : b: a on the candles where the condition is true, b on the others. Any number except 0 and na counts as true.

na means “no value”: the first candles of an average, a division by zero. It carries through arithmetic, and a comparison with it is false. Test for it with na(x), replace it with nz(x).

// starts a comment that runs to the end of the line. A long formula can continue on the next line: inside brackets, after an operator at the end of a line or before an operator at the start of the next one. Names are Latin letters, digits and _, up to 40 characters; titles in quotes can be in any language.

Parameters: input()

input() turns a number into a field under the script: you can change it without touching the text — like the length of an average in built-in indicators. Each chart keeps its own values.

len = input(20, "Length", 2, 500)
mult = input(2.0, "Deviation", min = 0.5, max = 10, step = 0.5)
basis = sma(close, len)
plot(basis + mult * stdev(close, len))
plot(basis - mult * stdev(close, len))

The order in the brackets: default value, title, minimum, maximum, step. A whole default (20) makes a whole-number parameter, a fractional one (2.0) — a fractional parameter. The numbers are written right in the brackets; a value outside the bounds moves to the nearest one. A script can have up to 16 parameters.

What you can draw

plot(series, "title", "color", width, style) — a line; hist(series, "title", "color") — columns from zero; hline(70, "title", "color") — a level; marker(condition, "up", "title", "color") — an arrow under the candle ("down" — above it) wherever the condition is true.

title("Momentum")
m = close - close[10]
hist(m, "Momentum", color = m > 0 ? "green" : "red")
plot(sma(m, 5), "Average", "orange")
hline(0)

By default a script is drawn in its own pane under the chart — like RSI. overlay(true) anywhere in the text puts it over the price — like moving averages. title("…") is the name in the legend.

A color is "#rrggbb" or a name: red, green, blue, orange, yellow, purple, pink, teal, aqua, lime, gray, white, black. The color of lines and columns can depend on the candle: color = close > open ? "green" : "red". Without a color the chart picks one itself.

Function reference

x, a, b are a series or a number; length is the window length in candles, a single number. An argument marked ? can be left out. Arguments can be given by name: ema(close, length = 20).

Moving averages

sma(x, length)Simple average of the last length values
ema(x, length)Exponential average: recent values weigh more than old ones
rma(x, length)Wilder’s smoothing — the way RSI and ATR are calculated
wma(x, length)Weighted average: the more recent the value, the bigger its weight
hma(x, length)Hull average: lags less than a regular one and stays smooth
dema(x, length)Double exponential average: 2 × ema − ema(ema)
tema(x, length)Triple exponential average — lags even less
linreg(x, length)End point of the regression line over the last length values

Windows and history

stdev(x, length)Standard deviation of the last length values
highest(x, length)Largest of the last length values
lowest(x, length)Smallest of the last length values
sum(x, length)Sum of the last length values
change(x, length?)Change over length candles: x - x[length]; without length — over one candle
roc(x, length?)Change over length candles in percent
cum(x)Running total from the first candle

Ready-made indicators

rsi(x, length)Relative Strength Index (RSI), from 0 to 100
tr()True range of the candle — same as the tr series
atr(length)Average true range (ATR) over length candles

Conditions and signals

cross(a, b)1 on the candle where a crossed b in either direction
crossover(a, b)1 on the candle where a rose above b
crossunder(a, b)1 on the candle where a fell below b
barssince(condition)Candles since the last candle where the condition was true
valuewhen(condition, x, nth?)The value of x on the candle where the condition was last true; nth = 1 — the time before
na(x)1 where there is no value
nz(x, replacement?)The value of x, and replacement where there is none (0 by default)

Math

abs(x)Absolute value
sign(x)Sign of the number: −1, 0 or 1
sqrt(x)Square root
exp(x)Exponent
log(x)Natural logarithm
log10(x)Decimal logarithm
floor(x)Round down
ceil(x)Round up
round(x, digits?)Rounding; digits — how many decimals to keep
pow(x, power)x to the power of power
min(a, b, …)Smallest of 2–10 values on every candle
max(a, b, …)Largest of 2–10 values on every candle
avg(a, b, …)Average of 2–10 values on every candle

Other symbols and intervals

other(x, symbol?, interval?)The formula x over the candles of another symbol or another interval; on every candle of the chart — the value of the last finished candle of that series

Script settings

input(default, title?, min?, max?, step?)A parameter: a field under the script — default value, title, bounds and step
overlay(on)overlay(true) — draw over the price; without it the script gets its own pane
title(text)Name of the indicator in the chart legend

What to draw

plot(series, title?, color?, width?, style?, join?)A line: title, color, width from 1 to 8, style "solid", "dashed" or "dotted"; join = true — no breaks on candles without a value
hist(series, title?, color?)Columns from zero
hline(value, title?, color?, width?, style?)A horizontal level at a single number
marker(condition, shape?, title?, color?, position?)A mark on the candles where the condition is true: "up" — an arrow under the candle, "down" — above it; also "circle", "square", "diamond", "cross", "xcross", "flag"
label(when, text, value?, y?, position?, shape?, color?, textcolor?, size?, digits?)A label on the candles where the condition is true: above the candle, under it or at the value y; {} in the text is the value, {+} — the value with its sign
fill(a, b, color?, opacity?, when?)An area between two lines: without a color — the up color where the first is above and the down color where it is below; when — only on some candles
background(when, color?, opacity?)The background of the candle through the whole pane where the condition is true
barcolor(color, when?)The color of the candles themselves; only in a script over the price — overlay(true)
table(value, title?, color?, digits?)A row “title — value of the last candle” in a table in the top right corner
alert(when, text?, value?)A signal for an alert: on the candles where the condition is true; a text where {value} becomes a number. Draws nothing — the alert is set with the bell in the legend

Strategy and orders

strategy(capital?, size?, sizing?, commission?, slippage?, lot?)Makes the script a strategy: capital, order size, commission, slippage, lot
long(when, size?, limit?, stop?)Buy: open a long position or reverse a short one
short(when, size?, limit?, stop?)Sell: open a short position or reverse a long one
exit(when?, stop?, target?, loss?, profit?, trail?)Close the position: at the market, by a stop or a target — as a price or in percent, by a trailing stop

Full language reference for developers — on GitHub

Strategies and backtesting

A strategy is the same kind of script with a strategy() line and at least one order: long() — buy, short() — sell short, exit() — close the position. Press “Apply to chart” — the “Strategy tester” opens under the chart: the trades appear on the chart, and the report shows the profit, the drawdown and a comparison with “bought and held”.

strategy(capital = 10000, size = 100, commission = 0.1)
title("MA cross strategy")
fast = ema(close, input(9, "Fast", 1, 500))
slow = ema(close, input(21, "Slow", 1, 500))
plot(fast, "Fast", "green")
plot(slow, "Slow", "red", 2)
long(crossover(fast, slow))
exit(crossunder(fast, slow))
exit(loss = input(5.0, "Stop, %", 0.5, 50))

Open in the editor

Test settings: strategy()

capitalStarting capital, 10,000 by default
sizeSize of one order; by default — all the capital
sizingWhat size means: "percent" — percent of the capital (the default), "cash" — an amount of money, "units" — a number of shares, contracts or coins
commissionCommission as a percentage of the value of every trade — on entry and on exit
slippageSlippage as a percentage of the price for market and stop orders
lotQuantity step: an order is rounded down to a whole number of lots

Everything except sizing can be a parameter: strategy(capital = input(10000), commission = input(0.1)). There is no leverage: an order is cut down to what the capital can buy. One position at a time: an order in the direction of the open position does not add to it.

Orders: long(), short(), exit()

long(condition) — buy at the open of the next candle; long(condition, limit = price) — a limit order, long(condition, stop = price) — a stop order on a breakout. short() does the same for selling. An opposite order reverses the position.

exit(condition) — close the position at the market; exit(stop = price) and exit(target = price) — a stop and a target as prices; exit(loss = 5) and exit(profit = 10) — a stop and a target in percent of the entry price; exit(trail = 3) — a trailing stop 3% from the best price since the entry. Several exit() calls work together.

An order lives for one candle — the next one. While the condition is true it is placed again on every candle: long(true, stop = highest(high, 20)) keeps a breakout order at the top of the channel, while long(crossover(fast, slow)) buys once — after the candle of the crossing.

Position state

position_sizePosition size: above zero — long, below zero — short, 0 — no position
position_priceEntry price of the position; na if there is no position
position_barsCandles since the entry; na if there is no position
open_profitProfit of the open position before the exit commission
equityEquity: the starting capital plus the profit of closed trades plus open_profit

These series exist only in a strategy. In an order you can compare them, add them up and take [n], while history functions over them (sma, highest, crossover…) are for drawing only.

How to read the report

  • Net profit — profit of the closed trades after all commissions — in money and as a percentage of the starting capital.
  • Trades, Winning trades — how many trades were closed and what share of them made a profit.
  • Profit factor — total profits divided by total losses: above 1 means the strategy earned more than it lost.
  • Max drawdown — the deepest fall of the equity from its peak — how much the strategy lost in a row before reaching a new high.
  • Average trade, Best / worst trade — the average result of a trade, the best and the worst one.
  • Bought and held — what buying the symbol with all the capital at the start and holding it to the end would have made, with the same commissions. If the strategy is clearly worse, holding would have been simpler.
  • Open position — a position that is still open: it is not part of the net profit and is valued at the last close.

The “Equity” view is the equity curve with the drawdown below it, “Trades” is the list of trades: clicking a row takes the chart to the trade. The gear in the panel header changes the strategy’s parameters, and the test is recalculated at once.

How orders are filled

  1. No looking ahead: a script sees a candle only once it has closed, so an order is filled on the next candle at the earliest. An order placed on the last candle is never filled.
  2. A market order is filled at the open of the next candle.
  3. Stops and limits are filled at their own price when it is within the candle. If the candle opens beyond the price (a gap), they are filled at the open: a stop gets a worse price, a limit a better one.
  4. Inside a candle the price is assumed to go from the open to one extreme, then to the other and to the close. With a position open, the extreme that is worse for it comes first — so if both the stop and the target are within one candle, the stop is counted.
  5. Slippage worsens the price of market and stop fills; commission is charged on the value of every fill.
  6. One position at a time, no leverage. A position closed on a candle is not reopened by the same signal on the same candle.
  7. A position still open after the last candle is not a trade yet: it is shown separately.
  8. If a short position eats up all the capital, it is closed and no more orders are placed.
  9. The test runs over the whole history of the symbol on this interval — up to the latest 20,000 candles; in replay mode — only over the candles shown.

A test on history does not promise the same result in the future: real orders are filled at other prices and at other moments. This is not investment advice.

Common errors

Errors show up as you type: the line with an error is highlighted, and the message under the field says where it is and what is wrong; clicking the error puts the cursor on the spot. While the text has an error, the “Apply to chart” button does not work, but you can still save a draft.

plot(clsoe)

Line 1, column 6 — Unknown name "clsoe"

A typo in the name, or the name is used before it was given a value. Candle series are written in lowercase Latin letters: close, not Close.

plot(emaa(close, 9))

Line 1, column 6 — Unknown function "emaa"

There is no such function. Check the reference above: every function is listed there.

up = close > open && volume > 0
marker(up)

Line 1, column 19 — Use the words "and", "or", "not" instead of "&&"

Conditions are joined with the words and, or and not, not with symbols.

same = close = open
marker(same)

Line 1, column 14 — Use "==" to compare: "=" only gives a name to a value

A single = gives a name to a value; a comparison is written with two: close == open.

plot(sma(close, 20)

Line 1, column 20 — Missing ")"

A closing bracket or quote is missing. Count the brackets in the line with the error.

close - open
plot(close)

Line 1, column 1 — This line does nothing: give the result a name or plot it

The line calculates a value but does nothing with it: give it a name (body = close - open) or draw it.

fast = ema(close, 9)

Line 1, column 1 — The script draws nothing: add plot(), hist(), hline() or marker()

The script draws nothing: add plot(), hist(), hline() or marker().

plot(sma(close, volume))

Line 1, column 17 — sma(): "length" must be a single number, not a series

A window length is a single number for the whole chart, not a series: sma(close, 20) or sma(close, input(20)).

long(close > open)
plot(close)

Line 1, column 1 — "long" works only in a strategy: add strategy() to the script

Orders work only in a strategy: add a strategy() line at the top.

Sometimes the text is correct, but the script shows “error” in the chart legend — it cannot be calculated on these candles. Most often the script is too heavy for this number of candles or a parameter sets too long a window: shorten the window or simplify the formulas.

Ready-made examples

The same examples are in the editor, in the “Examples” list. Open any of them, adjust it to your needs and save it as your own.

MACD with a histogram

The difference of two averages, a signal line and columns that change color as momentum grows or fades.

title("MACD")
macd = ema(close, input(12, "Fast")) - ema(close, input(26, "Slow"))
signal = ema(macd, input(9, "Signal"))
delta = macd - signal
plot(macd, "MACD", "blue")
plot(signal, "Signal", "orange")
hist(delta, "Histogram", color = delta >= 0 ? (delta > delta[1] ? "green" : "lime") : (delta < delta[1] ? "red" : "pink"))
hline(0)

Open in the editor

Bollinger Bands

An average and two bands two standard deviations away — over the price.

overlay(true)
title("Bollinger Bands")
len = input(20, "Length", 2, 500)
mult = input(2.0, "Deviation", 0.5, 10)
basis = sma(close, len)
dev = mult * stdev(close, len)
plot(basis, "Basis", "orange")
plot(basis + dev, "Upper", "blue")
plot(basis - dev, "Lower", "blue")

Open in the editor

Moving average cross with marks

A fast and a slow average and arrows where they crossed.

overlay(true)
title("MA cross")
fast = ema(close, input(9, "Fast", 1, 500))
slow = ema(close, input(21, "Slow", 1, 500))
plot(fast, "Fast", "green")
plot(slow, "Slow", "red", 2)
marker(crossover(fast, slow), "up", "Buy", "green")
marker(crossunder(fast, slow), "down", "Sell", "red")

Open in the editor

RSI with levels

RSI with overbought and oversold levels; the line changes color beyond the levels.

title("RSI")
len = input(14, "Length", 2, 200)
top = input(70, "Overbought", 50, 100)
bottom = input(30, "Oversold", 0, 50)
r = rsi(close, len)
plot(r, "RSI", color = r > top ? "red" : r < bottom ? "green" : "purple")
hline(top, "Overbought", "gray")
hline(bottom, "Oversold", "gray")
hline(50, style = "dotted")

Open in the editor

Moving average cross with alerts

A fast and a slow average and two alert() signals with a text — crossing up and down: an alert is set on them.

overlay(true)
title("MA cross alerts")
fast = ema(close, input(9, "Fast", 1, 500))
slow = ema(close, input(21, "Slow", 1, 500))
plot(fast, "Fast", "green")
plot(slow, "Slow", "red", 2)
alert(crossover(fast, slow), "Fast EMA crossed above the slow one at {value}")
alert(crossunder(fast, slow), "Fast EMA crossed below the slow one at {value}")

Open in the editor

Volume spikes on a price channel

A price channel over the past candles and marks where the price broke out of it on volume twice the average.

overlay(true)
len = input(20, "Channel", 2, 500)
upper = highest(high, len)[1]
lower = lowest(low, len)[1]
busy = volume > 2 * sma(volume, len)
plot(upper, "Upper", "teal")
plot(lower, "Lower", "teal")
marker(close > upper and busy, "up", "Breakout")
marker(close < lower and busy, "down", "Breakdown")

Open in the editor

Labels: RSI overbought and oversold

“RSI 72” labels above the candle where RSI rose above 70 and under the candle where it fell below 30, and a table with the RSI of the last candle — over the price.

overlay(true)
title("RSI labels")
len = input(14, "Length", 2, 200)
top = input(70, "Overbought", 50, 100)
bottom = input(30, "Oversold", 0, 50)
r = rsi(close, len)
label(crossover(r, top), "RSI {}", r, color = "red", digits = 0)
label(crossunder(r, bottom), "RSI {}", r, position = "below", color = "green", digits = 0)
table(r, "RSI", color = r > top ? "red" : r < bottom ? "green" : "gray", digits = 1)

Open in the editor

Cloud between moving averages

Two moving averages and a cloud between them: green while the fast one is above the slow one, red while it is below.

overlay(true)
title("MA cloud")
fast = ema(close, input(20, "Fast", 1, 500))
slow = ema(close, input(50, "Slow", 1, 500))
plot(fast, "Fast", "green")
plot(slow, "Slow", "red")
fill(fast, slow, color = fast > slow ? "green" : "red", opacity = 20)

Open in the editor

Trend background and big moves

Candle background by the trend — green above the average, red below it — and labels like “+3.4%” at candles with a big daily move.

overlay(true)
title("Trend background")
trend = sma(close, input(50, "Trend", 2, 500))
big = input(3.0, "Big move, %", 0.5, 50)
move = roc(close, 1)
plot(trend, "Trend", "gray")
background(close > trend, "green", 8)
background(close < trend, "red", 8)
label(move >= big, "{+}%", move, color = "green", digits = 1, shape = "box")
label(move <= -big, "{+}%", move, position = "below", color = "red", digits = 1, shape = "box")

Open in the editor

Relative strength to an index

How far the symbol is ahead of the index over the last candles, in percent. In the editor SPY becomes the main index of your market.

title("Relative strength")
len = input(20, "Candles", 1, 500)
market = other(close, "SPY")
mine = roc(close, len)
theirs = roc(market, len)
hist(mine - theirs, "Ahead of the index, %", color = mine > theirs ? "green" : "red")
hline(0)

Open in the editor

Daily levels on an intraday chart

The daily average and the high and the low of the last finished day — on an hourly or any other intraday chart.

overlay(true)
title("Daily levels")
len = input(20, "Days", 1, 500)
plot(other(sma(close, len), interval = "1d"), "Daily average", "orange", 2)
plot(other(high, interval = "1d"), "High of the last day", "green", style = "dashed")
plot(other(low, interval = "1d"), "Low of the last day", "red", style = "dashed")

Open in the editor

Strategy: moving average cross

Buys when the averages cross upwards, exits on the opposite cross or at a stop in percent.

strategy(capital = 10000, size = 100, commission = 0.1)
title("MA cross strategy")
fast = ema(close, input(9, "Fast", 1, 500))
slow = ema(close, input(21, "Slow", 1, 500))
plot(fast, "Fast", "green")
plot(slow, "Slow", "red", 2)
long(crossover(fast, slow))
exit(crossunder(fast, slow))
exit(loss = input(5.0, "Stop, %", 0.5, 50))

Open in the editor

Strategy: channel breakout

Buys on a breakout of the channel high with a stop order, exits on a break of the low of a shorter channel.

strategy(capital = 10000, size = 100, commission = 0.1)
title("Channel breakout")
entry = input(20, "Entry channel", 2, 500)
out = input(10, "Exit channel", 2, 500)
upper = highest(high, entry)
lower = lowest(low, out)
plot(upper, "Upper", "teal")
plot(lower, "Lower", "orange")
long(true, stop = upper)
exit(stop = lower)

Open in the editor

Strategy: RSI reversal

Buys when RSI comes back from the oversold zone, exits from the overbought zone or at a stop.

overlay(false)
strategy(capital = 10000, size = 100, commission = 0.1)
title("RSI reversal")
len = input(14, "Length", 2, 200)
bottom = input(30, "Buy above", 1, 50)
top = input(70, "Sell below", 50, 99)
r = rsi(close, len)
plot(r, "RSI", "purple")
hline(bottom, "Buy", "green")
hline(top, "Sell", "red")
long(crossover(r, bottom))
exit(crossunder(r, top))
exit(loss = input(8.0, "Stop, %", 0.5, 50))

Open in the editor

Limits

Saved scripts50
Characters in one script20,000
Bytes for all scripts together120,000
Your own indicators on one chart10
All indicators on one chart40
input() parameters per script16
Lines and columns: plot() and hist()32
hline() levels32
marker() sets16
label() sets16
Characters in the text of a label40
Areas, backgrounds and candle colors: fill(), background() and barcolor()16
table() rows12
long(), short() and exit() orders16
Names in a script200
Candles in one calculation100,000
Candles in one strategy test20,000
Trades in one test20,000

A script that goes over a limit gets an error instead of hanging the page. With the “Share” link, the texts of the scripts on the chart go along with it — up to 120,000 bytes for all of them.

FAQ

Do I need to know programming to write my own indicator?

No. An indicator is written as formulas, like in a spreadsheet: “the average over 20 candles”, “the close above the average”. Start with a ready-made example and change the numbers and colors — the editor shows at once if something is wrong.

Are custom indicators and strategies free?

Yes, everything is free and needs no sign-up: scripts are kept in your browser. Signing in is only needed to open them on other devices.

Can I share my indicator?

Yes. The “Share” button gives a link to the chart, and the texts of the scripts on it go along. The recipient sees the indicator and can save it for themselves.

Can I paste a script from TradingView?

Yes. The editor understands Pine Script: paste a ready-made indicator script as is, and the editor recognizes it by the //@version= line at the top.

Can I set an alert on my own indicator?

Yes. The bell in the legend of your indicator: an alert is set on its line — it crossed a number, the price or another line, entered a range — or on an alert() signal of the script with your own text. A Pine Script script also has alertcondition() (its text takes the placeholders of the price, the ticker, the interval and the lines of the script), all of its alert() calls at once with their frequencies, and the order fills of a strategy (alert_message); the data of other symbols from request.security the server loads itself. The alert keeps a copy of the script: editing the script does not change it, and the alerts window offers “Update”. The server checks it even when the page is closed; you need to sign in.

Does a backtest promise a profit?

No. The tester shows what would have happened on past candles under honest filling rules, but markets change and real orders are filled at other prices. This is not investment advice.

Why doesn’t the script start at the first candle?

An average over 50 candles needs 50 candles of history: until then there is no value, and the line starts later. Built-in indicators behave the same way.

Open the editor Open Trading

↑ Top