Home » Symbol Information Functions » Understanding syminfo.currency Function in Pine Script

Understanding syminfo.currency Function in Pine Script

Photo of author
Published on

Introduction to syminfo.currency

In Pine Script, particularly in its latest iteration, Version 5, the syminfo.currency function plays a crucial role for traders and developers working on scripting strategies or indicators. This function is essential for accessing the quote currency of the current symbol. Understanding its functionality and application is key for anyone looking to develop more dynamic and responsive scripts in Pine Script.

Usage of syminfo.currency

The primary use of syminfo.currency is to retrieve the quote currency of the trading pair your script is running on. For instance, if your script is applied to the EUR/USD pair, syminfo.currency will return “USD”, which is the quote currency in this pair.

Example Code:

indicator("My Currency Info Script", overlay=true)

// Retrieving the quote currency
quoteCurrency = syminfo.currency

// Displaying the quote currency on the chart
label.new(bar_index, high, text="Quote Currency: " + quoteCurrency, color=color.red)

In this example, we have a simple script that displays the quote currency of the symbol it is applied to. We first define the variable quoteCurrency to hold the value returned by syminfo.currency. Then, we use label.new to create a label on the chart displaying the quote currency.

Walkthrough of Each Line of Code:

  1. //@version=5: This specifies that the script uses Version 5 of Pine Script.
  2. indicator("My Currency Info Script", overlay=true): Defines the script as an indicator and ensures it’s overlaid on the price chart.
  3. quoteCurrency = syminfo.currency: Initializes a variable quoteCurrency and assigns it the value of the quote currency of the current trading pair.
  4. label.new(bar_index, high, text="Quote Currency: " + quoteCurrency, color=color.red): Creates a new label on the chart. This label shows the text “Quote Currency: ” followed by the quote currency value, placed at the current bar index and at the high price level, with the label color set to red.

Key Features and Takeaways

  • Function Usability: syminfo.currency is straightforward and requires no parameters. It’s highly useful for scripts that need to adapt based on the quote currency.
  • Syntax: The function is simple, with a syntax of syminfo.currency. It returns a string representing the quote currency.
  • Application: This function is particularly useful in multi-currency strategies, risk management scripts, or when displaying currency-specific information on charts.

Leave a Comment