Converting Price Data to Heiken-Ashi Format

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #244744 quote
    tomlin873
    Participant
    New

    Hello, on a 5 minute chart I want to inspect the high, low, 1st open, last close for the last three candles and draw that as a separate panel indicator on the 5 minute chart.
    Then the next 5 minute period and so on.
    (That is, a rolling 15 minute bar on a 5 minute chart. Conventionally 15m bars are only :00, :15, :30, :45.)

    So for the 3 candle ‘triplet’ the data generated is the max price high, min low across the three candles, the opening price at the start of the 15 minute ‘triplet’ and the closing price at the end of the ‘triplet’.

    I’ve attached my code so far – it works and gives an exact representation of PRICE candles generated in this way, :00, :15, :30, :45 candles match exactly the corresponding 15 minute chart data.

    My problem is: I do not get the correct result when I try to adjust my code for Heiken-Ashi output: it doesn’t match anything if I cross reference the 15m HA chart.

    Can anyone suggest code that takes my triplet data and draws the Heiken-Ashi candle version?

    Thank you very much

    // Uses the 5m bars over the last 15m period to create a 15m bar EACH 5 MINUES
    
    
    // Each price point:
    TripletLow = Lowest[3](Low)
    TripletHigh = Highest[3](High)
    TripletOpen = Open[2]
    TripletClose = Close
    
    // Draw Bars
    if TripletClose > TripletOpen then
    DrawCandle(TripletOpen, TripletHigh, TripletLow, TripletClose) Coloured (0, 200, 0) // Green candle
    else
    DrawCandle(TripletOpen, TripletHigh, TripletLow, TripletClose) Coloured (200, 0, 0) // Red candle
    endif
    
    Return
    #244745 quote
    JS
    Participant
    Senior

    Here’s the conversion of the “triplets” to Heikin Ashi…

    // Uses the 5m bars over the last 15m period to create a 15m bar EACH 5 MINUTES
    
    // Basis triplet-data
    TripletLow = Lowest[3](Low)
    TripletHigh = Highest[3](High)
    TripletOpen = Open[2]
    TripletClose = Close
    
    // Heikin-Ashi calculation
    HAClose = (TripletOpen + TripletHigh + TripletLow + TripletClose) / 4
    HAOpen = (TripletOpen + TripletClose) / 2  // Initialisation
    HAOpen = (HAOpen + HAClose) / 2
    HAHigh = Max(TripletHigh,Max(HAOpen, HAClose))
    HALow = Min(TripletLow,Min(HAOpen, HAClose))
    
    // Plotting HA-candles
    if HAClose > HAOpen then
    DrawCandle(HAOpen, HAHigh, HALow, HAClose) Coloured (0, 200, 0) // Groene HA candle
    else
    DrawCandle(HAOpen, HAHigh, HALow, HAClose) Coloured (200, 0, 0) // Rode HA candle
    endif
    
    Return
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Converting Price Data to Heiken-Ashi Format


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
tomlin873 @tomlin873 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by JS
11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/07/2025
Status: Active
Attachments: No files
Logo Logo
Loading...