Implementing SuperTrend Indicator Using Heikin Ashi Values in ProBuilder

25 Oct 2024
0 comment
0 attachment

This code snippet demonstrates how to calculate the SuperTrend indicator using Heikin Ashi candlestick values in ProBuilder. The SuperTrend is a popular trading indicator that combines price momentum and volatility to determine potential market trends. Heikin Ashi candles are used here to smooth price data and reduce noise, enhancing the effectiveness of the SuperTrend indicator.


ONCE xOpen = open
xClose = (open + high + low + close) / 4
IF BarIndex > 1 THEN
    xOpen = (xOpen[1] + xClose[1]) / 2
ENDIF
xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
MedianHA = (xHigh + xLow) / 2
// 
IF BarIndex > Max(Periods,Multiplier) THEN
    MyATR = AverageTrueRange[Periods](xClose) * Multiplier
    BasicUPPER = MedianHA + MyATR
    BasicLOWER = MedianHA - MyATR
    IF (BasicUPPER < FinalUPPER[1]) OR (xClose[1] > FinalUPPER[1]) THEN
        FinalUPPER = BasicUPPER
    ENDIF
    IF (BasicLOWER > FinalLOWER[1]) OR (xClose[1] < FinalLOWER[1]) THEN
        FinalLOWER = BasicLOWER
    ENDIF
    IF (ST[1] = FinalUPPER[1]) AND (xClose <= FinalUPPER) THEN
        ST = FinalUPPER
    ELSE IF (ST[1] = FinalUPPER[1]) AND (xClose > FinalUPPER) THEN
        ST = FinalLOWER
    ELSE IF (ST[1] = FinalLOWER[1]) AND (xClose >= FinalLOWER) THEN
        ST = FinalLOWER
    ELSE IF (ST[1] = FinalLOWER[1]) AND (xClose < FinalLOWER) THEN
        ST = FinalUPPER
    ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
RETURN ST AS "Super Trend HA"

Explanation of the code:

  • Initialization: The Heikin Ashi open (xOpen) and close (xClose) prices are calculated. The xClose is the average of the open, high, low, and close prices of the current bar.
  • Heikin Ashi Values: For subsequent bars, xOpen is recalculated as the average of the previous bar's xOpen and xClose. xLow and xHigh are determined as the minimum and maximum values among the low, xClose, and xOpen, and the high, xClose, and xOpen, respectively.
  • Median Calculation: MedianHA is calculated as the average of xHigh and xLow.
  • SuperTrend Calculation: The Average True Range (ATR) is calculated based on the xClose and adjusted by a multiplier. The basic upper and lower SuperTrend values are then computed by adding and subtracting the ATR from MedianHA.
  • Trend Determination: The final upper and lower SuperTrend values are adjusted based on previous values and the current xClose. The SuperTrend (ST) is then determined based on the previous trend and the current xClose position relative to the SuperTrend values.

This approach helps in smoothing the price data and potentially provides a clearer indication of the trend direction, which can be beneficial in various trading strategies.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/supertrend-per-heiken-ashi/#post-165551

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
robertogozzi New
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
33
indicator
132
strategy
170

Recent Snippets

Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Implementing Single Trade Per Timeframe Logic in ProBuilder
strategy
This code snippet demonstrates how to ensure that only one trade is executed per timeframe in a trading strategy using [...]
Logo Logo
Loading...