SoftwareTester
SoftwareTester

Reputation: 1090

How to change display of candles into Heikin Ashi from script

Changing the way Bar's style into Heikin Ashi from the menu is easy but how can you do it by code? I would like to avoid that a user has to remember he should change it when he uses an indicator or study.

Upvotes: 1

Views: 436

Answers (1)

vitruvius
vitruvius

Reputation: 21159

You cannot directly do that.

You can try calculating the Heikin Ashi values yourself and then use the plotcandle() function. This would only work if overlay=false.

However, if all you want is a simple warning to the user, I would suggest a simple warning text on the chart. Use chart.is_heikinashi built-in variable and print a warning text if the chart is not Heikin Ashi.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius

//@version=5
indicator("My script", overlay=true)


is_ha = chart.is_heikinashi

var testTable = table.new(position = position.top_right, columns = 1, rows = 1, bgcolor = color.yellow, border_width = 1)

if barstate.islast and not is_ha
    table.cell(table_id = testTable, column = 0, row = 0, text = "Please change to Heikin Ashi")

enter image description here

Upvotes: 1

Related Questions