Soon available

Not on the Chrome Web Store yet

ProRealCode Studio is on its way. As soon as it is published, this button will take you straight to its Chrome Web Store page.

Chapter 09 · Part II — Writing code

A mistake is marked on its line, and often repaired in one click.

Studio checks your code as you type. It shows where the mistake is and says what is wrong. When it knows the repair, it offers it as a button. For a value that looks wrong but raises no error, the console lets your code print what it computes.

  1. 01Read an error The line, the underline, the card.
  2. 02Fix it in one click The repairs Studio offers.
  3. 03The Problems panel Every error of every code, in one list.
  4. 04The console Print a value, bar by bar.
The editor with line 2 marked: its number in red on a pink band, a red wavy underline under “Average[30](close”, and the pointer on it, which has opened a card reading “Expected ')' (line 2, col 25)”.
A closing parenthesis is missing on line 2. The pointer rests on the underline, and the card says so.
Before you startYou can open a code in the editor and run it (chapter 02). Nothing in this chapter needs a prorealcode.com account.
ProRealCode StudioUser guide · Chapter 09
01 · Read an error

The red number says which line. The card says what is wrong.

Line 2 of the editor marked as an error: red line number, pink band, wavy underline, and the card with the message and its position. 1 2 3
The three marks of an error. The code under the card continues on lines 3 to 5.
  1. The line number, in red, on a tinted band. The line with the mistake.
  2. The wavy underline. The part of the line where Studio stopped understanding it.
  3. The card. The message, then its position: line 2, column 25. Here the line ends before the parenthesis that closes Average[30](close.
  1. Point at the underline.The card opens. It stays open while the pointer is on it, so you can reach a button inside it (sheet 3).
  2. Correct the line.The marks go away less than half a second after you stop typing.

Red or amber

RedAn error. The code cannot run as written.
AmberA warning. The code runs, but something deserves a look: a name that is never given a value, for instance, reads as 0.

When the editor checks

⚙ Preferences › Editor › “Inline error checking”.

While typingThe default. The marks follow your typing.
On ▶ Run onlyThe marks appear when you run the code, and go away as soon as you edit it.

The repair buttons work the same with either setting.

ProRealCode StudioUser guide · Chapter 09
02 · Fix it in one click

When Studio knows the repair, it is one click away.

x = Averge[20](close)
Unknown function 'Averge' — did you mean 'Average'?
Replace with 'Average'
Illustration. A misspelt name, and the card with its repair button.
  1. Point at the underline.The card shows the message and, under it, the button.
  2. Click the button.The line is corrected and checked again at once. Your capitals are kept: AVERGE becomes AVERAGE.
  3. Changed your mind? Press Ctrl + Z.A repair is undone like any other edit.

The repairs Studio offers

When the message saysThe buttonWhat it does
Unknown function 'Averge' — did you mean 'Average'?Replace with 'Average'Corrects the spelling.
'x' is never assigned — reads as 0Declare 'x' aboveAdds x = 0 above the line, the 0 selected for you to type over.
Expected 'endif'Insert missing ENDIFAdds the closing word where the block ends, lined up with the IF that opened it.
'NEXT' closes a block that was never openedRemove 'NEXT'Deletes the extra closing line.
An INCLUDE whose name has no quotesWrap the name in quotesAdds the quotes.
ProRealCode StudioUser guide · Chapter 09
03 · The Problems panel

Every error of every code, in one list.

The Problems panel on the left, with one row: “error · Code 1 · line 2” and the message “Expected ')' (line 2, col 25)” in red. On the right, the editor with the same line 2 marked in red. 1 2 3
The Problems panel beside the editor. One error, in the tab “Code 1”.
  1. “PROBLEMS”. The panel opens beside the editor.
  2. One row per problem. Error or warning, the code's name, the line. Then the message, in red for an error and amber for a warning.
  3. The same line in the editor, with the marks of sheet 2.
  1. Click the round “!” button on the rail, under the bell, or the “⚠ 1 problem” chip in the status bar.The panel opens. The red badge on the button counts the problems.
  2. Click a row.The code opens at that line, in its own tab if needed. A folded block opens to show it.

The warnings it adds

The code ran. These rows explain a chart that does not look as expected.

The row saysWhat it means
series “…” undefined on every bar (not drawn)That curve has no value on any bar, so nothing is drawn. Often a curve switched off by a setting, or a calculation that needs more bars than the chart holds.
the platform serves no order book for this instrumentThe code reads BID or ASK, which this instrument does not provide. Try it on a future or a stock.
computing for 25 s (past the 20 s mark)A long calculation. The chart keeps its last drawing until it finishes. The row stays afterwards and gives the final time.

An empty panel reads “No problems — all indicators parsed and ran cleanly.”

ProRealCode StudioUser guide · Chapter 09
04 · The console

No error, but a strange curve? Print the values.

An error stops a code. A wrong value does not: the code runs and draws the wrong curve. console() writes values into a panel under the editor, one line per bar.

A seven-line code that calls console() twice, and under it the >_ Console panel reading 1000 lines · 4994 dropped, then lines such as [2995] RSI is 46.3585 and [2995] close = 147.84 r = 46.3585.
The “>_ Console” panel under the editor, with lines from console().
r = RSI[14](close)console(r)// [2999] r = 48.2console("RSI is #r#")// [2999] RSI is 48.2console(close, r)// [2999] close = 1.123 r = 48.2PRINT(close) AS "Cl"// [2999] Cl = 1.123

Each instruction, and in grey the line it writes on bar 2999. The values are examples.

  1. Add a console(…) line where you want to look, then click “Run”.The “>_ Console” panel opens under the editor. Each line starts with the bar number, in brackets.
  2. Drag the divider above the panel to give it room. “Clear” empties it; its × closes it.Closed, it reopens at the next “Run” that prints something.
A text "RSI is #r#"Printed as written, each #name# replaced by its value.
A name rPrinted as r = 48.2. A value that does not exist prints NaN.
How many linesOne per bar, the history included. The newest 1,000 are kept. With several codes, each line starts with its code's name.
PRINTWorks like console(). In ProRealTime it builds a table instead; here it writes lines.
Remove it before copying the code to ProRealTimeconsole() exists only in Studio: the ProRealTime editor does not accept it, and a code that uses it carries the “Studio Only” chip (chapter 06). PRINT is accepted there, but it builds a table, not these lines.
ProRealCode StudioUser guide · Chapter 09
Chapter 09 · In short

Three places to look: the line, the panel, the console.

WhereWhat it showsHow to open it
The lineThe mistake where it is, its message, its repair button.Point at the red underline.
ProblemsEvery error and warning, for every code on the chart and in the editor.The round “!” button, or “⚠ 1 problem” in the status bar.
>_ ConsoleThe values your code prints with console().By itself after “Run”, or the console button.

I clicked a repair button and nothing changed.

The line changed after the check. Studio does not write over a line it has not checked. Wait half a second for the next check, then click again.

A curve is missing, and there is no error.

Open Problems. A row “undefined on every bar (not drawn)” names the curve that has no value.

Why is a name that is never given a value only a warning?

The code still runs: that name reads as 0. It is often a typing mistake, so the row offers a repair.

The console stays empty.

It reads “console is empty — add console(…) to your code, then ▶ Run”. A console() inside an IF prints only on the bars where the condition is true.

Can I switch the checking off?

No, but “On ▶ Run only” keeps the editor quiet while you type (sheet 2).

Next

Chapter 10 · Understanding a code: the flow map

A map of any code: which value feeds which, down to what reaches the chart.

ProRealCode StudioUser guide · Chapter 09
ProRealCode ProRealCode
Loading...