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 08 · Part II — Writing code

Change a setting, never the code.

A period, a colour, a threshold: whoever writes a code can turn any of them into a setting. Whoever uses the code then changes it from a window on the chart, copy by copy, without reading a line.

  1. 01Declare a setting The input() line and its eight types.
  2. 02ƒx Variables The same lines, filled in as a form.
  3. 03Limits, lists, groups What the reader is allowed to pick.
  4. 04⚙ Settings Change the values of one copy on the chart.
  5. 05Timeframe and instrument One code, another timeframe or market.
  6. 06In short Try values, common questions.

Who writes the code

Declares each setting once, in the code: its name, its starting value, its title, its type. “Variables”, in the editor's header, does it as a form (sections 01 to 03).

Who uses it

Opens ⚙ Settings for a copy on the chart and changes its values. The code does not change; another copy of it keeps its own values (sections 04 and 05).

Before you startYou have run a code from the editor (chapter 02 · Your first indicator). Its first example already declares two settings: you will find them in section 01.
ProRealCode StudioUser guide · Chapter 08
01 · Declare a setting

One line at the top of the code makes a setting.

input(period, 20, "MA period", int)
  1. period, the name. The rest of the code reads it like any variable: Average[period](close).
  2. 20, the starting value. It is what the code uses until somebody changes it.
  3. "MA period", the title shown in ⚙ Settings. Leave it out and the name is shown instead.
  4. int, the type. It decides the control in ⚙ Settings. Leave it out and the setting is a float.
TypeIn ⚙ SettingsThe value
intA whole-number fieldRounded to a whole number.
floatA number fieldAs typed.
boolA switch1 when on, 0 when off.
matypeA list of averages0 Simple (SMA), 1 Exponential (EMA), 2 Weighted (WMA), 3 Wilder, 4 Triangular, 5 End point, 6 Time series, 7 Hull, 8 ZeroLag.
stringA text fieldText: a label, a table title, a word.
colorA colour pickerA colour, written "#ff8800" in the code.
timeframeA list of timeframesSection 05.
instrumentA list of instrumentsSection 05.
Why “Studio Only” appearsThe ProRealTime platform's own editor does not know input(). A code that declares a setting this way carries the “Studio Only” chip (chapter 06): it runs in ProRealCode Studio, not when pasted into the platform.
ProRealCode StudioUser guide · Chapter 08
02 · ƒx Variables

Fill in a form, and Studio writes the lines.

The ƒx Variables window with three rows: rsiLen, int — whole number, 14, RSI length; level, float — number, 1.5, Band width; showBand, bool — true/false, a switch turned on, Show the band. Each row ends with ⋯ and ✕. At the bottom, the Apply to code button, the amber note not in your code yet — click Apply to code, and a greyed Try values button. 1 2 3 4 5 6 7
Three settings of three types, added here and not yet written into the code.
  1. “+ Add variable” adds an empty row.
  2. The banner: nothing reaches the code until you click “✔ Apply to code”.
  3. A row: the name, the type (“int — whole number”), the starting value, the title. An empty title shows the name.
  4. “⋯” opens the attributes of section 03; it shows how many are set. “✕” removes the row.
  5. A bool takes a switch as its starting value.
  6. “✔ Apply to code”, and the amber note beside it while the form and the code differ.
  7. “⚙ Try values” opens ⚙ Settings on this code's copy on the chart. Greyed until the code is on the chart.
  1. With the code open in the editor, click “Variables” in the header.The window lists the input() lines at the top of the code. None yet: it says so.
  2. Click “+ Add variable”, then fill in the name, the type, the value and the title.A mistake shows under the row: “invalid name — letters, digits and _ only, not starting with a digit”, for instance.
  3. Click “✔ Apply to code”.The lines appear at the top of the code and the code runs. The note reads “3 variables · in sync with the code”. Ctrl + Z in the editor takes it all back.
ProRealCode StudioUser guide · Chapter 08
03 · Limits, lists, groups

Seven attributes decide what the reader may pick.

Write them after the type, in any order, or fill them in under “⋯” in ƒx Variables.

AttributeOn typesIn ⚙ Settings
optionsint, float, stringA list of the values written: nothing else can be picked.
minvalint, floatThe lowest value. A smaller one typed in is raised to it.
maxvalint, floatThe highest value. Type 500 under maxval = 200 and the field reads 200.
stepint, floatHow far the field's arrows move the value. A value typed by hand is kept as typed.
groupallA heading, in the order the code declares them.
inlineallSettings that share the same word sit on one line.
tooltipallA help text behind an ⓘ next to the title.
input(len, 20, "Length", int, minval = 5, maxval = 200, step = 5, group = "Averages", tooltip = "Bars in the average")input(method, "EMA", "Type", string, options = ["SMA", "EMA", "WMA"], group = "Averages")input(tint, "#ff8800", "Colour", color, group = "Appearance")

Three settings in two groups. In ⚙ Settings: an “Averages” heading over a number field from 5 to 200 with an ⓘ and a list of three averages, then an “Appearance” heading over a colour picker.

ƒx Variables shows the block at the topThe window lists the input() lines that open the code, one after the other. A line written further down still works in ⚙ Settings, but the window does not show it and leaves it as written. A misspelt attribute stops the code with an error that lists the seven.
ProRealCode StudioUser guide · Chapter 08
04 · ⚙ Settings

Each copy on the chart has its own settings.

A row of the Codes on the chart window: Trend heat ribbon + regime HUD, 3 series · 4 inputs, a timing chip, then the eye, pencil, tag, copy, sliders, placement and bin icons, and Auto.
A row of “Codes on the chart” (Alt + I, chapter 12). The fifth icon, three sliders, opens ⚙ Settings.
The top of the window ⚙ Settings — Trend heat ribbon + regime HUD: four rows, Fastest ribbon EMA 12, Length step between lines 8, Regime lookback 100, Ribbon opacity 0-255 90, each tagged INT. 1 2 3
The four settings of the example “Trend heat ribbon + regime HUD”.
  1. The copy's name.
  2. A setting: its title, then its value. Type a new value and press Enter, or pick one in a list: the copy is redrawn at once, and Studio remembers the value when you reload the page.
  3. The type of the setting, here INT.

The bar at the bottom of the window

Settings move THIS instance only.Another copy of the code keeps its own values.
ƒx Edit declarationsOpens ƒx Variables, when this code is the one open in the editor.
↺ Reset to defaultsPuts back the starting values of this copy. Greyed while nothing has changed.
ProRealCode StudioUser guide · Chapter 08
05 · Timeframe and instrument

One code, read on another timeframe or another market.

A code that declares a timeframe setting gets a list of timeframes in ⚙ Settings. A code that declares none gets no list: nothing is added behind your back.

The setting moves whatever the code wrote it into. Here, the RSI is computed on hourly bars, whatever the chart shows.

input(mytf, "1 hour", "Timeframe", timeframe)
TIMEFRAME(mytf)
h1rsi = RSI[14](close)
TIMEFRAME(default)
RETURN h1rsi AS "H1 RSI"
The code input(mytf, "1 hour", "Timeframe", timeframe) Copy 1 on the chart Timeframe: 1 hour, the starting value Copy 2, made with Duplicate Timeframe: 4 hours, set in its ⚙ Settings Chart: 15 minutes
Illustration. The same code twice on one chart, each copy on its own timeframe. “Duplicate”, the copy icon of a row in “Codes on the chart”, makes a second copy with the same settings.

The timeframes offered

“Chart timeframe”, then 1, 2, 3, 5, 10, 15 and 30 minutes, 1, 2, 3, 4, 6, 8 and 12 hours, 1 day, 1 week, 1 month. A timeframe shorter than the chart's is greyed out: on a 15-minute chart, 1 to 10 minutes.

The instruments offered

A code that declares an instrument setting and passes it to MarketData() gets a list that starts with “Chart instrument”, followed by your chart's ticker, then the other instruments Studio can read.

Changing either one rebuilds the copyThe copy is computed again from its first bar, on the new timeframe or the new market. The other copies of the code do not move.
ProRealCode StudioUser guide · Chapter 08
Chapter 08 · In short

Declared once in the code, changed on every copy.

The ⚙ Settings window of Trend heat ribbon + regime HUD open over the ƒx Variables window, with its four settings and the buttons ƒx Edit declarations and ↺ Reset to defaults.
“⚙ Try values” opens ⚙ Settings over ƒx Variables: declare a setting, then try its values straight away.

From one window to the other

ƒx Variables, for the code: “⚙ Try values” jumps to the copy on the chart. ⚙ Settings, for a copy: “ƒx Edit declarations” jumps back to the code.

Renamed or removed a setting in ƒx Variables? A value you had set in ⚙ Settings is kept; “↺ Reset to defaults” clears it. Changed its type? The value goes back to the starting one.

⚙ Settings reads “No inputs declared”.

The code has no input() line. Add one, for instance with ƒx Variables, then run the code.

I changed a value and both copies moved.

That value is written in the code, not declared as a setting. Declare it with input() and each copy gets its own.

ƒx Variables says the code does not parse.

Fix the errors the editor shows first (chapter 09), then reopen the window.

“⚙ Try values” is greyed out.

The code is not on the chart yet. Click “Run”, then try again.

Next

Chapter 09 · Finding and fixing errors

The error line in the editor, one-click fixes, the Problems panel and the console.

ProRealCode StudioUser guide · Chapter 08
ProRealCode ProRealCode
Loading...