One particularly useful function in Pine Script is ** math.max**. This function returns the greatest value out of multiple inputs.

**Syntax of math.max**

The ** math.max** function has a very flexible syntax that can accommodate multiple arguments of different data types. Here are some basic forms of the function:

`math.max(number0, number1, ...) → simple int`

`math.max(number0, number1, ...) → simple float`

`math.max(number0, number1, ...) → input int`

`math.max(number0, number1, ...) → input float`

`math.max(number0, number1, ...) → series int`

`math.max(number0, number1, ...) → series float`

It’s important to note that the function takes at least two arguments and will return the highest value among these arguments.

**How it Works**

The ** math.max** function works by scanning through the input arguments and finding the greatest value. For example, if you pass in three numbers like so:

**, the function would return**

`math.max(1, 3, 2)`

**as it is the largest number among the arguments.**

`3`

**Using math.max in Pine Script**

Let’s look at a simple code example to understand how ** math.max** works in Pine Script:

//@version=5 indicator("math.max Example", overlay=true) plot(math.max(close, open), linewidth = 3)

**Code Explanation**

is the version directive that specifies the version of Pine Script to use for the script. This directive must be placed at the very start of the script and no other code or comments should precede it. Here, we are using version 5 of Pine Script.`//@version=5`

creates a new indicator script named “math.max Example”. The`indicator("math.max Example", overlay=true)`

part means that the output of this script will be drawn directly on the price chart, rather than in a separate pane below it.`overlay=true`

is using the`plot(math.max(close, open), linewidth = 3)`

function to draw a graph on the chart. The values that are being graphed are the result of`plot`

, which calculates the maximum of the`math.max(close, open)`

and`close`

prices for each bar on the chart. The`open`

parameter specifies the thickness of the line drawn on the chart to be 3 pixels.`linewidth = 3`

**Key Takeaway**

The ** math.max** function in Pine Script is a versatile tool for identifying the maximum value among a set of variables or data series. It can be used for various analytical purposes, such as identifying the highest price or volume in a certain time period.

**Conclusion**

Understanding how to use ** math.max** function in Pine Script is essential for any trader or analyst who wishes to create their own custom scripts. By using this function, you can obtain the maximum value from multiple inputs, helping you to develop more intricate trading strategies and indicators.