Reading Assignment: Pinescript

In this reading assignment, it’s time to get familiarized with Pinescript and all of it’s functions. Check out the Reference Manual and answer the following questions. The Reference Manual is a great resource to use in the future as well any time you are looking for a specific function or indicator.

  1. What does the language operator [] do? (Hint: It’s not for regular arrays)
  2. What does the input function do? (Hint: Try it in Tradingview)
  3. What does the Strategy function do?
  4. What information does the Volume variable contain?
  1. [] lets you query past instances of a variable… example if you wanted to confirm current candle open is greater than previous candle open: open > open[1]

  2. The input function provides an interface so you can edit the variable value via script settings. It also allows you to set the default, minimum and maximum allowed value where applicable.

  3. The strategy function emulates entering and exiting positions for back testing.

  4. Volume variable contains the buy/sell volume for the current bar.

1 Like
  1. What does the language operator [] do? (Hint: It’s not for regular arrays) [] lets to access to previous values of series , the number in the square backets indicates how many previous bars in the series the value is referred to.

  2. What does the input function do? (Hint: Try it in Tradingview) It adds an input to a script indicator. User can see and edit inputs on the Format Object dialog of the script study. Script inputs look and behave exactly the same as inputs of built-in Technical Analysis indicators.

  3. What does the Strategy function do? The function sets a number of strategy properties to applies the logic of the strategy to a series of data.

  4. What information does the Volume variable contain? It contains the current bar volume of trades.

  1. What does the language operator [] do? (Hint: It’s not for regular arrays)
  • it can be used to save value between bars.
  1. What does the input function do? (Hint: Try it in Tradingview)
  • Add new input.
  1. What does the Strategy function do?
  • To set up different strategy properties.
  1. What information does the Volume variable contain?
  • volume of current bar and previous bar
1 Like

1. What does the language operator [] do? (Hint: It’s not for regular arrays)
It is a series subscript that provides access to previous values of a series of data.
2. What does the input function do? (Hint: Try it in Tradingview)
It adds an input to the script editor.
3. What does the Strategy function do?
This function sets up a number of different strategy properties.
4. What information does the Volume variable contain?
Holds the current bar volume (buy/sell totals). Previous volume can be accessed by the language operator [].

1 Like
  • What does the language operator [] do? (Hint: It’s not for regular arrays)

Gets the value of the time series (“price”) in the past. can be applied to open/close/low,high.
Assuming the day resolution,

  • low[0] - “today” data
  • low[1] - “yesterday” data
  • and so on
  • What does the input function do? (Hint: Try it in Tradingview)

Adds a menu with parameters that can be specified by the user (just like for indicators)

  • What does the Strategy function do?

declares a strategy object which can be then used to entry/exit/close/etc.

  • What information does the Volume variable contain?

Amount of the instrument traded on a given time period (given “candle”)

1 Like
  1. [] Stores numbers, it can be used to pull previous data.
  2. Allows Data input
  3. The strategy function has many methods available to preform strategies. strategy.xxxxx
  4. The volume variable measures today’s volume

Thanks your answers are very clear. Made parts of https://www.tradingview.com/study-script-reference/ make more sense.

1 Like
  1. It lets you use values from previous candles.

  2. The input function adds an input to your script.

  3. The strategy function sets a number of strategy properties such as title, shorttitle, overlay, precision, scale, pyramiding, calc_on_order_fills, calc_on_every_tick, max_bars_back, backtest_fill_limits_assumption, default_qty_type, default_qty_value, initial_capital, currency, slippage, commission_type and commission_value.

  4. The volume variable contains the current bar volume.

1. What does the language operator [] do? (Hint: It’s not for regular arrays)
It’s a “Series subscript”, which provides access to previous values of a given series, for example bitcoin[10] to get the last 10 values from the current bitcoin timeframe.

2. What does the input function do? (Hint: Try it in Tradingview)
The input function adds settings/properties to an object, such as a plot/chart, where you can have an input to toggle it on/off, or to set a given symbol or the time resolution, etc…

3. What does the Strategy function do?
It adds a parameterized strategy to the script, when to open and to close a trade for example

4. What information does the Volume variable contain?
It contains the current bar volume, and other previous bars are accessible using series subscript operator []

1 Like
  1. Operator [] references some previous value of the series.
  2. Input functions make it possible to change variables for indicators. It also creates a widget, so the variables can be easily changed without the need to change code.
  3. Strategy function sets parameters for the strategy.
  4. Volume variable stores a current value of trade volume bars, but can also be used to access previous bars by indexing using [] operator.
1 Like

(1) What does the language operator [] do? (Hint: It’s not for regular arrays) They provide access to previous values.
(2) What does the input function do? (Hint: Try it in Tradingview) The input function add to the script indicator.
(3) What does the Strategy function do? The Strategy functions sets a number of strategy properties.
(4) What information does the Volume variable contain? The volume variable contains volume of a bar and can access previous values using the square brackets operator.

1 Like
  1. The language operator [], when used with one of the standard 4 variable (open, close, high, low) searches back from the current candle. So open[1] will get you the opening value of the previous candle and open[2] will get you the opening value for the one before that.

  2. Adds a value which can be input in the settings on the chart which can be used in later calculations. For example if you were comparing two MA’s (say a fast and a slow one) you could have something like
    fast = input(12, defval=12)
    slow = input(26, defval=26)

  3. strategy allows you to set a number of properties against a strategy for example its title, maximum number of entries in the same direction

  4. Gives you the current bar volume using the [] will allow you to look at previous values

1 Like

1 .What does the language operator [] do?
Provides access to previous values of a given series of data.

2 .What does the input function do?
Adds an input to the script indicator.

3.What does the Strategy function do?
The function sets a number of strategy properties.

4 .What information does the Volume variable contain?
Current bar volume.

1 Like