This question if about javascript (not pyhton or pine script).
I just want to create a simple few lines function => "convert" FROM regular open, high, low and close from an exchange TO a Heikin Ashi
variables open, high, low, close are from an exchange API that return an array with regual candlesticks
here the formula
ha_open = (last_ha_open - last_ha_close) / 2;
ha_close = (open + high + low + close)/4;
ha_high = max(high, ha_open, ha_close);
ha_low = min(low, ha_open, ha_close);
where I get "stuck" is the "last_ha_open" and "last_ha_close"
**** it's easy to save ha_open and ha_close with .push into an array
**** it's easy to retrieving them with array[(array.length -1)] (last of array)
**** it's where it gets tricky... : the infinite loop of calculate the first in the chain.. if wrong, the values don't match...
is there a javascript way to do this ????
Notes i could find about Heikin-ashi
Obs:
The first Heikin-Ashi close equals the average of the open, high, low and close ((O+H+L+C)/4).
The first Heikin-Ashi open equals the average of the open and close ((O+C)/2).
The first Heikin-Ashi high equals the high and the first Heikin-Ashi low equals the low.