Home » Ticker Functions » Understanding the ticker.heikinashi Function in Pine Script

Understanding the ticker.heikinashi Function in Pine Script

Photo of author
Published on

One advanced feature available to script developers is the ticker.heikinashi function. Through this blog post, we will explore the function in detail, dive deep into its syntax, and go through a unique use case that you can implement in your trading strategies.

What is the ticker.heikinashi Function?

ticker.heikinashi is a Pine Script function that creates a ticker identifier specifically for requesting Heikin Ashi bar values. Heikin Ashi is a type of candlestick chart that is calculated differently than the standard candlestick charts, making it useful for spotting trends and trend reversals.

Syntax

ticker.heikinashi(symbol) → simple string

Arguments

  • symbol (simple string): This refers to the Symbol ticker identifier.

Returns

The function will return a string value of the ticker id, which can then be supplied to the request.security function.

Example

Here’s a basic example to give you a better understanding:

//@version=5
indicator("ticker.heikinashi", overlay=true)
heikinashi_close = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
heikinashi_aapl_60_close = request.security(ticker.heikinashi("AAPL"), "60", close)
plot(heikinashi_close)
plot(heikinashi_aapl_60_close)
ticker.heikinashi Function in Pine Script

Unique Use Case: Comparative Heikin Ashi Analysis

Imagine wanting to compare the Heikin Ashi close values of the current ticker against that of a market leader, like Apple, on an hourly basis. Let’s break down the example code line by line.

//@version=5

This defines the version of Pine Script used, which in this case is version 5.

indicator("ticker.heikinashi", overlay=true)

This line sets the script as an indicator and overlays it on the price chart.

heikinashi_close = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)

Here, we are requesting the Heikin Ashi close value for the current ticker and the current timeframe. The syminfo.tickerid fetches the ticker id of the current chart.

heikinashi_aapl_60_close = request.security(ticker.heikinashi("AAPL"), "60", close)

In this line, we are doing a similar thing, but specifically for Apple (“AAPL”) and on an hourly basis (“60”).

plot(heikinashi_close)
plot(heikinashi_aapl_60_close)

Finally, these lines plot the Heikin Ashi close values for both tickers on the same chart.

With this, you can visually compare the trend strengths and directions of the two tickers in a more smoothed manner, thanks to the nature of the Heikin Ashi candles.

Key Takeaways

  • The ticker.heikinashi function allows users to fetch Heikin Ashi bar values for specific tickers.
  • It’s essential in creating custom indicators that require Heikin Ashi values.
  • With the ability to compare different tickers using Heikin Ashi, traders can make more informed decisions based on trend strengths and directions.

Conclusion

The ticker.heikinashi function in Pine Script opens the door to numerous analytical possibilities. Whether you’re designing a unique custom indicator or trying to gain a comparative perspective on market movements, understanding this function and its application can significantly benefit your trading strategies. As always, practice makes perfect, so don’t hesitate to play around with the code and come up with your unique analyses. Happy coding!

Leave a Comment